1- package me .simplicitee .project .items .item . parser ;
1+ package me .simplicitee .project .items .item ;
22
33import java .util .ArrayList ;
44import java .util .List ;
88import org .bukkit .Material ;
99import org .bukkit .NamespacedKey ;
1010import org .bukkit .configuration .file .FileConfiguration ;
11- import org .bukkit .inventory .ItemStack ;
12- import org .bukkit .inventory .Recipe ;
11+ import org .bukkit .inventory .CraftingRecipe ;
12+ import org .bukkit .inventory .RecipeChoice ;
1313import org .bukkit .inventory .ShapedRecipe ;
1414import org .bukkit .inventory .ShapelessRecipe ;
15- import org .bukkit .inventory .meta .ItemMeta ;
1615import org .bukkit .plugin .java .JavaPlugin ;
1716
17+ import me .simplicitee .project .items .BendingItem ;
18+ import me .simplicitee .project .items .ItemManager ;
1819import me .simplicitee .project .items .ItemsPlugin ;
19- import me .simplicitee .project .items .item .ItemDataParser ;
2020
21- public class RecipeParser implements ItemDataParser {
21+ public final class RecipeParser {
2222
2323 private static final String PATH = "Recipe" ;
2424 private static final char [] CHARS = {'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' };
2525
26- @ Override
27- public String getPath () {
28- return PATH ;
29- }
30-
31- @ Override
32- public void apply (String name , ItemStack item , ItemMeta meta , FileConfiguration config ) {
26+ private RecipeParser () {}
27+
28+ public static void apply (BendingItem item ) {
29+ FileConfiguration config = item .config ();
3330 if (!config .contains (PATH )) return ;
3431
3532 Logger logger = JavaPlugin .getPlugin (ItemsPlugin .class ).getLogger ();
33+ String name = item .getInternalName ();
34+
3635
3736 if (!config .contains (PATH + ".Ingredients" )) {
3837 logger .warning ("Recipe for '" + name + "' requires a list of ingredients under the config path 'Recipe.Ingredients'" );
@@ -55,38 +54,51 @@ public void apply(String name, ItemStack item, ItemMeta meta, FileConfiguration
5554 logger .warning ("Ingredients list for '" + name + "' recipe cannot be longer than 9 items!" );
5655 return ;
5756 }
58-
59- List <Material > mats = new ArrayList <>();
57+ List <RecipeChoice > mats = new ArrayList <>();
6058 for (String mat : ingredients ) {
59+ if (mat .startsWith ("EXACT:" )) {
60+ BendingItem bItem = ItemManager .get (mat .substring (6 ));
61+ if (bItem == item ) {
62+ logger .warning ("Recipe for '" + name + "' contains self, ignoring recipe." );
63+ return ;
64+ }
65+
66+ mats .add (new RecipeChoice .ExactChoice (bItem .internal ()));
67+ continue ;
68+ }
69+
6170 try {
62- mats .add (Material .valueOf (mat .toUpperCase ()));
71+ mats .add (new RecipeChoice . MaterialChoice ( Material .valueOf (mat .toUpperCase () )));
6372 } catch (Exception e ) {
6473 logger .warning ("Unable to parse material from '" + mat + "' in '" + name + "' recipe!" );
6574 return ;
6675 }
6776 }
6877
69- Recipe recipe = null ;
78+ CraftingRecipe recipe = null ;
7079
7180 if (isShaped ) {
7281 if (!config .contains (PATH + ".Shape" )) {
7382 logger .warning ("Recipe for '" + name + "' requires a shape under the config path 'Recipe.Shape'" );
7483 return ;
7584 }
7685
77- ShapedRecipe shaped = new ShapedRecipe (new NamespacedKey (JavaPlugin .getPlugin (ItemsPlugin .class ), name ), item );
78-
86+ ShapedRecipe shaped = new ShapedRecipe (new NamespacedKey (JavaPlugin .getPlugin (ItemsPlugin .class ), name ), item .internal ());
7987 shaped .shape (config .getStringList (PATH + ".Shape" ).toArray (new String [0 ]));
8088
8189 for (int i = 0 ; i < ingredients .size (); ++i ) {
8290 shaped .setIngredient (CHARS [i ], mats .get (i ));
8391 }
92+
93+ recipe = shaped ;
8494 } else {
85- ShapelessRecipe shapeless = new ShapelessRecipe (new NamespacedKey (JavaPlugin .getPlugin (ItemsPlugin .class ), name ), item );
95+ ShapelessRecipe shapeless = new ShapelessRecipe (new NamespacedKey (JavaPlugin .getPlugin (ItemsPlugin .class ), name ), item . internal () );
8696
87- for (Material ingredient : mats ) {
97+ for (RecipeChoice ingredient : mats ) {
8898 shapeless .addIngredient (ingredient );
8999 }
100+
101+ recipe = shapeless ;
90102 }
91103
92104 Bukkit .addRecipe (recipe );
0 commit comments