2424import  com .google .common .base .Enums ;
2525import  com .google .common .base .Strings ;
2626import  com .google .common .collect .Multimap ;
27- import  org .apache .commons .lang .StringUtils ;
28- import  org .apache .commons .lang .math .NumberUtils ;
2927import  org .bukkit .*;
3028import  org .bukkit .attribute .Attribute ;
3129import  org .bukkit .attribute .AttributeModifier ;
@@ -125,7 +123,7 @@ public static void serialize(@Nonnull ItemStack item, @Nonnull ConfigurationSect
125123        if  (meta .hasLore ()) config .set ("lore" , meta .getLore ()); // TODO Add a method to "untranslate" color codes. 
126124
127125        if  (supports (14 )) {
128-             if  (meta .hasCustomModelData ()) config .set ("custom-model" , meta .getCustomModelData ());
126+             if  (meta .hasCustomModelData ()) config .set ("custom-model-data " , meta .getCustomModelData ());
129127        }
130128        if  (supports (11 )) {
131129            if  (meta .isUnbreakable ()) config .set ("unbreakable" , true );
@@ -436,6 +434,42 @@ public static ItemStack deserialize(@Nonnull Map<String, Object> serializedItem,
436434        return  deserialize (mapToConfigSection (serializedItem ), translator );
437435    }
438436
437+     private  static  int  toInt (String  str , @ SuppressWarnings ("SameParameterValue" ) int  defaultValue ) {
438+         try  {
439+             return  Integer .parseInt (str );
440+         } catch  (NumberFormatException  nfe ) {
441+             return  defaultValue ;
442+         }
443+     }
444+ 
445+     private  static  List <String > split (@ Nonnull  String  str , @ SuppressWarnings ("SameParameterValue" ) char  separatorChar ) {
446+         List <String > list  = new  ArrayList <>(5 );
447+         boolean  match  = false , lastMatch  = false ;
448+         int  len  = str .length ();
449+         int  start  = 0 ;
450+ 
451+         for  (int  i  = 0 ; i  < len ; i ++) {
452+             if  (str .charAt (i ) == separatorChar ) {
453+                 if  (match ) {
454+                     list .add (str .substring (start , i ));
455+                     match  = false ;
456+                     lastMatch  = true ;
457+                 }
458+ 
459+                 // This is important, it should not be i++ 
460+                 start  = i  + 1 ;
461+                 continue ;
462+             }
463+ 
464+             lastMatch  = false ;
465+             match  = true ;
466+         }
467+ 
468+         if  (match  || lastMatch ) {
469+             list .add (str .substring (start , len ));
470+         }
471+         return  list ;
472+     }
439473
440474    /** 
441475     * Deserialize an ItemStack from the config. 
@@ -539,10 +573,10 @@ public static ItemStack edit(@Nonnull ItemStack item,
539573
540574                String  baseEffect  = config .getString ("base-effect" );
541575                if  (!Strings .isNullOrEmpty (baseEffect )) {
542-                     String []  split  = StringUtils . split (baseEffect , ',' );
543-                     PotionType  type  = Enums .getIfPresent (PotionType .class , split [ 0 ] .trim ().toUpperCase (Locale .ENGLISH )).or (PotionType .UNCRAFTABLE );
544-                     boolean  extended  = split .length  != 1  && Boolean .parseBoolean (split [ 1 ] .trim ());
545-                     boolean  upgraded  = split .length  > 2  && Boolean .parseBoolean (split [ 2 ] .trim ());
576+                     List < String >  split  = split (baseEffect , ',' );
577+                     PotionType  type  = Enums .getIfPresent (PotionType .class , split . get ( 0 ) .trim ().toUpperCase (Locale .ENGLISH )).or (PotionType .UNCRAFTABLE );
578+                     boolean  extended  = split .size ()  != 1  && Boolean .parseBoolean (split . get ( 1 ) .trim ());
579+                     boolean  upgraded  = split .size ()  > 2  && Boolean .parseBoolean (split . get ( 2 ) .trim ());
546580                    PotionData  potionData  = new  PotionData (type , extended , upgraded );
547581                    potion .setBasePotionData (potionData );
548582                }
@@ -556,10 +590,10 @@ public static ItemStack edit(@Nonnull ItemStack item,
556590                    int  level  = config .getInt ("level" );
557591                    String  baseEffect  = config .getString ("base-effect" );
558592                    if  (!Strings .isNullOrEmpty (baseEffect )) {
559-                         String []  split  = StringUtils . split (baseEffect , ',' );
560-                         PotionType  type  = Enums .getIfPresent (PotionType .class , split [ 0 ] .trim ().toUpperCase (Locale .ENGLISH )).or (PotionType .SLOWNESS );
561-                         boolean  extended  = split .length  != 1  && Boolean .parseBoolean (split [ 1 ] .trim ());
562-                         boolean  splash  = split .length  > 2  && Boolean .parseBoolean (split [ 2 ] .trim ());
593+                         List < String >  split  = split (baseEffect , ',' );
594+                         PotionType  type  = Enums .getIfPresent (PotionType .class , split . get ( 0 ) .trim ().toUpperCase (Locale .ENGLISH )).or (PotionType .SLOWNESS );
595+                         boolean  extended  = split .size ()  != 1  && Boolean .parseBoolean (split . get ( 1 ) .trim ());
596+                         boolean  splash  = split .size ()  > 2  && Boolean .parseBoolean (split . get ( 2 ) .trim ());
563597
564598                        item  = (new  Potion (type , level , splash , extended )).toItemStack (1 );
565599                    }
@@ -580,7 +614,7 @@ public static ItemStack edit(@Nonnull ItemStack item,
580614                    ShulkerBox  box  = (ShulkerBox ) state ;
581615                    for  (String  key  : shulkerSection .getKeys (false )) {
582616                        ItemStack  boxItem  = deserialize (shulkerSection .getConfigurationSection (key ));
583-                         int  slot  = NumberUtils . toInt (key , 0 );
617+                         int  slot  = toInt (key , 0 );
584618                        box .getInventory ().setItem (slot , boxItem );
585619                    }
586620                    box .update (true );
@@ -774,35 +808,47 @@ public static ItemStack edit(@Nonnull ItemStack item,
774808
775809        // Custom Model Data 
776810        if  (supports (14 )) {
777-             int  modelData  = config .getInt ("model-data" );
811+             int  modelData  = config .getInt ("custom- model-data" );
778812            if  (modelData  != 0 ) meta .setCustomModelData (modelData );
779813        }
780814
781815        // Lore 
782-         List <String > translatedLore ;
783-         List <String > lores  = config .getStringList ("lore" );
784-         if  (!lores .isEmpty ()) {
785-             translatedLore  = new  ArrayList <>(lores .size ());
786- 
787-             for  (String  lore  : lores ) {
788-                 if  (lore .isEmpty ()) {
789-                     translatedLore .add (" " );
790-                     continue ;
791-                 }
792- 
793-                 for  (String  singleLore  : splitNewLine (lore )) {
794-                     if  (singleLore .isEmpty ()) {
816+         if  (config .isSet ("lore" )) {
817+             List <String > translatedLore ;
818+             List <String > lores  = config .getStringList ("lore" );
819+             if  (!lores .isEmpty ()) {
820+                 translatedLore  = new  ArrayList <>(lores .size ());
821+ 
822+                 for  (String  lore  : lores ) {
823+                     if  (lore .isEmpty ()) {
795824                        translatedLore .add (" " );
796825                        continue ;
797826                    }
798-                     translatedLore .add (translator .apply (singleLore ));
827+ 
828+                     for  (String  singleLore  : splitNewLine (lore )) {
829+                         if  (singleLore .isEmpty ()) {
830+                             translatedLore .add (" " );
831+                             continue ;
832+                         }
833+                         translatedLore .add (translator .apply (singleLore ));
834+                     }
835+                 }
836+             } else  {
837+                 String  lore  = config .getString ("lore" );
838+                 translatedLore  = new  ArrayList <>(10 );
839+ 
840+                 if  (!Strings .isNullOrEmpty (lore )) {
841+                     for  (String  singleLore  : splitNewLine (lore )) {
842+                         if  (singleLore .isEmpty ()) {
843+                             translatedLore .add (" " );
844+                             continue ;
845+                         }
846+                         translatedLore .add (translator .apply (singleLore ));
847+                     }
799848                }
800849            }
801850
802851            meta .setLore (translatedLore );
803-         } else  {
804-             String  lore  = config .getString ("lore" );
805-             if  (!Strings .isNullOrEmpty (lore )) meta .setLore (Collections .singletonList (translator .apply (lore )));
806852        }
807853
808854        // Enchantments 
@@ -949,9 +995,9 @@ private static Map<String, Object> configSectionToMap(@Nonnull ConfigurationSect
949995    @ Nonnull 
950996    public  static  Color  parseColor (@ Nullable  String  str ) {
951997        if  (Strings .isNullOrEmpty (str )) return  Color .BLACK ;
952-         String []  rgb  = StringUtils . split (StringUtils . deleteWhitespace ( str ), ',' );
953-         if  (rgb .length  < 3 ) return  Color .WHITE ;
954-         return  Color .fromRGB (NumberUtils . toInt (rgb [ 0 ] , 0 ), NumberUtils . toInt (rgb [ 1 ] , 0 ), NumberUtils . toInt (rgb [ 2 ] , 0 ));
998+         List < String >  rgb  = split (str . replace ( " " ,  "" ), ',' );
999+         if  (rgb .size ()  < 3 ) return  Color .WHITE ;
1000+         return  Color .fromRGB (toInt (rgb . get ( 0 ) , 0 ), toInt (rgb . get ( 1 ) , 0 ), toInt (rgb . get ( 2 ) , 0 ));
9551001    }
9561002
9571003    /** 
0 commit comments