diff --git a/src/main/java/net/knarcraft/blacksmith/config/GlobalSetting.java b/src/main/java/net/knarcraft/blacksmith/config/GlobalSetting.java index 4cc86d0..4613600 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/GlobalSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/GlobalSetting.java @@ -49,15 +49,7 @@ public enum GlobalSetting { * The cost for repairing a damaged anvil */ ANVIL_DAMAGED_COST("global.damagedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 20.0, - "damagedAnvilReforgingCost"), - - /** - * Whether to disable the normal limitation for which items are reforgeAble - * - *

If true, all items instanceof Damageable can be reforged

- */ - DISABLE_MATERIAL_LIMITATION("global.disableMaterialLimitation", SettingValueType.BOOLEAN, false, - "disableMaterialLimitation"); + "damagedAnvilReforgingCost"); private final String path; private final String parent; diff --git a/src/main/java/net/knarcraft/blacksmith/config/GlobalSettings.java b/src/main/java/net/knarcraft/blacksmith/config/GlobalSettings.java index 92da7cc..b0b4223 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/GlobalSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/GlobalSettings.java @@ -295,15 +295,6 @@ public class GlobalSettings { } } - /** - * Whether to disable the "EnchantmentTarget.BREAKABLE" limitation - * - * @return

True if the material limitation is disabled

- */ - public boolean disableMaterialLimitation() { - return asBoolean(GlobalSetting.DISABLE_MATERIAL_LIMITATION); - } - /** * Gets the given value as a boolean * diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java index 78b55bc..885381e 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java @@ -460,8 +460,7 @@ public class NPCSettings { } Material material = InputParsingHelper.matchMaterial(item); - boolean limitationDisabled = BlacksmithPlugin.getInstance().getSettings().disableMaterialLimitation(); - if (material != null && ItemHelper.isRepairable(new ItemStack(material, 1), limitationDisabled)) { + if (material != null && ItemHelper.isRepairable(new ItemStack(material, 1))) { if (!blacklist) { reforgeAbleItems.add(material); } else { diff --git a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java index 1ff6ea4..623fa79 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java @@ -179,8 +179,7 @@ public class BlacksmithTrait extends Trait { List reforgeAbleItems = config.getReforgeAbleItems(); boolean notHoldingAnvil = !this.config.getRepairAnvils() || !ItemHelper.isAnvil(hand.getType(), false); - boolean limitationDisabled = BlacksmithPlugin.getInstance().getSettings().disableMaterialLimitation(); - boolean notHoldingRepairable = !ItemHelper.isRepairable(hand, limitationDisabled) || + boolean notHoldingRepairable = !ItemHelper.isRepairable(hand) || (!reforgeAbleItems.isEmpty() && !reforgeAbleItems.contains(hand.getType())); if (notHoldingAnvil && notHoldingRepairable) { diff --git a/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java b/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java index 854c206..c4f76bb 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java @@ -1,7 +1,6 @@ package net.knarcraft.blacksmith.util; import org.bukkit.Material; -import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; @@ -20,13 +19,11 @@ public final class ItemHelper { /** * Gets whether the given item is repairable * - * @param item

The item to check

- * @param disableMaterialLimitation

Whether to disable the EnchantmentTarget.BREAKABLE limitation

+ * @param item

The item to check

* @return

True if the item is repairable

*/ - public static boolean isRepairable(ItemStack item, boolean disableMaterialLimitation) { - return item.getItemMeta() instanceof Damageable && (disableMaterialLimitation || - EnchantmentTarget.BREAKABLE.includes(item)); + public static boolean isRepairable(ItemStack item) { + return item.getItemMeta() instanceof Damageable && getMaxDurability(item) > 0; } /** @@ -79,7 +76,7 @@ public final class ItemHelper { List reforgeAbleMaterials = new ArrayList<>(); for (Material material : Material.values()) { ItemStack item = new ItemStack(material); - if (item.getItemMeta() instanceof Damageable && EnchantmentTarget.BREAKABLE.includes(item)) { + if (isRepairable(item)) { reforgeAbleMaterials.add(material); } } diff --git a/src/main/java/net/knarcraft/blacksmith/util/SalvageHelper.java b/src/main/java/net/knarcraft/blacksmith/util/SalvageHelper.java index 6751e82..9163a7a 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/SalvageHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/SalvageHelper.java @@ -23,16 +23,14 @@ public final class SalvageHelper { * *

Note: Only items craft-able in a crafting table are salvageable. Netherite gear is therefore not salvageable.

* - * @param server

The server to get recipes from

- * @param salvagedItem

The item stack to salvage

- * @param ignoredSalvage

Any material which should not be returned as part of the salvage.

- * @param limitationDisabled

Whether the repairable item limitation is disabled

+ * @param server

The server to get recipes from

+ * @param salvagedItem

The item stack to salvage

+ * @param ignoredSalvage

Any material which should not be returned as part of the salvage.

* @return

The items to return to the user, or null if not salvageable

*/ - public static List getSalvage(Server server, ItemStack salvagedItem, List ignoredSalvage, - boolean limitationDisabled) { + public static List getSalvage(Server server, ItemStack salvagedItem, List ignoredSalvage) { if (salvagedItem == null || salvagedItem.getAmount() < 1 || - !ItemHelper.isRepairable(salvagedItem, limitationDisabled)) { + !ItemHelper.isRepairable(salvagedItem)) { return null; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b8f24c5..9176afd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -33,10 +33,6 @@ global: # The cost of fully repairing a damaged anvil damagedAnvilReforgingCost: 20.0 - - # This disables the EnchantmentTarget.BREAKABLE limitation. If set to true, all items able to have durability are seen - # as reforgeAble. This should not be set to true unless you have special needs. - disableMaterialLimitation: false # The settings which are set to any new NPC. To change any of these settings for an existing NPC, you must change the # Citizens NPC file, or use the /blacksmith command diff --git a/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java b/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java index 102032d..31a9e88 100644 --- a/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java +++ b/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java @@ -4,11 +4,11 @@ import be.seeseemelk.mockbukkit.MockBukkit; import net.knarcraft.blacksmith.CustomServerMock; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -36,27 +36,17 @@ public class ItemHelperTest { name.endsWith("_HELMET") || name.equals("ELYTRA") || name.endsWith("BOW") || name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS") || name.equals("TRIDENT") || name.equals("FISHING_ROD") || name.equals("FLINT_AND_STEEL") || name.equals("SHEARS")) { - assertTrue(ItemHelper.isRepairable(new ItemStack(material, 1), false)); + assertTrue(ItemHelper.isRepairable(new ItemStack(material, 1))); } } - assertFalse(ItemHelper.isRepairable(new ItemStack(Material.POTATO, 1), false)); - assertFalse(ItemHelper.isRepairable(new ItemStack(Material.DIRT, 1), false)); + assertFalse(ItemHelper.isRepairable(new ItemStack(Material.POTATO, 1))); + assertFalse(ItemHelper.isRepairable(new ItemStack(Material.DIRT, 1))); } @Test - public void isRepairableLimitDisabledTest() { - /*The assertFalse pert of this test is kind of pointless, as every material in the game seems to implement - Damageable */ - for (Material material : Material.values()) { - ItemStack itemStack = new ItemStack(material, 1); - if (new ItemStack(material, 1).getItemMeta() instanceof Damageable) { - assertTrue(ItemHelper.isRepairable(itemStack, true)); - } else { - assertFalse(ItemHelper.isRepairable(itemStack, true)); - } - } - assertTrue(ItemHelper.isRepairable(new ItemStack(Material.POTATO, 1), true)); - assertTrue(ItemHelper.isRepairable(new ItemStack(Material.DIRT, 1), true)); + public void getMaxDurabilityTest() { + assertEquals(1561, ItemHelper.getMaxDurability(new ItemStack(Material.DIAMOND_PICKAXE, 1))); + assertEquals(0, ItemHelper.getMaxDurability(new ItemStack(Material.POTATO, 1))); } } diff --git a/src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java b/src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java index 6092168..f54d9f4 100644 --- a/src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java +++ b/src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java @@ -40,14 +40,14 @@ public class SalvageHelperTest { @Test public void getNullForInvalidItemTest() { //Assert that a non-reforge-able item will return null - assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.POTATO, 1), null, false)); + assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.POTATO, 1), null)); } @Test public void getNullForLessThanOneItemTest() { //Assert that 0 or 1 items will return null - assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_AXE, 0), null, false)); - assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_SWORD, -1), null, false)); + assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_AXE, 0), null)); + assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_SWORD, -1), null)); } @Test @@ -57,7 +57,7 @@ public class SalvageHelperTest { expectedSalvage.add(new ItemStack(Material.STICK, 2)); ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 1); //Note: Conversion to sets makes sure the order doesn't matter - assertEquals(expectedSalvage, new HashSet<>(SalvageHelper.getSalvage(server, itemToSalvage, null, false))); + assertEquals(expectedSalvage, new HashSet<>(SalvageHelper.getSalvage(server, itemToSalvage, null))); } @Test @@ -67,7 +67,7 @@ public class SalvageHelperTest { expectedSalvage.add(new ItemStack(Material.STICK, 14)); ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 7); //Note: Conversion to sets makes sure the order doesn't matter - assertEquals(expectedSalvage, new HashSet<>(SalvageHelper.getSalvage(server, itemToSalvage, null, false))); + assertEquals(expectedSalvage, new HashSet<>(SalvageHelper.getSalvage(server, itemToSalvage, null))); } @Test @@ -82,7 +82,7 @@ public class SalvageHelperTest { damageable.setDamage(100); } itemToSalvage.setItemMeta(meta); - List salvage = SalvageHelper.getSalvage(server, itemToSalvage, null, false); + List salvage = SalvageHelper.getSalvage(server, itemToSalvage, null); //Assert that some items are given assertNotEquals(salvage, new ArrayList<>()); //Assert that a damaged item won't give full salvage @@ -102,7 +102,7 @@ public class SalvageHelperTest { damageable.setDamage(100); } itemToSalvage.setItemMeta(meta); - List salvage = SalvageHelper.getSalvage(server, itemToSalvage, ignoredSalvage, false); + List salvage = SalvageHelper.getSalvage(server, itemToSalvage, ignoredSalvage); //Assert that some items are given assertNotEquals(salvage, new ArrayList<>()); //Assert that a damaged diamond pickaxe with sticks ignored returns 2 diamonds a salvage