8
8
import it .angrybear .yagl .wrappers .Enchantment ;
9
9
import it .fulminazzo .fulmicollection .interfaces .functions .BiFunctionException ;
10
10
import it .fulminazzo .fulmicollection .interfaces .functions .TriConsumer ;
11
- import it .fulminazzo .fulmicollection .objects .Refl ;
12
11
import it .fulminazzo .yamlparser .configuration .ConfigurationSection ;
13
12
import it .fulminazzo .yamlparser .configuration .IConfiguration ;
14
13
import it .fulminazzo .yamlparser .parsers .YAMLParser ;
15
14
import org .jetbrains .annotations .NotNull ;
16
15
import org .jetbrains .annotations .Nullable ;
17
16
18
- import java .util .LinkedList ;
17
+ import java .util .ArrayList ;
19
18
import java .util .List ;
20
- import java .util .Set ;
21
19
import java .util .stream .Collectors ;
22
20
23
21
/**
@@ -53,12 +51,9 @@ public ItemParser() {
53
51
itemSection .getListOptional ("enchantments" , Enchantment .class ).ifPresent (item ::addEnchantments );
54
52
itemSection .getListOptional ("item-flags" , ItemFlag .class ).ifPresent (item ::addItemFlags );
55
53
56
- ConfigurationSection recipesSection = itemSection .getConfigurationSection ("recipes" );
57
- if (recipesSection != null ) {
58
- final List <Recipe > recipes = new LinkedList <>();
59
- @ NotNull Set <String > keys = recipesSection .getKeys ();
60
- for (String k : keys ) recipes .add (recipesSection .get (k , Recipe .class ));
61
- if (!recipes .isEmpty ()) item = item .copy (RecipeItem .class ).setRecipes (recipes .toArray (new Recipe [0 ]));
54
+ if (itemSection .contains ("recipes" )) {
55
+ List <Recipe > recipes = itemSection .getList ("recipes" , Recipe .class );
56
+ if (recipes != null ) item = item .copy (RecipeItem .class ).setRecipes (recipes .toArray (new Recipe [0 ]));
62
57
}
63
58
64
59
return item ;
@@ -70,9 +65,11 @@ public ItemParser() {
70
65
return (c , s , i ) -> {
71
66
c .set (s , null );
72
67
if (i == null ) return ;
68
+
73
69
final ConfigurationSection itemSection = c .createSection (s );
74
70
String material = i .getMaterial ();
75
71
if (material != null ) itemSection .set ("material" , material .toLowerCase ());
72
+
76
73
itemSection .set ("amount" , i .getAmount ());
77
74
itemSection .set ("durability" , i .getDurability ());
78
75
itemSection .set ("display-name" , MessageUtils .decolor (i .getDisplayName ()));
@@ -83,11 +80,9 @@ public ItemParser() {
83
80
itemSection .set ("custom-model-data" , i .getCustomModelData ());
84
81
85
82
if (i instanceof RecipeItem ) {
86
- ConfigurationSection recipesSection = itemSection .createSection ("recipes" );
87
- List <Recipe > recipes = new Refl <>(i ).getFieldObject ("recipes" );
88
- if (recipes != null )
89
- for (int j = 0 ; j < recipes .size (); j ++)
90
- recipesSection .set (String .valueOf (j ), recipes .get (j ));
83
+ List <Recipe > recipes = new ArrayList <>();
84
+ ((RecipeItem ) i ).forEach (recipes ::add );
85
+ itemSection .setList ("recipes" , recipes );
91
86
}
92
87
};
93
88
}
0 commit comments