From cfe1827e145adc74117c2cc58bc23f4e2c3cf4ad Mon Sep 17 00:00:00 2001 From: Aria Date: Sat, 14 Dec 2019 01:32:58 +0100 Subject: [PATCH] Alternative validation code for buttons to prevent a bug in latest paper (And I actually remembered to delete debug messages this time!) --- .../Indyuce/mmoitems/api/util/IsSimilar.java | 17 +++++++++++++++++ .../mmoitems/gui/CraftingStationPreview.java | 9 +++++---- .../mmoitems/gui/CraftingStationView.java | 9 +++++---- .../mmoitems/manager/UpdaterManager.java | 3 ++- 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmoitems/api/util/IsSimilar.java diff --git a/src/main/java/net/Indyuce/mmoitems/api/util/IsSimilar.java b/src/main/java/net/Indyuce/mmoitems/api/util/IsSimilar.java new file mode 100644 index 00000000..1578eac9 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/api/util/IsSimilar.java @@ -0,0 +1,17 @@ +package net.Indyuce.mmoitems.api.util; + +import org.bukkit.inventory.ItemStack; + +import net.Indyuce.mmoitems.version.VersionMaterial; + +public class IsSimilar { + public static boolean check(ItemStack i1, ItemStack i2) { + if(i1.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) { + System.out.println("IS SIMILAR: head"); + return i1.toString().equals(i2.toString()); + } + + System.out.println("IS SIMILAR: non head"); + return i1.isSimilar(i2); + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java b/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java index 9d4c194d..f5a0bbf6 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java @@ -19,6 +19,7 @@ import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe; import net.Indyuce.mmoitems.api.crafting.recipe.RecipeInfo; import net.Indyuce.mmoitems.api.crafting.recipe.UpgradingRecipe; import net.Indyuce.mmoitems.api.item.plugin.ConfigItem; +import net.Indyuce.mmoitems.api.util.IsSimilar; import net.md_5.bungee.api.ChatColor; public class CraftingStationPreview extends PluginInventory { @@ -97,26 +98,26 @@ public class CraftingStationPreview extends PluginInventory { if (!MMOUtils.isPluginItem(event.getCurrentItem(), false)) return; - if (event.getCurrentItem().isSimilar(ConfigItem.CONFIRM.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.CONFIRM.getItem())) { CraftingStationView csv = new CraftingStationView(player, station, previousPage); csv.processRecipe(recipe); csv.open(); return; } - if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_PAGE.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.PREVIOUS_PAGE.getItem())) { page--; open(); return; } - if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_PAGE.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.NEXT_PAGE.getItem())) { page++; open(); return; } - if (event.getCurrentItem().isSimilar(ConfigItem.BACK.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.BACK.getItem())) { new CraftingStationView(player, station, previousPage).open(); return; } diff --git a/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java b/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java index d5cb01a4..94a9a606 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java @@ -25,6 +25,7 @@ import net.Indyuce.mmoitems.api.event.crafting.PlayerUseRecipeEvent; import net.Indyuce.mmoitems.api.item.NBTItem; import net.Indyuce.mmoitems.api.item.plugin.ConfigItem; import net.Indyuce.mmoitems.api.player.PlayerData; +import net.Indyuce.mmoitems.api.util.IsSimilar; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.listener.CustomSoundListener; @@ -129,25 +130,25 @@ public class CraftingStationView extends PluginInventory { if (!MMOUtils.isPluginItem(event.getCurrentItem(), false)) return; - if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_IN_QUEUE.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.PREVIOUS_IN_QUEUE.getItem())) { queueOffset--; open(); return; } - if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_IN_QUEUE.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.NEXT_IN_QUEUE.getItem())) { queueOffset++; open(); return; } - if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_PAGE.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.NEXT_PAGE.getItem())) { page++; open(); return; } - if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_PAGE.getItem())) { + if (IsSimilar.check(event.getCurrentItem(), ConfigItem.PREVIOUS_PAGE.getItem())) { page--; open(); return; diff --git a/src/main/java/net/Indyuce/mmoitems/manager/UpdaterManager.java b/src/main/java/net/Indyuce/mmoitems/manager/UpdaterManager.java index 0da596dc..a807f2ed 100644 --- a/src/main/java/net/Indyuce/mmoitems/manager/UpdaterManager.java +++ b/src/main/java/net/Indyuce/mmoitems/manager/UpdaterManager.java @@ -24,6 +24,7 @@ import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.MMOItem; import net.Indyuce.mmoitems.api.item.NBTItem; +import net.Indyuce.mmoitems.api.util.IsSimilar; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.version.durability.DurabilityHandler; @@ -78,7 +79,7 @@ public class UpdaterManager implements Listener { return; ItemStack newItem = getUpdated(item); - if (!newItem.isSimilar(item)) + if (!IsSimilar.check(newItem, item)) event.setCurrentItem(newItem); }