@@ -95,6 +95,8 @@ public void handleClick(InventoryClickEvent event) {
9595 } else {
9696 event .getInventory ().getItem (templateSlot ).setAmount (amount );
9797 }
98+
99+ ((Player ) event .getWhoClicked ()).updateInventory ();
98100 }
99101
100102 if (event .getInventory ().getItem (itemSlot ) != null ) {
@@ -104,6 +106,8 @@ public void handleClick(InventoryClickEvent event) {
104106 } else {
105107 event .getInventory ().getItem (itemSlot ).setAmount (amount );
106108 }
109+
110+ ((Player ) event .getWhoClicked ()).updateInventory ();
107111 }
108112
109113 if (event .getInventory ().getItem (upgradeSlot ) != null ) {
@@ -113,6 +117,8 @@ public void handleClick(InventoryClickEvent event) {
113117 } else {
114118 event .getInventory ().getItem (upgradeSlot ).setAmount (amount );
115119 }
120+
121+ ((Player ) event .getWhoClicked ()).updateInventory ();
116122 }
117123
118124 return ;
@@ -198,50 +204,73 @@ private void updateGui(Inventory inv) {
198204 ItemStack finalAddition = addition ;
199205 ItemStack finalBase = base ;
200206
201- Iterator <Recipe > recipeIterator = Bukkit .getServer ().recipeIterator ();
202- while (recipeIterator .hasNext ()) {
203- inv .setItem (outputSlot , new ItemStack (Material .AIR ));
204- Recipe recipe = recipeIterator .next ();
205-
206- if (recipe instanceof SmithingTrimRecipe trimRecipe ) {
207- boolean test1 = trimRecipe .getTemplate ().test (finalTemplate );
208- boolean test2 = trimRecipe .getBase ().test (finalBase );
209- boolean test3 = trimRecipe .getAddition ().test (finalAddition );
210-
211- if (test1 && test2 && test3 ) {
212- ItemStack clone = finalBase .clone ();
213- ItemMeta meta = clone .getItemMeta ();
214- if (meta instanceof ArmorMeta armorMeta ) {
215- ArmorTrim trim = armorTrim (finalAddition , finalTemplate );
216-
217- armorMeta .setTrim (trim );
218- clone .setItemMeta (armorMeta );
219- }
220-
221- inv .setItem (outputSlot , clone );
222- break ;
223- } else {
224- inv .setItem (outputSlot , new ItemStack (Material .AIR ));
207+ // Very very very ugly solution, but I guess, it works!
208+ boolean successful = checkRecipe (inv , finalBase , finalAddition , finalTemplate );
209+ if (!successful ) {
210+ successful = checkRecipe (inv , finalBase , finalTemplate , finalAddition );
211+ }
212+ if (!successful ) {
213+ successful = checkRecipe (inv , finalTemplate , finalBase , finalAddition );
214+ }
215+ if (!successful ) {
216+ successful = checkRecipe (inv , finalTemplate , finalAddition , finalBase );
217+ }
218+ if (!successful ) {
219+ successful = checkRecipe (inv , finalAddition , finalBase , finalTemplate );
220+ }
221+ if (!successful ) {
222+ checkRecipe (inv , finalAddition , finalTemplate , finalBase );
223+ }
224+
225+ }, 0L );
226+ }
227+
228+ private boolean checkRecipe (Inventory inventory , ItemStack finalTemplate , ItemStack finalBase , ItemStack finalAddition ) {
229+ Iterator <Recipe > recipeIterator = Bukkit .getServer ().recipeIterator ();
230+ while (recipeIterator .hasNext ()) {
231+ inventory .setItem (outputSlot , new ItemStack (Material .AIR ));
232+ Recipe recipe = recipeIterator .next ();
233+
234+ if (recipe instanceof SmithingTrimRecipe trimRecipe ) {
235+ boolean test1 = trimRecipe .getTemplate ().test (finalTemplate );
236+ boolean test2 = trimRecipe .getBase ().test (finalBase );
237+ boolean test3 = trimRecipe .getAddition ().test (finalAddition );
238+
239+ if (test1 && test2 && test3 ) {
240+ ItemStack clone = finalBase .clone ();
241+ ItemMeta meta = clone .getItemMeta ();
242+ if (meta instanceof ArmorMeta armorMeta ) {
243+ ArmorTrim trim = armorTrim (finalAddition , finalTemplate );
244+
245+ armorMeta .setTrim (trim );
246+ clone .setItemMeta (armorMeta );
225247 }
248+
249+ inventory .setItem (outputSlot , clone );
250+ return true ;
251+ } else {
252+ inventory .setItem (outputSlot , new ItemStack (Material .AIR ));
226253 }
254+ }
227255
228- if (recipe instanceof SmithingTransformRecipe transformRecipe ) {
229- boolean test1 = transformRecipe .getTemplate ().getItemStack ().getType () == finalTemplate .getType ();
230- boolean test2 = transformRecipe .getBase ().getItemStack ().getType () == finalBase .getType ();
231- ItemMeta baseItemMeta = finalBase .getItemMeta ();
232- boolean test3 = transformRecipe .getAddition ().getItemStack ().getType () == finalAddition .getType ();
233-
234- if (test1 && test2 && test3 ) {
235- ItemStack item = transformRecipe .getResult ();
236- item .setItemMeta (baseItemMeta );
237- inv .setItem (outputSlot , item );
238- break ;
239- } else {
240- inv .setItem (outputSlot , new ItemStack (Material .AIR ));
241- }
256+ if (recipe instanceof SmithingTransformRecipe transformRecipe ) {
257+ boolean test1 = transformRecipe .getTemplate ().test (finalTemplate );
258+ boolean test2 = transformRecipe .getBase ().test (finalBase );
259+ ItemMeta baseItemMeta = finalBase .getItemMeta ();
260+ boolean test3 = transformRecipe .getAddition ().test (finalAddition );
261+
262+ if (test1 && test2 && test3 ) {
263+ ItemStack item = transformRecipe .getResult ();
264+ item .setItemMeta (baseItemMeta );
265+ inventory .setItem (outputSlot , item );
266+ return true ;
267+ } else {
268+ inventory .setItem (outputSlot , new ItemStack (Material .AIR ));
242269 }
243270 }
244- }, 0L );
271+ }
272+
273+ return false ;
245274 }
246275
247276 @ Nullable
0 commit comments