diff --git a/README.md b/README.md index 10c9609..f4c54be 100644 --- a/README.md +++ b/README.md @@ -159,21 +159,22 @@ All currently supported presets, and available filters for each preset: #### Configuration values -| Key | Value type | Description | -|------------------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| dropItem | true/false | Whether the blacksmith should drop the repaired item on the ground (instead of putting it into the player's inventory). | -| disableCoolDown | true/false | Whether to completely disable the cool-down between repairs. | -| disableDelay | true/false | Whether to completely disable the delay required to reforge an item. | -| failReforgeChance | 0-100 | The chance of the blacksmith failing to repair an item. | -| extraEnchantmentChance | 0-100 | The chance of the blacksmith adding an enchantment to an item. | -| maxEnchantments | 0-10 | The maximum number of different enchantments a blacksmith can add. | -| maxReforgeDelay | 0-3600 | The maximum number of seconds a player needs to wait for an item to be repaired. | -| minReforgeDelay | 0-3600 | The minimum number of seconds a player needs to wait for an item to be repaired. | -| reforgeCoolDown | 0-3600 | The cool-down, in seconds, a player has to wait between each time they use one specific blacksmith. | -| reforgeAbleItems | DIAMOND_LEGGINGS,GOLD-pickaxe,bow, etc. | Specifies which items this blacksmith is able to reforge. If set to "" or null, all normally repairable items can be repaired. If set to a list of items, only the items specified can be repaired. Some presets have been included for ease of use. Use a preset by specifying "preset:sword-smith" instead of a material such as "gold-pickaxe". | -| blacksmithTitle | text string | The title displayed as part of the message explaining that a blacksmith doesn't recognize a player's held item | -| enchantmentBlocklist | string list | A string list of all enchantments a blacksmith should not be allowed to add to items. | -| reforgeAnvils | true/false | Whether to allow the blacksmith to reforge anvils. If enabled, chipped and damaged anvils will be replaced with a normal anvil. | +| Key | Value type | Description | +|--------------------------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| dropItem | true/false | Whether the blacksmith should drop the repaired item on the ground (instead of putting it into the player's inventory). | +| disableCoolDown | true/false | Whether to completely disable the cool-down between repairs. | +| disableDelay | true/false | Whether to completely disable the delay required to reforge an item. | +| failReforgeChance | 0-100 | The chance of the blacksmith failing to repair an item (further damaging it, or just repairing it a bit), and either removing or downgrading all enchantments (if failReforgeRemovesEnchantments is true). | +| failReforgeRemovesEnchantments | true/false | Whether a failed reforge should remove or downgrade all enchantments on the item. | +| extraEnchantmentChance | 0-100 | The chance of the blacksmith adding an enchantment to an item. | +| maxEnchantments | 0-10 | The maximum number of different enchantments a blacksmith can add. | +| maxReforgeDelay | 0-3600 | The maximum number of seconds a player needs to wait for an item to be repaired. | +| minReforgeDelay | 0-3600 | The minimum number of seconds a player needs to wait for an item to be repaired. | +| reforgeCoolDown | 0-3600 | The cool-down, in seconds, a player has to wait between each time they use one specific blacksmith. | +| reforgeAbleItems | DIAMOND_LEGGINGS,GOLD-pickaxe,bow, etc. | Specifies which items this blacksmith is able to reforge. If set to "" or null, all normally repairable items can be repaired. If set to a list of items, only the items specified can be repaired. Some presets have been included for ease of use. Use a preset by specifying "preset:sword-smith" instead of a material such as "gold-pickaxe". | +| blacksmithTitle | text string | The title displayed as part of the message explaining that a blacksmith doesn't recognize a player's held item | +| enchantmentBlocklist | string list | A string list of all enchantments a blacksmith should not be allowed to add to items. | +| reforgeAnvils | true/false | Whether to allow the blacksmith to reforge anvils. If enabled, chipped and damaged anvils will be replaced with a normal anvil. | #### Messages diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java index 56c81fe..f46d0e8 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java @@ -17,6 +17,12 @@ public enum NPCSetting { */ FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"), + /** + * The setting for whether failing a reforging should downgrade/remove enchantments as well + */ + FAIL_REMOVE_ENCHANTMENTS("failReforgeRemovesEnchantments", SettingValueType.BOOLEAN, false, + "failReforgeRemovesEnchantments"), + /** * The setting for the chance of an additional enchantment being added */ diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java index 885381e..b1ad4cb 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java @@ -258,6 +258,15 @@ public class NPCSettings { return asInt(NPCSetting.FAIL_CHANCE); } + /** + * Gets whether a failed reforging should remove/downgrade enchantments + * + * @return
Whether enchantments should be removed
+ */ + public boolean getFailRemovesEnchantments() { + return asBoolean(NPCSetting.FAIL_REMOVE_ENCHANTMENTS); + } + /** * Gets the chance for adding an extra enchantment to an item * @@ -282,7 +291,7 @@ public class NPCSettings { * @returnWhether to drop reforged items on the ground
*/ public boolean getDropItem() { - return ConfigHelper.asBoolean(getValue(NPCSetting.DROP_ITEM)); + return asBoolean(NPCSetting.DROP_ITEM); } /** @@ -318,7 +327,7 @@ public class NPCSettings { * @returnTrue if this blacksmith is able to repair anvils
*/ public boolean getRepairAnvils() { - return ConfigHelper.asBoolean(getValue(NPCSetting.REPAIR_ANVILS)); + return asBoolean(NPCSetting.REPAIR_ANVILS); } /** @@ -343,6 +352,16 @@ public class NPCSettings { return getValue(setting).toString(); } + /** + * Gets the boolean value of the given setting + * + * @param settingThe setting to get the value of
+ * @returnThe value of the given setting as a boolean
+ */ + private boolean asBoolean(NPCSetting setting) { + return ConfigHelper.asBoolean(getValue(setting)); + } + /** * Gets the value of a setting, using the default if not set * diff --git a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java index 365d0d7..95188b7 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java @@ -133,14 +133,19 @@ public class ReforgeSession implements Runnable { itemToReforge.setType(Material.ANVIL); } - // Add random enchantments + //See if a random roll (0-99) is less than extraEnchantmentChance, and add a random enchantment int roll = random.nextInt(100); - if (!(roll < config.getExtraEnchantmentChance() && - itemToReforge.getEnchantments().keySet().size() < config.getMaxEnchantments())) { - // Abort if randomness isn't on our side, or if max enchantments has been reached - return; + if (roll < config.getExtraEnchantmentChance() && + itemToReforge.getEnchantments().keySet().size() < config.getMaxEnchantments() && + !ItemHelper.isAnvil(itemToReforge.getType(), false)) { + addRandomEnchantment(); } + } + /** + * Adds a random enchantment to the currently reforged item + */ + private void addRandomEnchantment() { //Find usable enchantments first List