From ad56d515b29afc75128c0e4fee299f44c74626e4 Mon Sep 17 00:00:00 2001 From: xGinko Date: Tue, 6 Aug 2024 20:22:32 +0200 Subject: [PATCH] fix unbreakable module --- .../modules/illegals/items/Unbreakables.java | 35 +++++++++---------- .../modules/illegals/items/Unbreakables.java | 25 ++++++------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java index f4cfade09..1c7619a35 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java @@ -6,7 +6,6 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; import java.util.EnumSet; import java.util.List; @@ -53,12 +52,26 @@ public boolean shouldEnable() { @Override public ItemLegality legalityOf(ItemStack itemStack) { - if (itemStack == null || itemStack.getType().isAir()) { + if (itemStack == null || itemStack.getType().isAir() || !itemStack.hasItemMeta()) { return ItemLegality.LEGAL; } if (!useWhitelist || blacklistMode == whitelistedTypes.contains(itemStack.getType())) { - if (isUnbreakable(itemStack)) { + if (itemStack.getItemMeta().isUnbreakable()) { + return ItemLegality.ILLEGAL; + } + + Damageable damageable = (Damageable) itemStack.getItemMeta(); + + if (!damageable.hasDamage()) { + return ItemLegality.LEGAL; + } + + if (itemStack.getType().getMaxDurability() == 0) { + return ItemLegality.LEGAL; + } + + if (damageable.getDamage() > itemStack.getType().getMaxDurability() || damageable.getDamage() < 0) { return ItemLegality.ILLEGAL; } } @@ -77,20 +90,4 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) { itemStack.setAmount(0); } } - - private boolean isUnbreakable(ItemStack itemStack) { - if (!itemStack.hasItemMeta()) return false; - - ItemMeta meta = itemStack.getItemMeta(); - if (meta.isUnbreakable()) return true; - - Damageable damageMeta = (Damageable) meta; - if (!damageMeta.hasDamage()) return false; - - final short itemMaxDurability = itemStack.getType().getMaxDurability(); - if (itemMaxDurability == 0) return false; - - final int remainingDurability = itemMaxDurability - damageMeta.getDamage(); - return remainingDurability > itemMaxDurability || remainingDurability < 0; - } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java index c2aba9260..1047ea161 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/illegals/items/Unbreakables.java @@ -62,9 +62,19 @@ public ItemLegality legalityOf(ItemStack itemStack) { } if (!useWhitelist || blacklistMode == whitelistedTypes.contains(itemStack.getType())) { - if (isUnbreakable(itemStack)) { + if (itemStack.getItemMeta().isUnbreakable()) { return ItemLegality.ILLEGAL; } + + if (!skipZeroDurability || itemStack.getType().getMaxDurability() != 0) { + if (itemStack.getDurability() > itemStack.getType().getMaxDurability() || itemStack.getDurability() < 0) { + return ItemLegality.ILLEGAL; + } + } else { + if (itemStack.getDurability() > 2031) { + return ItemLegality.ILLEGAL; + } + } } if (checkStored) { @@ -81,17 +91,4 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) { itemStack.setAmount(0); } } - - private boolean isUnbreakable(ItemStack itemStack) { - final int durability = itemStack.getDurability(); - final short maxDurability = itemStack.getType().getMaxDurability(); - if (!skipZeroDurability || maxDurability != 0) { - if (durability > maxDurability) { - return true; - } - return durability < 0; - } else { - return durability > 2031; - } - } }