From 531b12a6fa91a603ce5b784e7d0168f07e6becf3 Mon Sep 17 00:00:00 2001 From: Zrips Date: Sat, 27 Nov 2021 17:16:21 +0200 Subject: [PATCH] Taking into consideration changed durability on the item --- .../jobs/listeners/JobsPaymentListener.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 01609c11..f4da8b6a 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -736,7 +736,6 @@ public final class JobsPaymentListener implements Listener { for (ItemStack OneDye : dyeStack) { Jobs.action(jPlayer, new ItemActionInfo(OneDye, ActionType.DYE)); } - return; } @@ -857,6 +856,33 @@ public final class JobsPaymentListener implements Listener { return null; } + private static boolean changed(ItemStack first, ItemStack second, ItemStack result) { + + if (result == null) + return true; + + ItemStack itemToCheck = first; + if (first == null || first.getType() != result.getType()) + itemToCheck = second; + + if (itemToCheck == null) + return true; + + if (itemToCheck.getType() != result.getType()) + return true; + + try { + if (new CMIItemStack(itemToCheck).getDurability() != new CMIItemStack(result).getDurability() || itemToCheck.getEnchantments().size() != result.getEnchantments().size()) + return true; + } catch (Throwable e) { + } + + if (itemToCheck.getEnchantments().size() != result.getEnchantments().size()) + return true; + + return false; + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryRepair(InventoryClickEvent event) { // If event is nothing or place, do nothing @@ -979,8 +1005,13 @@ public final class JobsPaymentListener implements Listener { if (enchantName != null) Jobs.action(jPlayer, new EnchantActionInfo(enchantName, oneEnchant.getValue(), ActionType.ENCHANT)); } - } else if (secondSlotItem == null || secondSlotItem.getType() != Material.ENCHANTED_BOOK) // Enchanted books does not have durability + } else if (secondSlotItem == null || secondSlotItem.getType() != Material.ENCHANTED_BOOK) { // Enchanted books does not have durability + + if (!changed(firstSlot, secondSlotItem, resultStack)) + return; + Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR)); + } } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)