diff --git a/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java b/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java index 66a5951..1cd0986 100644 --- a/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java +++ b/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java @@ -7,7 +7,7 @@ import net.knarcraft.blacksmith.command.BlackSmithEditCommand; import net.knarcraft.blacksmith.command.BlackSmithEditTabCompleter; import net.knarcraft.blacksmith.command.PresetCommand; import net.knarcraft.blacksmith.command.PresetTabCompleter; -import net.knarcraft.blacksmith.config.GlobalSettings; +import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings; import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage; import net.knarcraft.blacksmith.listener.NPCClickListener; import net.knarcraft.blacksmith.listener.PlayerListener; @@ -33,7 +33,7 @@ import java.util.logging.Level; public class BlacksmithPlugin extends JavaPlugin { private static BlacksmithPlugin instance; - private GlobalSettings config; + private GlobalBlacksmithSettings config; private static Translator translator; private static StringFormatter stringFormatter; @@ -67,7 +67,7 @@ public class BlacksmithPlugin extends JavaPlugin { * * @return

Settings for the blacksmith plugin

*/ - public GlobalSettings getSettings() { + public GlobalBlacksmithSettings getSettings() { return config; } @@ -115,7 +115,7 @@ public class BlacksmithPlugin extends JavaPlugin { this.saveConfig(); //Load settings - config = new GlobalSettings(this); + config = new GlobalBlacksmithSettings(this); config.load(); //Prepare the translator diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java index 5449e39..11b649c 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java @@ -1,9 +1,9 @@ package net.knarcraft.blacksmith.command; import net.knarcraft.blacksmith.BlacksmithPlugin; -import net.knarcraft.blacksmith.config.GlobalSetting; -import net.knarcraft.blacksmith.config.GlobalSettings; -import net.knarcraft.blacksmith.config.NPCSetting; +import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSetting; +import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings; +import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting; import net.knarcraft.blacksmith.config.SettingValueType; import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage; import net.knarcraft.blacksmith.formatting.ItemType; @@ -38,46 +38,46 @@ public class BlackSmithConfigCommand implements CommandExecutor { if (commandName.equalsIgnoreCase("reload")) { return new ReloadCommand().onCommand(sender, command, label, args); } - GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings(); + GlobalBlacksmithSettings settings = BlacksmithPlugin.getInstance().getSettings(); //Find which global setting the user has specified, if any - GlobalSetting detectedGlobalSetting = null; - for (GlobalSetting globalSetting : GlobalSetting.values()) { - if (commandName.equalsIgnoreCase(globalSetting.getCommandName())) { - detectedGlobalSetting = globalSetting; + GlobalBlacksmithSetting detectedGlobalBlacksmithSetting = null; + for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) { + if (commandName.equalsIgnoreCase(globalBlacksmithSetting.getCommandName())) { + detectedGlobalBlacksmithSetting = globalBlacksmithSetting; break; } } //Find which npc setting the user has specified, if any - NPCSetting detectedNPCSetting = null; - for (NPCSetting npcSetting : NPCSetting.values()) { - if (commandName.equalsIgnoreCase(npcSetting.getCommandName())) { - detectedNPCSetting = npcSetting; + BlacksmithNPCSetting detectedBlacksmithNPCSetting = null; + for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) { + if (commandName.equalsIgnoreCase(blacksmithNpcSetting.getCommandName())) { + detectedBlacksmithNPCSetting = blacksmithNpcSetting; break; } } //Display the current value of a setting if (args.length == 1) { - return displayCurrentValue(detectedGlobalSetting, detectedNPCSetting, settings, sender); + return displayCurrentValue(detectedGlobalBlacksmithSetting, detectedBlacksmithNPCSetting, settings, sender); } else if (args.length == 2 && isSpecialCase(commandName)) { - if (displaySpecialCaseValue(args[1], sender, detectedGlobalSetting, settings)) { + if (displaySpecialCaseValue(args[1], sender, detectedGlobalBlacksmithSetting, settings)) { return true; } } //Update the value of a special-case setting - if (args.length == 3 && updateSpecialCase(settings, detectedGlobalSetting, args, sender)) { + if (args.length == 3 && updateSpecialCase(settings, detectedGlobalBlacksmithSetting, args, sender)) { return true; } //Change the value of the specified setting - if ((detectedGlobalSetting != null && - TypeValidationHelper.isValid(detectedGlobalSetting.getValueType(), args[1], sender)) || - (detectedNPCSetting != null && - TypeValidationHelper.isValid(detectedNPCSetting.getValueType(), args[1], sender))) { - return changeValue(args, detectedGlobalSetting, detectedNPCSetting, settings, sender); + if ((detectedGlobalBlacksmithSetting != null && + TypeValidationHelper.isValid(detectedGlobalBlacksmithSetting.getValueType(), args[1], sender)) || + (detectedBlacksmithNPCSetting != null && + TypeValidationHelper.isValid(detectedBlacksmithNPCSetting.getValueType(), args[1], sender))) { + return changeValue(args, detectedGlobalBlacksmithSetting, detectedBlacksmithNPCSetting, settings, sender); } else { return false; } @@ -87,28 +87,28 @@ public class BlackSmithConfigCommand implements CommandExecutor { * Changes the value of the setting defined in the user's input * * @param args

The arguments given by the user

- * @param detectedGlobalSetting

The global setting recognized from the input, if any

- * @param detectedNPCSetting

The NPC setting recognized from the input, if any

+ * @param detectedGlobalBlacksmithSetting

The global setting recognized from the input, if any

+ * @param detectedBlacksmithNPCSetting

The NPC setting recognized from the input, if any

* @param settings

The global settings object to get settings from

* @param sender

The command sender to display any output to

* @return

True if the value was successfully changed

*/ - private boolean changeValue(String[] args, GlobalSetting detectedGlobalSetting, NPCSetting detectedNPCSetting, - GlobalSettings settings, CommandSender sender) { + private boolean changeValue(String[] args, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, BlacksmithNPCSetting detectedBlacksmithNPCSetting, + GlobalBlacksmithSettings settings, CommandSender sender) { String newValue = args[1]; - if (detectedGlobalSetting != null) { - settings.changeValue(detectedGlobalSetting, newValue); + if (detectedGlobalBlacksmithSetting != null) { + settings.changeValue(detectedGlobalBlacksmithSetting, newValue); BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, - getValueChangedMessage(detectedGlobalSetting.getCommandName(), newValue)); + getValueChangedMessage(detectedGlobalBlacksmithSetting.getCommandName(), newValue)); return true; - } else if (detectedNPCSetting != null) { + } else if (detectedBlacksmithNPCSetting != null) { //This makes sure all arguments are treated as a sentence - if (detectedNPCSetting.getValueType() == SettingValueType.STRING) { + if (detectedBlacksmithNPCSetting.getValueType() == SettingValueType.STRING) { newValue = String.join(" ", Arrays.asList(args).subList(1, args.length)); } - settings.changeValue(detectedNPCSetting, newValue); + settings.changeValue(detectedBlacksmithNPCSetting, newValue); BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, - getValueChangedMessage(detectedNPCSetting.getCommandName(), newValue)); + getValueChangedMessage(detectedBlacksmithNPCSetting.getCommandName(), newValue)); return true; } else { return false; @@ -118,28 +118,28 @@ public class BlackSmithConfigCommand implements CommandExecutor { /** * Displays the current value of the selected setting * - * @param detectedGlobalSetting

The global setting recognized from the input, if any

- * @param detectedNPCSetting

The NPC setting recognized from the input, if any

+ * @param detectedGlobalBlacksmithSetting

The global setting recognized from the input, if any

+ * @param detectedBlacksmithNPCSetting

The NPC setting recognized from the input, if any

* @param settings

The global settings object to get settings from

* @param sender

The command sender to display any output to

* @return

True if a settings was successfully displayed

*/ - private boolean displayCurrentValue(GlobalSetting detectedGlobalSetting, NPCSetting detectedNPCSetting, - GlobalSettings settings, CommandSender sender) { + private boolean displayCurrentValue(GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, BlacksmithNPCSetting detectedBlacksmithNPCSetting, + GlobalBlacksmithSettings settings, CommandSender sender) { String settingValue; String correctCommandName; boolean printRawValue = false; //Find the value of the specified setting //TODO: See if there's a way to remove this duplication - if (detectedGlobalSetting != null) { - settingValue = String.valueOf(settings.getRawValue(detectedGlobalSetting)); - correctCommandName = detectedGlobalSetting.getCommandName(); - } else if (detectedNPCSetting != null) { - settingValue = String.valueOf(settings.getRawValue(detectedNPCSetting)); - correctCommandName = detectedNPCSetting.getCommandName(); + if (detectedGlobalBlacksmithSetting != null) { + settingValue = String.valueOf(settings.getRawValue(detectedGlobalBlacksmithSetting)); + correctCommandName = detectedGlobalBlacksmithSetting.getCommandName(); + } else if (detectedBlacksmithNPCSetting != null) { + settingValue = String.valueOf(settings.getRawValue(detectedBlacksmithNPCSetting)); + correctCommandName = detectedBlacksmithNPCSetting.getCommandName(); //For messages, print an additional raw value showing which color codes are used - if (detectedNPCSetting.getPath().startsWith("defaults.messages")) { + if (detectedBlacksmithNPCSetting.getPath().startsWith("defaults.messages")) { printRawValue = true; } } else { @@ -165,15 +165,15 @@ public class BlackSmithConfigCommand implements CommandExecutor { * @param settings

The settings object to query

* @return

True if the value was successfully displayed

*/ - private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalSetting setting, - GlobalSettings settings) { - if (setting == GlobalSetting.BASE_PRICE || setting == GlobalSetting.PRICE_PER_DURABILITY_POINT) { + private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalBlacksmithSetting setting, + GlobalBlacksmithSettings settings) { + if (setting == GlobalBlacksmithSetting.BASE_PRICE || setting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) { Material material = InputParsingHelper.matchMaterial(selector); if (material == null) { return false; } String currentValue; - if (setting == GlobalSetting.BASE_PRICE) { + if (setting == GlobalBlacksmithSetting.BASE_PRICE) { currentValue = String.valueOf(settings.getBasePrice(material)); } else { currentValue = String.valueOf(settings.getPricePerDurabilityPoint(material)); @@ -182,7 +182,7 @@ public class BlackSmithConfigCommand implements CommandExecutor { BlacksmithTranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(), ItemType.MATERIAL, material.name(), currentValue)); return true; - } else if (setting == GlobalSetting.ENCHANTMENT_COST) { + } else if (setting == GlobalBlacksmithSetting.ENCHANTMENT_COST) { Enchantment enchantment = InputParsingHelper.matchEnchantment(selector); if (enchantment == null) { return false; @@ -204,21 +204,21 @@ public class BlackSmithConfigCommand implements CommandExecutor { * @return

True if the command is a special case

*/ private boolean isSpecialCase(String commandName) { - return commandName.equalsIgnoreCase(GlobalSetting.BASE_PRICE.getCommandName()) || - commandName.equalsIgnoreCase(GlobalSetting.PRICE_PER_DURABILITY_POINT.getCommandName()) || - commandName.equalsIgnoreCase(GlobalSetting.ENCHANTMENT_COST.getCommandName()); + return commandName.equalsIgnoreCase(GlobalBlacksmithSetting.BASE_PRICE.getCommandName()) || + commandName.equalsIgnoreCase(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getCommandName()) || + commandName.equalsIgnoreCase(GlobalBlacksmithSetting.ENCHANTMENT_COST.getCommandName()); } /** * Updates a special-case configuration value if a special-case is encountered * * @param settings

The settings to modify

- * @param detectedGlobalSetting

The global setting specified

+ * @param detectedGlobalBlacksmithSetting

The global setting specified

* @param args

All arguments given

* @param sender

The command sender to notify if successful

* @return

True if already handled as a special case

*/ - private boolean updateSpecialCase(GlobalSettings settings, GlobalSetting detectedGlobalSetting, String[] args, + private boolean updateSpecialCase(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, String[] args, CommandSender sender) { if (InputParsingHelper.isEmpty(args[2])) { args[2] = "-1"; @@ -228,10 +228,10 @@ public class BlackSmithConfigCommand implements CommandExecutor { double newPrice = Double.parseDouble(args[2]); String newValue = String.valueOf(newPrice); - if (detectedGlobalSetting == GlobalSetting.BASE_PRICE || - detectedGlobalSetting == GlobalSetting.PRICE_PER_DURABILITY_POINT) { - return updatePriceSpecialCase(settings, detectedGlobalSetting, args[1], newPrice, sender); - } else if (detectedGlobalSetting == GlobalSetting.ENCHANTMENT_COST) { + if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE || + detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) { + return updatePriceSpecialCase(settings, detectedGlobalBlacksmithSetting, args[1], newPrice, sender); + } else if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.ENCHANTMENT_COST) { //Update enchantment cost for an item Enchantment enchantment = InputParsingHelper.matchEnchantment(args[1]); if (enchantment == null) { @@ -241,7 +241,7 @@ public class BlackSmithConfigCommand implements CommandExecutor { String itemChanged = enchantment.getKey().getKey(); settings.setEnchantmentCost(enchantment, newPrice); BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, - BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalSetting.getCommandName(), + BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalBlacksmithSetting.getCommandName(), itemType, itemChanged, newValue)); return true; } else { @@ -253,27 +253,27 @@ public class BlackSmithConfigCommand implements CommandExecutor { * Updates a special case price configuration value if a special case is encountered * * @param settings

The settings to modify

- * @param detectedGlobalSetting

The global setting specified

+ * @param detectedGlobalBlacksmithSetting

The global setting specified

* @param materialName

The material name to update the price for

* @param newPrice

The new price to update to

* @param sender

The command sender to respond to

* @return

True if the input was valid, and the item(s) was/were updated

*/ - private boolean updatePriceSpecialCase(GlobalSettings settings, GlobalSetting detectedGlobalSetting, + private boolean updatePriceSpecialCase(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, String materialName, double newPrice, CommandSender sender) { ItemType itemType = ItemType.MATERIAL; String itemChanged; //Update base price or price per durability point for an item if (materialName.contains("*")) { itemChanged = materialName; - updateAllMatchedPrices(settings, detectedGlobalSetting, materialName, newPrice); + updateAllMatchedPrices(settings, detectedGlobalBlacksmithSetting, materialName, newPrice); } else { Material material = InputParsingHelper.matchMaterial(materialName); if (material == null) { return false; } itemChanged = material.name(); - if (detectedGlobalSetting == GlobalSetting.BASE_PRICE) { + if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE) { settings.setBasePrice(material, newPrice); } else { settings.setPricePerDurabilityPoint(material, newPrice); @@ -281,7 +281,7 @@ public class BlackSmithConfigCommand implements CommandExecutor { } BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, - BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalSetting.getCommandName(), + BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalBlacksmithSetting.getCommandName(), itemType, itemChanged, String.valueOf(newPrice))); return true; } @@ -290,11 +290,11 @@ public class BlackSmithConfigCommand implements CommandExecutor { * Updates all materials matching the material name wildcard * * @param settings

The settings to modify

- * @param detectedGlobalSetting

The global setting specified

+ * @param detectedGlobalBlacksmithSetting

The global setting specified

* @param materialName

The wildcard material name to update cost for

* @param newPrice

The new cost for the matched items

*/ - private void updateAllMatchedPrices(GlobalSettings settings, GlobalSetting detectedGlobalSetting, + private void updateAllMatchedPrices(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, String materialName, double newPrice) { String search = InputParsingHelper.regExIfy(materialName); for (Material material : ItemHelper.getAllReforgeAbleMaterials()) { @@ -302,7 +302,7 @@ public class BlackSmithConfigCommand implements CommandExecutor { continue; } - if (detectedGlobalSetting == GlobalSetting.BASE_PRICE) { + if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE) { settings.setBasePrice(material, newPrice); } else { settings.setPricePerDurabilityPoint(material, newPrice); diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigTabCompleter.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigTabCompleter.java index 0c05448..425cb88 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigTabCompleter.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigTabCompleter.java @@ -1,7 +1,7 @@ package net.knarcraft.blacksmith.command; -import net.knarcraft.blacksmith.config.GlobalSetting; -import net.knarcraft.blacksmith.config.NPCSetting; +import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSetting; +import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting; import net.knarcraft.blacksmith.config.SettingValueType; import net.knarcraft.blacksmith.util.InputParsingHelper; import org.bukkit.command.Command; @@ -39,20 +39,20 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { if (args.length == 1) { List availableCommands = new ArrayList<>(); availableCommands.add("reload"); - for (NPCSetting setting : NPCSetting.values()) { + for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) { availableCommands.add(setting.getCommandName()); } - for (GlobalSetting globalSetting : GlobalSetting.values()) { - availableCommands.add(globalSetting.getCommandName()); + for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) { + availableCommands.add(globalBlacksmithSetting.getCommandName()); } return filterMatchingContains(availableCommands, args[0]); } else if (args.length == 2) { return tabCompleteCommandValues(args[0], args[1]); } else if (args.length == 3) { //Get per-material tab completions, or return nothing if an invalid setting was specified - for (GlobalSetting globalSetting : GlobalSetting.values()) { - if (globalSetting.getCommandName().equalsIgnoreCase(args[0])) { - return getPerTypeTabCompletions(globalSetting, args); + for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) { + if (globalBlacksmithSetting.getCommandName().equalsIgnoreCase(args[0])) { + return getPerTypeTabCompletions(globalBlacksmithSetting, args); } } return new ArrayList<>(); @@ -68,14 +68,14 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { */ private List skipCompletionForSpacedMessage(String[] args) { if (args.length > 2) { - NPCSetting npcSetting = null; - for (NPCSetting setting : NPCSetting.values()) { + BlacksmithNPCSetting blacksmithNpcSetting = null; + for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) { if (setting.getCommandName().equalsIgnoreCase(args[0])) { - npcSetting = setting; + blacksmithNpcSetting = setting; break; } } - if (npcSetting != null && npcSetting.getPath().startsWith("defaults.messages")) { + if (blacksmithNpcSetting != null && blacksmithNpcSetting.getPath().startsWith("defaults.messages")) { return new ArrayList<>(); } } @@ -85,18 +85,18 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { /** * Gets tab-completions for a selected material or enchantment * - * @param globalSetting

The global setting to get tab-completions for

+ * @param globalBlacksmithSetting

The global setting to get tab-completions for

* @param args

The arguments given by the user

* @return

The tab-completions to show to the user

*/ - private List getPerTypeTabCompletions(GlobalSetting globalSetting, String[] args) { + private List getPerTypeTabCompletions(GlobalBlacksmithSetting globalBlacksmithSetting, String[] args) { //Display possible tab-completions only if a valid enchantment or material is provided - if (((globalSetting == GlobalSetting.BASE_PRICE || - globalSetting == GlobalSetting.PRICE_PER_DURABILITY_POINT) && + if (((globalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE || + globalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) && InputParsingHelper.matchMaterial(args[1]) != null) || - (globalSetting == GlobalSetting.ENCHANTMENT_COST && + (globalBlacksmithSetting == GlobalBlacksmithSetting.ENCHANTMENT_COST && InputParsingHelper.matchEnchantment(args[1]) != null)) { - return filterMatchingContains(getTabCompletions(globalSetting.getValueType()), args[2]); + return filterMatchingContains(getTabCompletions(globalBlacksmithSetting.getValueType()), args[2]); } else { return new ArrayList<>(); } @@ -113,15 +113,15 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { if (commandName.equalsIgnoreCase("reload")) { return new ArrayList<>(); } - for (GlobalSetting globalSetting : GlobalSetting.values()) { - if (globalSetting.getCommandName().equalsIgnoreCase(commandName)) { - return getCompletions(globalSetting, commandValue); + for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) { + if (globalBlacksmithSetting.getCommandName().equalsIgnoreCase(commandName)) { + return getCompletions(globalBlacksmithSetting, commandValue); } } - for (NPCSetting npcSetting : NPCSetting.values()) { - if (npcSetting.getCommandName().equalsIgnoreCase(commandName)) { + for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) { + if (blacksmithNpcSetting.getCommandName().equalsIgnoreCase(commandName)) { return filterMatchingContains(getTabCompletions( - npcSetting.getValueType()), commandValue); + blacksmithNpcSetting.getValueType()), commandValue); } } return null; @@ -130,15 +130,15 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { /** * Gets tab-completions for the given global setting and filters on the command value * - * @param globalSetting

The global setting to get tab-completions for

+ * @param globalBlacksmithSetting

The global setting to get tab-completions for

* @param commandValue

The command value used to filter between available tab-completions

* @return

The available tab-completions

*/ - private List getCompletions(GlobalSetting globalSetting, String commandValue) { - List returnValues = filterMatchingContains(getTabCompletions(globalSetting.getValueType()), commandValue); - if (globalSetting == GlobalSetting.BASE_PRICE || globalSetting == GlobalSetting.PRICE_PER_DURABILITY_POINT) { + private List getCompletions(GlobalBlacksmithSetting globalBlacksmithSetting, String commandValue) { + List returnValues = filterMatchingContains(getTabCompletions(globalBlacksmithSetting.getValueType()), commandValue); + if (globalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE || globalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) { returnValues.addAll(filterMatchingContains(getTabCompletions(SettingValueType.MATERIAL), commandValue)); - } else if (globalSetting == GlobalSetting.ENCHANTMENT_COST) { + } else if (globalBlacksmithSetting == GlobalBlacksmithSetting.ENCHANTMENT_COST) { returnValues.addAll(filterMatchingContains(getTabCompletions(SettingValueType.ENCHANTMENT), commandValue)); } return returnValues; diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java index d4fa0d4..96972a9 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java @@ -3,7 +3,7 @@ package net.knarcraft.blacksmith.command; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; import net.knarcraft.blacksmith.BlacksmithPlugin; -import net.knarcraft.blacksmith.config.NPCSetting; +import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting; import net.knarcraft.blacksmith.config.SettingValueType; import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage; import net.knarcraft.blacksmith.trait.BlacksmithTrait; @@ -41,15 +41,15 @@ public class BlackSmithEditCommand implements CommandExecutor { BlacksmithTrait blacksmithTrait = npc.getTraitNullable(BlacksmithTrait.class); - for (NPCSetting npcSetting : NPCSetting.values()) { - String commandName = npcSetting.getCommandName(); + for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) { + String commandName = blacksmithNpcSetting.getCommandName(); if (commandName.equalsIgnoreCase(args[0])) { String newValue = args.length < 2 ? null : args[1]; //This makes sure all arguments are treated as a sentence - if (npcSetting.getValueType() == SettingValueType.STRING && args.length > 2) { + if (blacksmithNpcSetting.getValueType() == SettingValueType.STRING && args.length > 2) { newValue = String.join(" ", Arrays.asList(args).subList(1, args.length)); } - return displayOrChangeNPCSetting(blacksmithTrait, npcSetting, newValue, sender); + return displayOrChangeNPCSetting(blacksmithTrait, blacksmithNpcSetting, newValue, sender); } } return false; @@ -59,23 +59,23 @@ public class BlackSmithEditCommand implements CommandExecutor { * Changes the given NPC setting, or displays the current value if a new value isn't specified * * @param blacksmithTrait

The blacksmith trait belonging to the selected NPC

- * @param npcSetting

The NPC setting to change

+ * @param blacksmithNpcSetting

The NPC setting to change

* @param newValue

The value to change the setting to

* @param sender

The command sender to notify about results

* @return

True if everything went successfully

*/ - private boolean displayOrChangeNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, String newValue, + private boolean displayOrChangeNPCSetting(BlacksmithTrait blacksmithTrait, BlacksmithNPCSetting blacksmithNpcSetting, String newValue, CommandSender sender) { if (newValue == null) { //Display the current value of the setting - displayNPCSetting(blacksmithTrait, npcSetting, sender); + displayNPCSetting(blacksmithTrait, blacksmithNpcSetting, sender); } else { //If an empty value or null, clear the value instead of changing it if (InputParsingHelper.isEmpty(newValue)) { newValue = null; } else { //Abort if an invalid value is given - boolean isValidType = TypeValidationHelper.isValid(npcSetting.getValueType(), newValue, sender); + boolean isValidType = TypeValidationHelper.isValid(blacksmithNpcSetting.getValueType(), newValue, sender); if (!isValidType) { return false; } @@ -83,9 +83,9 @@ public class BlackSmithEditCommand implements CommandExecutor { } //Change the setting - blacksmithTrait.getSettings().changeSetting(npcSetting, newValue); + blacksmithTrait.getSettings().changeSetting(blacksmithNpcSetting, newValue); BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, - getValueChangedMessage(npcSetting.getCommandName(), String.valueOf(newValue))); + getValueChangedMessage(blacksmithNpcSetting.getCommandName(), String.valueOf(newValue))); //Save the changes immediately to prevent data loss on server crash CitizensAPI.getNPCRegistry().saveToStore(); } @@ -96,24 +96,24 @@ public class BlackSmithEditCommand implements CommandExecutor { * Displays the current value of the given NPC setting * * @param blacksmithTrait

The blacksmith trait of the NPC to get the value from

- * @param npcSetting

The NPC setting to see the value of

+ * @param blacksmithNpcSetting

The NPC setting to see the value of

* @param sender

The command sender to display the value to

*/ - private void displayNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, CommandSender sender) { - String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting)); + private void displayNPCSetting(BlacksmithTrait blacksmithTrait, BlacksmithNPCSetting blacksmithNpcSetting, CommandSender sender) { + String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(blacksmithNpcSetting)); if (InputParsingHelper.isEmpty(rawValue)) { //Display the default value, if no custom value has been specified - rawValue = String.valueOf(BlacksmithPlugin.getInstance().getSettings().getRawValue(npcSetting)); + rawValue = String.valueOf(BlacksmithPlugin.getInstance().getSettings().getRawValue(blacksmithNpcSetting)); BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, - getCurrentValueMessage(npcSetting.getCommandName(), rawValue)); + getCurrentValueMessage(blacksmithNpcSetting.getCommandName(), rawValue)); } else { //Add a marker if the value has been customized String marker = BlacksmithPlugin.getTranslator().getTranslatedMessage( BlacksmithTranslatableMessage.SETTING_OVERRIDDEN_MARKER); BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, - getCurrentValueMessage(npcSetting.getCommandName(), rawValue) + marker); + getCurrentValueMessage(blacksmithNpcSetting.getCommandName(), rawValue) + marker); } - if (npcSetting.getPath().startsWith("defaults.messages")) { + if (blacksmithNpcSetting.getPath().startsWith("defaults.messages")) { sender.sendMessage(BlacksmithTranslatableMessage.getRawValueMessage( rawValue.replace(ChatColor.COLOR_CHAR, '&'))); } diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditTabCompleter.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditTabCompleter.java index 927f775..9aef110 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditTabCompleter.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditTabCompleter.java @@ -1,6 +1,6 @@ package net.knarcraft.blacksmith.command; -import net.knarcraft.blacksmith.config.NPCSetting; +import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting; import net.knarcraft.blacksmith.util.TabCompleteValuesHelper; import net.knarcraft.knarlib.util.TabCompletionHelper; import org.bukkit.command.Command; @@ -26,7 +26,7 @@ public class BlackSmithEditTabCompleter implements TabCompleter { } List npcSettings = new ArrayList<>(); - for (NPCSetting setting : NPCSetting.values()) { + for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) { npcSettings.add(setting.getCommandName()); } @@ -49,10 +49,10 @@ public class BlackSmithEditTabCompleter implements TabCompleter { * @return

Some valid options for the command's argument

*/ private List tabCompleteCommandValues(String commandName, String commandValue) { - for (NPCSetting npcSetting : NPCSetting.values()) { - if (npcSetting.getCommandName().equalsIgnoreCase(commandName)) { + for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) { + if (blacksmithNpcSetting.getCommandName().equalsIgnoreCase(commandName)) { return TabCompletionHelper.filterMatchingContains(TabCompleteValuesHelper.getTabCompletions( - npcSetting.getValueType()), commandValue); + blacksmithNpcSetting.getValueType()), commandValue); } } return null; diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java index f46d0e8..b6b70c3 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java @@ -1,214 +1,43 @@ package net.knarcraft.blacksmith.config; /** - * An enum representing all of Blacksmith's settings + * An interface describing an NPC setting */ -public enum NPCSetting { - - /** - * The setting for whether the NPC should drop an item to the ground when finished - * - *

If set to false, the item will be directly put in the player's inventory instead

- */ - DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"), - - /** - * The setting for the chance of a reforging to fail - */ - 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 - */ - EXTRA_ENCHANTMENT_CHANCE("extraEnchantmentChance", SettingValueType.PERCENTAGE, 5, - "extraEnchantmentChance"), - - /** - * The setting for the maximum amount of enchantments that can be added to an item - */ - MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"), - - /** - * The maximum amount of seconds a player may need to wait for the reforging to finish - */ - MAX_REFORGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"), - - /** - * The minimum amount of seconds a player may need to wait for the reforging to finish - */ - MIN_REFORGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"), - - /** - * The setting for number of seconds a player has to wait between each usage of the blacksmith - */ - REFORGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"), - - /** - * The setting for which items the blacksmith is able to reforge - */ - REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"), - - /** - * The setting for the title used to display which kind of blacksmith the NPC is - * - *

While this should be entirely configurable, values such as armor-smith, sword-smith and similar, which - * describe the blacksmith's specialization, and thus the range of reforge-able items, is expected.

- */ - BLACKSMITH_TITLE("blacksmithTitle", SettingValueType.STRING, "blacksmith", "blacksmithTitle"), - - /** - * The setting for the enchantments a blacksmith cannot apply to items - */ - ENCHANTMENT_BLOCKLIST("enchantmentBlocklist", SettingValueType.STRING_LIST, new String[]{"binding_curse", - "mending", "vanishing_curse"}, "enchantmentBlocklist"), - - /** - * Whether to allow this blacksmith to repair anvils - */ - REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils"), - - /*----------- - | Messages | - -----------*/ - - /** - * The message displayed when the blacksmith is busy with another player - */ - BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING, - "&cI'm busy at the moment. Come back later!", "busyPlayerMessage"), - - /** - * The message displayed when the blacksmith is already reforging something for the player - */ - BUSY_WITH_REFORGE_MESSAGE("messages.busyReforgeMessage", SettingValueType.STRING, - "&cI'm working on it. Be patient! I'll finish {time}!", "busyReforgeMessage"), - - /** - * The message displayed if the player has to wait for the cool-down to expire - */ - COOL_DOWN_UNEXPIRED_MESSAGE("messages.coolDownUnexpiredMessage", SettingValueType.STRING, - "&cYou've already had your chance! Give me a break! I'll be ready {time}!", - "coolDownUnexpiredMessage"), - - /** - * The message displayed when displaying the cost of reforging the held item to the player - */ - COST_MESSAGE("messages.costMessage", SettingValueType.STRING, - "&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!", "costMessage"), - - /** - * The message displayed if the blacksmith fails reforging an item - */ - FAIL_MESSAGE("messages.failReforgeMessage", SettingValueType.STRING, - "&cWhoops! Didn't mean to do that! Maybe next time?", "failReforgeMessage"), - - /** - * The message displayed if a player is unable to pay the blacksmith - */ - INSUFFICIENT_FUNDS_MESSAGE("messages.insufficientFundsMessage", SettingValueType.STRING, - "&cYou don't have enough money to reforge that item!", "insufficientFundsMessage"), - - /** - * The message displayed if the blacksmith encounters an item they cannot reforge - */ - INVALID_ITEM_MESSAGE("messages.invalidItemMessage", SettingValueType.STRING, - "&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!", "invalidItemMessage"), - - /** - * The message displayed if a player presents a different item after seeing the price to reforge an item - */ - ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("messages.itemChangedMessage", SettingValueType.STRING, - "&cThat's not the item you wanted to reforge before!", "itemChangedMessage"), - - /** - * The message displayed when the blacksmith starts reforging an item - */ - START_REFORGE_MESSAGE("messages.startReforgeMessage", SettingValueType.STRING, - "&eOk, let's see what I can do...", "startReforgeMessage"), - - /** - * The message displayed when the blacksmith successfully finishes reforging an item - */ - SUCCESS_MESSAGE("messages.successMessage", SettingValueType.STRING, - "There you go! All better!", "successMessage"), - - /** - * The message displayed when trying to reforge an item with full durability - */ - NOT_DAMAGED_MESSAGE("messages.notDamagedMessage", SettingValueType.STRING, - "&cThat item is not in need of repair", "notDamagedMessage"); - - private final String path; - private final String childPath; - private final Object value; - private final String commandName; - private final SettingValueType valueType; - - /** - * Instantiates a new setting - * - * @param path

The full config path for this setting

- * @param valueType

The type of value used by this setting

- * @param value

The default value of this setting

- * @param commandName

The name of the command used to change this setting

- */ - NPCSetting(String path, SettingValueType valueType, Object value, String commandName) { - this.path = "defaults." + path; - this.value = value; - this.valueType = valueType; - this.childPath = path; - this.commandName = commandName; - } +public interface NPCSetting { /** * Gets the full config path for this setting * * @return

The full config path for this setting

*/ - public String getPath() { - return path; - } + String getPath(); /** * Gets the config path without the root node * * @return

The config path without the root node

*/ - public String getChildPath() { - return childPath; - } + String getChildPath(); /** * Gets the value of this setting * * @return

The value of this setting

*/ - public Object getDefaultValue() { - return value; - } + Object getDefaultValue(); /** * The name of the command used to change this setting * * @return

The name of this setting's command

*/ - public String getCommandName() { - return commandName; - } + String getCommandName(); /** * Gets the value type for this setting * * @return

The value type for this setting

*/ - public SettingValueType getValueType() { - return this.valueType; - } - + SettingValueType getValueType(); + } diff --git a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSetting.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSetting.java new file mode 100644 index 0000000..180db39 --- /dev/null +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSetting.java @@ -0,0 +1,197 @@ +package net.knarcraft.blacksmith.config.blacksmith; + +import net.knarcraft.blacksmith.config.NPCSetting; +import net.knarcraft.blacksmith.config.SettingValueType; + +/** + * An enum representing all of Blacksmith's settings + */ +public enum BlacksmithNPCSetting implements NPCSetting { + + /** + * The setting for whether the NPC should drop an item to the ground when finished + * + *

If set to false, the item will be directly put in the player's inventory instead

+ */ + DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"), + + /** + * The setting for the chance of a reforging to fail + */ + 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 + */ + EXTRA_ENCHANTMENT_CHANCE("extraEnchantmentChance", SettingValueType.PERCENTAGE, 5, + "extraEnchantmentChance"), + + /** + * The setting for the maximum amount of enchantments that can be added to an item + */ + MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"), + + /** + * The maximum amount of seconds a player may need to wait for the reforging to finish + */ + MAX_REFORGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"), + + /** + * The minimum amount of seconds a player may need to wait for the reforging to finish + */ + MIN_REFORGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"), + + /** + * The setting for number of seconds a player has to wait between each usage of the blacksmith + */ + REFORGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"), + + /** + * The setting for which items the blacksmith is able to reforge + */ + REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"), + + /** + * The setting for the title used to display which kind of blacksmith the NPC is + * + *

While this should be entirely configurable, values such as armor-smith, sword-smith and similar, which + * describe the blacksmith's specialization, and thus the range of reforge-able items, is expected.

+ */ + BLACKSMITH_TITLE("blacksmithTitle", SettingValueType.STRING, "blacksmith", "blacksmithTitle"), + + /** + * The setting for the enchantments a blacksmith cannot apply to items + */ + ENCHANTMENT_BLOCKLIST("enchantmentBlocklist", SettingValueType.STRING_LIST, new String[]{"binding_curse", + "mending", "vanishing_curse"}, "enchantmentBlocklist"), + + /** + * Whether to allow this blacksmith to repair anvils + */ + REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils"), + + /*----------- + | Messages | + -----------*/ + + /** + * The message displayed when the blacksmith is busy with another player + */ + BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING, + "&cI'm busy at the moment. Come back later!", "busyPlayerMessage"), + + /** + * The message displayed when the blacksmith is already reforging something for the player + */ + BUSY_WITH_REFORGE_MESSAGE("messages.busyReforgeMessage", SettingValueType.STRING, + "&cI'm working on it. Be patient! I'll finish {time}!", "busyReforgeMessage"), + + /** + * The message displayed if the player has to wait for the cool-down to expire + */ + COOL_DOWN_UNEXPIRED_MESSAGE("messages.coolDownUnexpiredMessage", SettingValueType.STRING, + "&cYou've already had your chance! Give me a break! I'll be ready {time}!", + "coolDownUnexpiredMessage"), + + /** + * The message displayed when displaying the cost of reforging the held item to the player + */ + COST_MESSAGE("messages.costMessage", SettingValueType.STRING, + "&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!", "costMessage"), + + /** + * The message displayed if the blacksmith fails reforging an item + */ + FAIL_MESSAGE("messages.failReforgeMessage", SettingValueType.STRING, + "&cWhoops! Didn't mean to do that! Maybe next time?", "failReforgeMessage"), + + /** + * The message displayed if a player is unable to pay the blacksmith + */ + INSUFFICIENT_FUNDS_MESSAGE("messages.insufficientFundsMessage", SettingValueType.STRING, + "&cYou don't have enough money to reforge that item!", "insufficientFundsMessage"), + + /** + * The message displayed if the blacksmith encounters an item they cannot reforge + */ + INVALID_ITEM_MESSAGE("messages.invalidItemMessage", SettingValueType.STRING, + "&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!", "invalidItemMessage"), + + /** + * The message displayed if a player presents a different item after seeing the price to reforge an item + */ + ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("messages.itemChangedMessage", SettingValueType.STRING, + "&cThat's not the item you wanted to reforge before!", "itemChangedMessage"), + + /** + * The message displayed when the blacksmith starts reforging an item + */ + START_REFORGE_MESSAGE("messages.startReforgeMessage", SettingValueType.STRING, + "&eOk, let's see what I can do...", "startReforgeMessage"), + + /** + * The message displayed when the blacksmith successfully finishes reforging an item + */ + SUCCESS_MESSAGE("messages.successMessage", SettingValueType.STRING, + "There you go! All better!", "successMessage"), + + /** + * The message displayed when trying to reforge an item with full durability + */ + NOT_DAMAGED_MESSAGE("messages.notDamagedMessage", SettingValueType.STRING, + "&cThat item is not in need of repair", "notDamagedMessage"); + + private final String path; + private final String childPath; + private final Object value; + private final String commandName; + private final SettingValueType valueType; + + /** + * Instantiates a new setting + * + * @param path

The full config path for this setting

+ * @param valueType

The type of value used by this setting

+ * @param value

The default value of this setting

+ * @param commandName

The name of the command used to change this setting

+ */ + BlacksmithNPCSetting(String path, SettingValueType valueType, Object value, String commandName) { + this.path = "defaults." + path; + this.value = value; + this.valueType = valueType; + this.childPath = path; + this.commandName = commandName; + } + + @Override + public String getPath() { + return path; + } + + @Override + public String getChildPath() { + return childPath; + } + + @Override + public Object getDefaultValue() { + return value; + } + + @Override + public String getCommandName() { + return commandName; + } + + @Override + public SettingValueType getValueType() { + return this.valueType; + } + +} diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java similarity index 80% rename from src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java rename to src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java index b1ad4cb..bdb1c3e 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java @@ -1,7 +1,9 @@ -package net.knarcraft.blacksmith.config; +package net.knarcraft.blacksmith.config.blacksmith; import net.citizensnpcs.api.util.DataKey; import net.knarcraft.blacksmith.BlacksmithPlugin; +import net.knarcraft.blacksmith.config.SettingValueType; +import net.knarcraft.blacksmith.config.SmithPreset; import net.knarcraft.blacksmith.util.ConfigHelper; import net.knarcraft.blacksmith.util.InputParsingHelper; import net.knarcraft.blacksmith.util.ItemHelper; @@ -20,18 +22,18 @@ import java.util.logging.Level; /** * A class which keeps track of all Blacksmith settings/config values for one NPC */ -public class NPCSettings { +public class BlacksmithNPCSettings { private final List reforgeAbleItems = new ArrayList<>(); private final List enchantmentBlocklist = new ArrayList<>(); - private final Map currentValues = new HashMap<>(); - private final GlobalSettings globalSettings; + private final Map currentValues = new HashMap<>(); + private final GlobalBlacksmithSettings globalBlacksmithSettings; /** * Instantiates a new "Settings" object */ - public NPCSettings(GlobalSettings globalSettings) { - this.globalSettings = globalSettings; + public BlacksmithNPCSettings(GlobalBlacksmithSettings globalBlacksmithSettings) { + this.globalBlacksmithSettings = globalBlacksmithSettings; } /** @@ -40,7 +42,7 @@ public class NPCSettings { * @param key

The data key to load variables from

*/ public void loadVariables(DataKey key) { - for (NPCSetting setting : NPCSetting.values()) { + for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) { if (key.keyExists(setting.getChildPath())) { currentValues.put(setting, key.getRaw(setting.getChildPath())); } @@ -56,7 +58,7 @@ public class NPCSettings { * @param key

The data key to save variables to

*/ public void saveVariables(DataKey key) { - for (NPCSetting setting : NPCSetting.values()) { + for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) { key.setRaw(setting.getChildPath(), currentValues.get(setting)); } } @@ -67,7 +69,7 @@ public class NPCSettings { * @param setting

The setting to change

* @param newValue

The new value of the setting

*/ - public void changeSetting(NPCSetting setting, Object newValue) { + public void changeSetting(BlacksmithNPCSetting setting, Object newValue) { if (setting.getValueType() == SettingValueType.STRING_LIST || setting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { //Workaround to make sure it's treated as the correct type @@ -75,10 +77,10 @@ public class NPCSettings { } else { currentValues.put(setting, newValue); } - if (setting == NPCSetting.REFORGE_ABLE_ITEMS) { + if (setting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) { updateReforgeAbleItems(); } - if (setting == NPCSetting.ENCHANTMENT_BLOCKLIST) { + if (setting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) { updateEnchantmentBlocklist(); } } @@ -89,7 +91,7 @@ public class NPCSettings { * @param setting

The setting to get the value of

* @return

The current value of the setting

*/ - public Object getRawValue(NPCSetting setting) { + public Object getRawValue(BlacksmithNPCSetting setting) { return currentValues.get(setting); } @@ -99,7 +101,7 @@ public class NPCSettings { * @return

The busy with player message

*/ public String getBusyWithPlayerMessage() { - return asString(NPCSetting.BUSY_WITH_PLAYER_MESSAGE); + return asString(BlacksmithNPCSetting.BUSY_WITH_PLAYER_MESSAGE); } /** @@ -108,7 +110,7 @@ public class NPCSettings { * @return

The busy reforging message

*/ public String getBusyReforgingMessage() { - return asString(NPCSetting.BUSY_WITH_REFORGE_MESSAGE); + return asString(BlacksmithNPCSetting.BUSY_WITH_REFORGE_MESSAGE); } /** @@ -117,7 +119,7 @@ public class NPCSettings { * @return

The message to use for displaying item cost

*/ public String getCostMessage() { - return asString(NPCSetting.COST_MESSAGE); + return asString(BlacksmithNPCSetting.COST_MESSAGE); } /** @@ -126,7 +128,7 @@ public class NPCSettings { * @return

The invalid item message

*/ public String getInvalidItemMessage() { - return asString(NPCSetting.INVALID_ITEM_MESSAGE); + return asString(BlacksmithNPCSetting.INVALID_ITEM_MESSAGE); } /** @@ -135,7 +137,7 @@ public class NPCSettings { * @return

The not damaged message

*/ public String getNotDamagedMessage() { - return asString(NPCSetting.NOT_DAMAGED_MESSAGE); + return asString(BlacksmithNPCSetting.NOT_DAMAGED_MESSAGE); } /** @@ -144,7 +146,7 @@ public class NPCSettings { * @return

The start reforge message

*/ public String getStartReforgeMessage() { - return asString(NPCSetting.START_REFORGE_MESSAGE); + return asString(BlacksmithNPCSetting.START_REFORGE_MESSAGE); } /** @@ -153,7 +155,7 @@ public class NPCSettings { * @return

The reforge success message

*/ public String getSuccessMessage() { - return asString(NPCSetting.SUCCESS_MESSAGE); + return asString(BlacksmithNPCSetting.SUCCESS_MESSAGE); } /** @@ -162,7 +164,7 @@ public class NPCSettings { * @return

The reforge fail message

*/ public String getFailMessage() { - return asString(NPCSetting.FAIL_MESSAGE); + return asString(BlacksmithNPCSetting.FAIL_MESSAGE); } /** @@ -171,7 +173,7 @@ public class NPCSettings { * @return

The insufficient funds message

*/ public String getInsufficientFundsMessage() { - return asString(NPCSetting.INSUFFICIENT_FUNDS_MESSAGE); + return asString(BlacksmithNPCSetting.INSUFFICIENT_FUNDS_MESSAGE); } /** @@ -180,7 +182,7 @@ public class NPCSettings { * @return

The cool down unexpired message

*/ public String getCoolDownUnexpiredMessage() { - return asString(NPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE); + return asString(BlacksmithNPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE); } /** @@ -189,7 +191,7 @@ public class NPCSettings { * @return

The item changed message

*/ public String getItemChangedMessage() { - return asString(NPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE); + return asString(BlacksmithNPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE); } /** @@ -200,9 +202,9 @@ public class NPCSettings { * @return

All items reforge-able by this NPC

*/ public List getReforgeAbleItems() { - Object currentValue = currentValues.get(NPCSetting.REFORGE_ABLE_ITEMS); + Object currentValue = currentValues.get(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS); if (currentValue == null || String.valueOf(currentValue).isEmpty()) { - return globalSettings.getReforgeAbleItems(); + return globalBlacksmithSettings.getReforgeAbleItems(); } else { return new ArrayList<>(this.reforgeAbleItems); } @@ -214,9 +216,9 @@ public class NPCSettings { * @return

The list of blocked enchantments

*/ public List getEnchantmentBlocklist() { - Object currentValue = currentValues.get(NPCSetting.ENCHANTMENT_BLOCKLIST); + Object currentValue = currentValues.get(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST); if (currentValue == null || String.valueOf(currentValue).isEmpty()) { - return globalSettings.getEnchantmentBlocklist(); + return globalBlacksmithSettings.getEnchantmentBlocklist(); } else { return new ArrayList<>(this.enchantmentBlocklist); } @@ -228,7 +230,7 @@ public class NPCSettings { * @return

The minimum reforge delay

*/ public int getMinReforgeDelay() { - return asInt(NPCSetting.MIN_REFORGE_DELAY); + return asInt(BlacksmithNPCSetting.MIN_REFORGE_DELAY); } /** @@ -237,7 +239,7 @@ public class NPCSettings { * @return

The maximum reforge delay

*/ public int getMaxReforgeDelay() { - return asInt(NPCSetting.MAX_REFORGE_DELAY); + return asInt(BlacksmithNPCSetting.MAX_REFORGE_DELAY); } /** @@ -246,7 +248,7 @@ public class NPCSettings { * @return

The reforge cool-down

*/ public int getReforgeCoolDown() { - return asInt(NPCSetting.REFORGE_COOL_DOWN); + return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN); } /** @@ -255,7 +257,7 @@ public class NPCSettings { * @return

The fail chance

*/ public int getFailChance() { - return asInt(NPCSetting.FAIL_CHANCE); + return asInt(BlacksmithNPCSetting.FAIL_CHANCE); } /** @@ -264,7 +266,7 @@ public class NPCSettings { * @return

Whether enchantments should be removed

*/ public boolean getFailRemovesEnchantments() { - return asBoolean(NPCSetting.FAIL_REMOVE_ENCHANTMENTS); + return asBoolean(BlacksmithNPCSetting.FAIL_REMOVE_ENCHANTMENTS); } /** @@ -273,7 +275,7 @@ public class NPCSettings { * @return

The extra enchantment chance

*/ public int getExtraEnchantmentChance() { - return asInt(NPCSetting.EXTRA_ENCHANTMENT_CHANCE); + return asInt(BlacksmithNPCSetting.EXTRA_ENCHANTMENT_CHANCE); } /** @@ -282,7 +284,7 @@ public class NPCSettings { * @return

The maximum enchantments

*/ public int getMaxEnchantments() { - return asInt(NPCSetting.MAX_ENCHANTMENTS); + return asInt(BlacksmithNPCSetting.MAX_ENCHANTMENTS); } /** @@ -291,7 +293,7 @@ public class NPCSettings { * @return

Whether to drop reforged items on the ground

*/ public boolean getDropItem() { - return asBoolean(NPCSetting.DROP_ITEM); + return asBoolean(BlacksmithNPCSetting.DROP_ITEM); } /** @@ -300,7 +302,7 @@ public class NPCSettings { * @return

The title of the blacksmith

*/ public String getBlacksmithTitle() { - return asString(NPCSetting.BLACKSMITH_TITLE); + return asString(BlacksmithNPCSetting.BLACKSMITH_TITLE); } /** @@ -309,7 +311,7 @@ public class NPCSettings { * @return

Whether to disable the reforge-cool-down

*/ public boolean getDisableCoolDown() { - return asInt(NPCSetting.REFORGE_COOL_DOWN) <= 0; + return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN) <= 0; } /** @@ -318,7 +320,7 @@ public class NPCSettings { * @return

Whether to disable the reforge delay

*/ public boolean getDisableDelay() { - return asInt(NPCSetting.MAX_REFORGE_DELAY) <= 0; + return asInt(BlacksmithNPCSetting.MAX_REFORGE_DELAY) <= 0; } /** @@ -327,7 +329,7 @@ public class NPCSettings { * @return

True if this blacksmith is able to repair anvils

*/ public boolean getRepairAnvils() { - return asBoolean(NPCSetting.REPAIR_ANVILS); + return asBoolean(BlacksmithNPCSetting.REPAIR_ANVILS); } /** @@ -338,7 +340,7 @@ public class NPCSettings { * @param setting

The setting to get the value of

* @return

The value of the given setting as an integer

*/ - private int asInt(NPCSetting setting) { + private int asInt(BlacksmithNPCSetting setting) { return ConfigHelper.asInt(getValue(setting)); } @@ -348,7 +350,7 @@ public class NPCSettings { * @param setting

The setting to get the value of

* @return

The value of the given setting as a string

*/ - private String asString(NPCSetting setting) { + private String asString(BlacksmithNPCSetting setting) { return getValue(setting).toString(); } @@ -358,7 +360,7 @@ public class NPCSettings { * @param setting

The setting to get the value of

* @return

The value of the given setting as a boolean

*/ - private boolean asBoolean(NPCSetting setting) { + private boolean asBoolean(BlacksmithNPCSetting setting) { return ConfigHelper.asBoolean(getValue(setting)); } @@ -368,11 +370,11 @@ public class NPCSettings { * @param setting

The setting to get the value of

* @return

The current value

*/ - private Object getValue(NPCSetting setting) { + private Object getValue(BlacksmithNPCSetting setting) { Object value = currentValues.get(setting); //If not set, use the default value from the config.yml file if (value == null) { - Map defaultNPCSettings = globalSettings.getDefaultNPCSettings(); + Map defaultNPCSettings = globalBlacksmithSettings.getDefaultNPCSettings(); if (defaultNPCSettings.containsKey(setting)) { value = defaultNPCSettings.get(setting); } @@ -412,7 +414,7 @@ public class NPCSettings { private void updateEnchantmentBlocklist() { this.enchantmentBlocklist.clear(); this.enchantmentBlocklist.addAll(getEnchantmentBlocklist(ConfigHelper.asStringList(getValue( - NPCSetting.ENCHANTMENT_BLOCKLIST)))); + BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST)))); } /** @@ -446,7 +448,7 @@ public class NPCSettings { private void updateReforgeAbleItems() { this.reforgeAbleItems.clear(); this.reforgeAbleItems.addAll(getReforgeAbleItems(ConfigHelper.asStringList(getValue( - NPCSetting.REFORGE_ABLE_ITEMS)))); + BlacksmithNPCSetting.REFORGE_ABLE_ITEMS)))); } /** diff --git a/src/main/java/net/knarcraft/blacksmith/config/GlobalSetting.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSetting.java similarity index 93% rename from src/main/java/net/knarcraft/blacksmith/config/GlobalSetting.java rename to src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSetting.java index 4613600..b5e64ac 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/GlobalSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSetting.java @@ -1,8 +1,10 @@ -package net.knarcraft.blacksmith.config; +package net.knarcraft.blacksmith.config.blacksmith; + +import net.knarcraft.blacksmith.config.SettingValueType; import java.util.Arrays; -public enum GlobalSetting { +public enum GlobalBlacksmithSetting { /** * The base price for repairing, regardless of durability @@ -65,7 +67,7 @@ public enum GlobalSetting { * @param value

The default value of this setting

* @param commandName

The name of the command used to change this setting

*/ - GlobalSetting(String path, SettingValueType valueType, Object value, String commandName) { + GlobalBlacksmithSetting(String path, SettingValueType valueType, Object value, String commandName) { this.path = path; this.value = value; this.commandName = commandName; diff --git a/src/main/java/net/knarcraft/blacksmith/config/GlobalSettings.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSettings.java similarity index 79% rename from src/main/java/net/knarcraft/blacksmith/config/GlobalSettings.java rename to src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSettings.java index b0b4223..b5b458d 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/GlobalSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSettings.java @@ -1,8 +1,9 @@ -package net.knarcraft.blacksmith.config; +package net.knarcraft.blacksmith.config.blacksmith; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.YamlStorage; import net.knarcraft.blacksmith.BlacksmithPlugin; +import net.knarcraft.blacksmith.config.SettingValueType; import net.knarcraft.blacksmith.util.ConfigHelper; import net.knarcraft.blacksmith.util.InputParsingHelper; import net.knarcraft.blacksmith.util.ItemHelper; @@ -19,15 +20,15 @@ import java.util.logging.Level; /** * A class which keeps track of all default NPC settings and all global settings */ -public class GlobalSettings { +public class GlobalBlacksmithSettings { private final Map materialBasePrices = new HashMap<>(); private final Map materialPricePerDurabilityPoints = new HashMap<>(); private final Map enchantmentCosts = new HashMap<>(); - private final Map defaultNPCSettings = new HashMap<>(); + private final Map defaultNPCSettings = new HashMap<>(); private final List defaultReforgeAbleMaterials = new ArrayList<>(); private final List defaultEnchantmentBlocklist = new ArrayList<>(); - private final Map globalSettings = new HashMap<>(); + private final Map globalSettings = new HashMap<>(); private final YamlStorage defaultConfig; @@ -36,7 +37,7 @@ public class GlobalSettings { * * @param plugin

A reference to the blacksmith plugin

*/ - public GlobalSettings(BlacksmithPlugin plugin) { + public GlobalBlacksmithSettings(BlacksmithPlugin plugin) { defaultConfig = new YamlStorage(new File(plugin.getDataFolder() + File.separator + "config.yml"), "Blacksmith Configuration\nWarning: The values under defaults are the values set for a " + "blacksmith upon creation. To change any values for existing NPCs, edit the citizens NPC file."); @@ -70,32 +71,32 @@ public class GlobalSettings { /** * Changes the value of the given setting * - * @param globalSetting

The global setting to change

+ * @param globalBlacksmithSetting

The global setting to change

* @param newValue

The new value of the setting

*/ - public void changeValue(GlobalSetting globalSetting, Object newValue) { - globalSettings.put(globalSetting, newValue); + public void changeValue(GlobalBlacksmithSetting globalBlacksmithSetting, Object newValue) { + globalSettings.put(globalBlacksmithSetting, newValue); save(); } /** * Changes the value of the given setting * - * @param npcSetting

The default NPC setting to change

+ * @param blacksmithNpcSetting

The default NPC setting to change

* @param newValue

The new value for the setting

*/ - public void changeValue(NPCSetting npcSetting, Object newValue) { - if (npcSetting.getValueType() == SettingValueType.STRING_LIST || - npcSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { + public void changeValue(BlacksmithNPCSetting blacksmithNpcSetting, Object newValue) { + if (blacksmithNpcSetting.getValueType() == SettingValueType.STRING_LIST || + blacksmithNpcSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { //Workaround to make sure it's treated as the correct type - defaultNPCSettings.put(npcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue)); + defaultNPCSettings.put(blacksmithNpcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue)); } else { - defaultNPCSettings.put(npcSetting, newValue); + defaultNPCSettings.put(blacksmithNpcSetting, newValue); } save(); - if (npcSetting == NPCSetting.REFORGE_ABLE_ITEMS) { + if (blacksmithNpcSetting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) { loadReforgeAbleItems(); - } else if (npcSetting == NPCSetting.ENCHANTMENT_BLOCKLIST) { + } else if (blacksmithNpcSetting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) { loadEnchantmentBlocklist(); } } @@ -103,21 +104,21 @@ public class GlobalSettings { /** * Gets the current raw value of the given global setting * - * @param globalSetting

The setting to get

+ * @param globalBlacksmithSetting

The setting to get

* @return

The current raw setting value

*/ - public Object getRawValue(GlobalSetting globalSetting) { - return globalSettings.get(globalSetting); + public Object getRawValue(GlobalBlacksmithSetting globalBlacksmithSetting) { + return globalSettings.get(globalBlacksmithSetting); } /** * Gets the current raw value of the given default NPC setting * - * @param npcSetting

The setting to get

+ * @param blacksmithNpcSetting

The setting to get

* @return

The current raw setting value

*/ - public Object getRawValue(NPCSetting npcSetting) { - return defaultNPCSettings.get(npcSetting); + public Object getRawValue(BlacksmithNPCSetting blacksmithNpcSetting) { + return defaultNPCSettings.get(blacksmithNpcSetting); } /** @@ -131,7 +132,7 @@ public class GlobalSettings { if (newEnchantmentCost < 0) { throw new IllegalArgumentException("Enchantment cost cannot be negative!"); } - globalSettings.put(GlobalSetting.ENCHANTMENT_COST, newEnchantmentCost); + globalSettings.put(GlobalBlacksmithSetting.ENCHANTMENT_COST, newEnchantmentCost); } else { if (newEnchantmentCost < 0) { enchantmentCosts.put(enchantment, null); @@ -153,7 +154,7 @@ public class GlobalSettings { if (newPrice < 0) { throw new IllegalArgumentException("Price per durability point cannot be negative!"); } - globalSettings.put(GlobalSetting.PRICE_PER_DURABILITY_POINT, newPrice); + globalSettings.put(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT, newPrice); } else { //Use a negative price to unset the per-item value if (newPrice < 0) { @@ -176,7 +177,7 @@ public class GlobalSettings { if (newBasePrice < 0) { throw new IllegalArgumentException("Base price cannot be negative!"); } - globalSettings.put(GlobalSetting.BASE_PRICE, newBasePrice); + globalSettings.put(GlobalBlacksmithSetting.BASE_PRICE, newBasePrice); } else { //Use a negative price to unset the per-item value if (newBasePrice < 0) { @@ -193,7 +194,7 @@ public class GlobalSettings { * * @return

The current value of the default NPC settings

*/ - public Map getDefaultNPCSettings() { + public Map getDefaultNPCSettings() { return new HashMap<>(this.defaultNPCSettings); } @@ -206,7 +207,7 @@ public class GlobalSettings { * @return

Whether to use natural cost

*/ public boolean getUseNaturalCost() { - return asBoolean(GlobalSetting.NATURAL_COST); + return asBoolean(GlobalBlacksmithSetting.NATURAL_COST); } /** @@ -215,7 +216,7 @@ public class GlobalSettings { * @return

Whether to show exact time

*/ public boolean getShowExactTime() { - return asBoolean(GlobalSetting.SHOW_EXACT_TIME); + return asBoolean(GlobalBlacksmithSetting.SHOW_EXACT_TIME); } /** @@ -228,7 +229,7 @@ public class GlobalSettings { if (materialBasePrices.containsKey(material) && materialBasePrices.get(material) != null) { return materialBasePrices.get(material); } else { - return asDouble(GlobalSetting.BASE_PRICE); + return asDouble(GlobalBlacksmithSetting.BASE_PRICE); } } @@ -243,7 +244,7 @@ public class GlobalSettings { materialPricePerDurabilityPoints.get(material) != null) { return materialPricePerDurabilityPoints.get(material); } else { - return asDouble(GlobalSetting.PRICE_PER_DURABILITY_POINT); + return asDouble(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT); } } @@ -257,7 +258,7 @@ public class GlobalSettings { if (enchantmentCosts.containsKey(enchantment) && enchantmentCosts.get(enchantment) != null) { return enchantmentCosts.get(enchantment); } else { - return asDouble(GlobalSetting.ENCHANTMENT_COST); + return asDouble(GlobalBlacksmithSetting.ENCHANTMENT_COST); } } @@ -287,9 +288,9 @@ public class GlobalSettings { */ public double getAnvilCost(Material material) { if (material == Material.CHIPPED_ANVIL) { - return asDouble(GlobalSetting.ANVIL_CHIPPED_COST); + return asDouble(GlobalBlacksmithSetting.ANVIL_CHIPPED_COST); } else if (material == Material.DAMAGED_ANVIL) { - return asDouble(GlobalSetting.ANVIL_DAMAGED_COST); + return asDouble(GlobalBlacksmithSetting.ANVIL_DAMAGED_COST); } else { throw new IllegalArgumentException("An unexpected item was encountered!"); } @@ -303,7 +304,7 @@ public class GlobalSettings { * @param setting

The setting to get the value of

* @return

The value of the given setting as a boolean

*/ - public boolean asBoolean(GlobalSetting setting) { + public boolean asBoolean(GlobalBlacksmithSetting setting) { return ConfigHelper.asBoolean(getValue(setting)); } @@ -315,7 +316,7 @@ public class GlobalSettings { * @param setting

The setting to get the value of

* @return

The value of the given setting as a double

*/ - public double asDouble(GlobalSetting setting) { + public double asDouble(GlobalBlacksmithSetting setting) { return ConfigHelper.asDouble(getValue(setting)); } @@ -325,7 +326,7 @@ public class GlobalSettings { * @param setting

The setting to get the value of

* @return

The current value

*/ - private Object getValue(GlobalSetting setting) { + private Object getValue(GlobalBlacksmithSetting setting) { Object value = globalSettings.get(setting); //If not set in config.yml, use the default value from the enum if (value == null) { @@ -340,13 +341,13 @@ public class GlobalSettings { * @param root

The root node of all global settings

*/ private void loadGlobalSettings(DataKey root) { - for (GlobalSetting globalSetting : GlobalSetting.values()) { - if (!root.keyExists(globalSetting.getPath())) { + for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) { + if (!root.keyExists(globalBlacksmithSetting.getPath())) { //If the setting does not exist in the config file, add it - root.setRaw(globalSetting.getPath(), globalSetting.getDefaultValue()); + root.setRaw(globalBlacksmithSetting.getPath(), globalBlacksmithSetting.getDefaultValue()); } else { //Set the setting to the value found in the path - globalSettings.put(globalSetting, root.getRaw(globalSetting.getPath())); + globalSettings.put(globalBlacksmithSetting, root.getRaw(globalBlacksmithSetting.getPath())); } } @@ -357,7 +358,7 @@ public class GlobalSettings { loadPricesPerDurabilityPoint(root); //Load all enchantment prices - DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent()); + DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent()); Map relevantKeys = getRelevantKeys(enchantmentCostNode); for (String key : relevantKeys.keySet()) { String enchantmentName = relevantKeys.get(key); @@ -372,7 +373,7 @@ public class GlobalSettings { * @param root

The configuration root node to search from

*/ private void loadPricesPerDurabilityPoint(DataKey root) { - DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent()); + DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent()); Map relevantKeys = getRelevantKeys(basePerDurabilityPriceNode); for (String key : relevantKeys.keySet()) { @@ -394,7 +395,7 @@ public class GlobalSettings { * @param root

The configuration root node to search from

*/ private void loadBasePrices(DataKey root) { - DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent()); + DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent()); Map relevantKeys = getRelevantKeys(basePriceNode); for (String key : relevantKeys.keySet()) { @@ -479,7 +480,7 @@ public class GlobalSettings { * @param root

The root node of all default NPC settings

*/ private void loadDefaultNPCSettings(DataKey root) { - for (NPCSetting setting : NPCSetting.values()) { + for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) { if (!root.keyExists(setting.getPath())) { //If the setting does not exist in the config file, add it root.setRaw(setting.getPath(), setting.getDefaultValue()); @@ -497,8 +498,8 @@ public class GlobalSettings { */ private void loadReforgeAbleItems() { defaultReforgeAbleMaterials.clear(); - defaultReforgeAbleMaterials.addAll(NPCSettings.getReforgeAbleItems(ConfigHelper.asStringList( - defaultNPCSettings.get(NPCSetting.REFORGE_ABLE_ITEMS)))); + defaultReforgeAbleMaterials.addAll(BlacksmithNPCSettings.getReforgeAbleItems(ConfigHelper.asStringList( + defaultNPCSettings.get(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS)))); } /** @@ -506,8 +507,8 @@ public class GlobalSettings { */ private void loadEnchantmentBlocklist() { defaultEnchantmentBlocklist.clear(); - defaultEnchantmentBlocklist.addAll(NPCSettings.getEnchantmentBlocklist(ConfigHelper.asStringList( - defaultNPCSettings.get(NPCSetting.ENCHANTMENT_BLOCKLIST)))); + defaultEnchantmentBlocklist.addAll(BlacksmithNPCSettings.getEnchantmentBlocklist(ConfigHelper.asStringList( + defaultNPCSettings.get(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST)))); } /** @@ -516,29 +517,29 @@ public class GlobalSettings { private void save() { DataKey root = defaultConfig.getKey(""); //Save all default NPC settings - for (NPCSetting setting : NPCSetting.values()) { + for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) { root.setRaw(setting.getPath(), defaultNPCSettings.get(setting)); } //Save all normal global settings - for (GlobalSetting globalSetting : GlobalSetting.values()) { - root.setRaw(globalSetting.getPath(), globalSettings.get(globalSetting)); + for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) { + root.setRaw(globalBlacksmithSetting.getPath(), globalSettings.get(globalBlacksmithSetting)); } //Save all base prices - DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent()); + DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent()); for (Material material : materialBasePrices.keySet()) { basePriceNode.setRaw(unNormalizeName(material.name()), materialBasePrices.get(material)); } //Save all per-durability-point prices - DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent()); + DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent()); for (Material material : materialPricePerDurabilityPoints.keySet()) { basePerDurabilityPriceNode.setRaw(unNormalizeName(material.name()), materialPricePerDurabilityPoints.get(material)); } //Load all enchantment prices - DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent()); + DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent()); for (Enchantment enchantment : enchantmentCosts.keySet()) { enchantmentCostNode.setRaw(unNormalizeName(enchantment.getKey().getKey()), enchantmentCosts.get(enchantment)); } diff --git a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSetting.java b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSetting.java new file mode 100644 index 0000000..b88f270 --- /dev/null +++ b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSetting.java @@ -0,0 +1,83 @@ +package net.knarcraft.blacksmith.config.scrapper; + +import net.knarcraft.blacksmith.config.NPCSetting; +import net.knarcraft.blacksmith.config.SettingValueType; + +public enum ScrapperNPCSetting implements NPCSetting { + + /** + * The setting for whether the NPC should drop an item to the ground when finished + * + *

If set to false, the item will be directly put in the player's inventory instead

+ */ + DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"), + + /** + * The chance of a scrapper returning no salvage, regardless of item condition + */ + FAIL_SALVAGE_CHANCE("failSalvageChance", SettingValueType.POSITIVE_DOUBLE, 0, "failSalvageChance"), + + /** + * The setting for which items a scrapper is able to salvage + */ + SALVAGE_ABLE_ITEMS("salvageAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "salvageAbleItems"), + + /*----------- + | Messages | + -----------*/ + + /** + * The message displayed when the scrapper is busy with another player + */ + BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING, + "&cI'm busy at the moment. Come back later!", "busyPlayerMessage"), + ; + + private final String path; + private final String childPath; + private final Object value; + private final String commandName; + private final SettingValueType valueType; + + /** + * Instantiates a new setting + * + * @param path

The full config path for this setting

+ * @param valueType

The type of value used by this setting

+ * @param value

The default value of this setting

+ * @param commandName

The name of the command used to change this setting

+ */ + ScrapperNPCSetting(String path, SettingValueType valueType, Object value, String commandName) { + this.path = "defaults." + path; + this.value = value; + this.valueType = valueType; + this.childPath = path; + this.commandName = commandName; + } + + @Override + public String getPath() { + return path; + } + + @Override + public String getChildPath() { + return childPath; + } + + @Override + public Object getDefaultValue() { + return value; + } + + @Override + public String getCommandName() { + return commandName; + } + + @Override + public SettingValueType getValueType() { + return this.valueType; + } + +} diff --git a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSettings.java new file mode 100644 index 0000000..268aabc --- /dev/null +++ b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSettings.java @@ -0,0 +1,4 @@ +package net.knarcraft.blacksmith.config.scrapper; + +public class ScrapperNPCSettings { +} diff --git a/src/main/java/net/knarcraft/blacksmith/manager/EconomyManager.java b/src/main/java/net/knarcraft/blacksmith/manager/EconomyManager.java index 11e5c59..7f46106 100644 --- a/src/main/java/net/knarcraft/blacksmith/manager/EconomyManager.java +++ b/src/main/java/net/knarcraft/blacksmith/manager/EconomyManager.java @@ -1,7 +1,7 @@ package net.knarcraft.blacksmith.manager; import net.knarcraft.blacksmith.BlacksmithPlugin; -import net.knarcraft.blacksmith.config.GlobalSettings; +import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings; import net.knarcraft.blacksmith.util.ItemHelper; import net.milkbowl.vault.economy.Economy; import org.bukkit.Material; @@ -89,15 +89,15 @@ public class EconomyManager { * @return

The cost of the repair

*/ private static double getCost(ItemStack item) { - GlobalSettings globalSettings = BlacksmithPlugin.getInstance().getSettings(); + GlobalBlacksmithSettings globalBlacksmithSettings = BlacksmithPlugin.getInstance().getSettings(); Material material = item.getType(); //Calculate the base price - double price = globalSettings.getBasePrice(material); + double price = globalBlacksmithSettings.getBasePrice(material); // Adjust price based on durability - double pricePerDurabilityPoint = globalSettings.getPricePerDurabilityPoint(material); - if (globalSettings.getUseNaturalCost()) { + double pricePerDurabilityPoint = globalBlacksmithSettings.getPricePerDurabilityPoint(material); + if (globalBlacksmithSettings.getUseNaturalCost()) { //Cost increases with damage price += ((double) ItemHelper.getDamage(item)) * pricePerDurabilityPoint; } else { @@ -110,7 +110,7 @@ public class EconomyManager { //Override the cost for anvils if (ItemHelper.isAnvil(material, true)) { - price = globalSettings.getAnvilCost(material); + price = globalBlacksmithSettings.getAnvilCost(material); } return price; } @@ -122,7 +122,7 @@ public class EconomyManager { * @return

The resulting enchantment cost

*/ private static double getEnchantmentCost(ItemStack item) { - GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings(); + GlobalBlacksmithSettings settings = BlacksmithPlugin.getInstance().getSettings(); double price = 0; for (Enchantment enchantment : item.getEnchantments().keySet()) { price += settings.getEnchantmentCost(enchantment) * item.getEnchantmentLevel(enchantment); diff --git a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java index 623fa79..70cee1a 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java @@ -4,7 +4,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.util.DataKey; import net.knarcraft.blacksmith.BlacksmithPlugin; -import net.knarcraft.blacksmith.config.NPCSettings; +import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings; import net.knarcraft.blacksmith.formatting.TimeFormatter; import net.knarcraft.blacksmith.manager.EconomyManager; import net.knarcraft.blacksmith.util.ItemHelper; @@ -31,7 +31,7 @@ public class BlacksmithTrait extends Trait { private final Map coolDowns = new HashMap<>(); private ReforgeSession session; - private final NPCSettings config; + private final BlacksmithNPCSettings config; private long _sessionStart = System.currentTimeMillis(); /** @@ -41,7 +41,7 @@ public class BlacksmithTrait extends Trait { super("blacksmith"); //This should crash if the blacksmith plugin hasn't been properly registered Bukkit.getServer().getPluginManager().getPlugin("Blacksmith"); - this.config = new NPCSettings(BlacksmithPlugin.getInstance().getSettings()); + this.config = new BlacksmithNPCSettings(BlacksmithPlugin.getInstance().getSettings()); } /** @@ -49,7 +49,7 @@ public class BlacksmithTrait extends Trait { * * @return

The current settings for this NPC

*/ - public NPCSettings getSettings() { + public BlacksmithNPCSettings getSettings() { return config; } diff --git a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java index 95188b7..a30757b 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java @@ -2,7 +2,7 @@ package net.knarcraft.blacksmith.trait; import net.citizensnpcs.api.npc.NPC; import net.knarcraft.blacksmith.BlacksmithPlugin; -import net.knarcraft.blacksmith.config.NPCSettings; +import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings; import net.knarcraft.blacksmith.manager.EconomyManager; import net.knarcraft.blacksmith.util.InputParsingHelper; import net.knarcraft.blacksmith.util.ItemHelper; @@ -33,7 +33,7 @@ public class ReforgeSession implements Runnable { private final ItemStack itemToReforge; private int taskId; private long finishTime = 0; - private final NPCSettings config; + private final BlacksmithNPCSettings config; private static final String[] enchantments = new String[Enchantment.values().length]; private static final Random random = new Random(); @@ -45,7 +45,7 @@ public class ReforgeSession implements Runnable { * @param npc

The Blacksmith NPC involved in the session

* @param config

The config to use for the session

*/ - ReforgeSession(BlacksmithTrait blacksmithTrait, Player player, NPC npc, NPCSettings config) { + ReforgeSession(BlacksmithTrait blacksmithTrait, Player player, NPC npc, BlacksmithNPCSettings config) { this.blacksmithTrait = blacksmithTrait; this.player = player; this.npc = npc; diff --git a/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java new file mode 100644 index 0000000..7ec5b8b --- /dev/null +++ b/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java @@ -0,0 +1,17 @@ +package net.knarcraft.blacksmith.trait; + +import net.citizensnpcs.api.trait.Trait; + +/** + * The class representing a scrapper NPC trait + */ +public class ScrapperTrait extends Trait { + + protected ScrapperTrait(String name) { + super(name); + } + + //TODO: A scrapper will take items and turn them into the base ingredients + //TODO: If an item is enchanted, give an appropriate amount of exp + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0abfc99..bb24871 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,120 +3,164 @@ # The language used for messages. Only "en" is supported language: en -# The settings which apply to all Blacksmith NPCs. These can also be changed using the /blacksmithconfig command -global: - # The minimum price of each cost - basePrice: - # You can add, for example "diamond-sword: 15.3" to change the base cost for a specific item - default: 10.0 - - # The additional cost for each durability point missing (natural cost) or present (not natural cost) - pricePerDurabilityPoint: - # You can add, for example "diamond-sword: 0.09" to change the base cost for a specific item - default: 0.005 - - # The additional cost for each enchantment level present on an item - enchantmentCost: - # You can add, for example "arrow-infinite: 0.09" to change the enchantment cost for a specific enchantment - default: 5 - - # Natural cost makes re-forging more expensive the more damaged the item is. Disabling this will enable the legacy - # blacksmith behavior instead - useNaturalCost: true - - # Exact time displays the exact number of seconds and minutes remaining as part of the reforging cool-down and - # reforging delay messages, instead of just vaguely hinting at the remaining time. - showExactTime: false +# Settings for the blacksmith trait +blacksmith: + # The settings which apply to all Blacksmith NPCs. These can also be changed using the /blacksmithconfig command + global: + # The minimum price of each cost + basePrice: + # You can add, for example "diamond-sword: 15.3" to change the base cost for a specific item + default: 10.0 - # The cost of fully repairing a chipped anvil - chippedAnvilReforgingCost: 10.0 + # The additional cost for each durability point missing (natural cost) or present (not natural cost) + pricePerDurabilityPoint: + # You can add, for example "diamond-sword: 0.09" to change the base cost for a specific item + default: 0.005 - # The cost of fully repairing a damaged anvil - damagedAnvilReforgingCost: 20.0 - -# 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 -defaults: - # Whether the item will drop a reforged item on the ground, instead of putting it into the user's inventory - dropItem: true - - # The items a blacksmith is able to reforge. Setting this only allows NPCs to repair the listed items. This should be - # set for each individual NPC, and should not be set here, unless you want to restrict NPCs which have not been set - # up yet. - reforgeAbleItems: [ ] - - # The enchantments a blacksmith is denied from applying to an item. Disable anything you find too op or annoying. - enchantmentBlocklist: [ "binding_curse", "mending", "vanishing_curse" ] - - # The chance to fail reforging an item, which only repairs the item a tiny bit or not at all (0-100) - failReforgeChance: 10 # Default = 10% + # The additional cost for each enchantment level present on an item + enchantmentCost: + # You can add, for example "arrow-infinite: 0.09" to change the enchantment cost for a specific enchantment + default: 5 - # Whether failed reforging should remove or downgrade the item's enchantments - failReforgeRemovesEnchantments: false # Default = false - - # The chance that an enchantment will be added to the reforged item (0-100) - extraEnchantmentChance: 5 # Default = 5% - - # The maximum number of enchantments the blacksmith will try to add - maxEnchantments: 3 + # Natural cost makes re-forging more expensive the more damaged the item is. Disabling this will enable the legacy + # blacksmith behavior instead + useNaturalCost: true - # Whether the blacksmith will reforge anvils as a special case - reforgeAnvils: false + # Exact time displays the exact number of seconds and minutes remaining as part of the reforging cool-down and + # reforging delay messages, instead of just vaguely hinting at the remaining time. + showExactTime: false + + # The cost of fully repairing a chipped anvil + chippedAnvilReforgingCost: 10.0 + + # The cost of fully repairing a damaged anvil + damagedAnvilReforgingCost: 20.0 - # All settable delays - delaysInSeconds: - # The maximum time for a reforging to finish - maximum: 30 + # 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 + defaults: + # Whether the item will drop a reforged item on the ground, instead of putting it into the user's inventory + dropItem: true + + # The items a blacksmith is able to reforge. Setting this only allows NPCs to repair the listed items. This should be + # set for each individual NPC, and should not be set here, unless you want to restrict NPCs which have not been set + # up yet. + reforgeAbleItems: [ ] + + # The enchantments a blacksmith is denied from applying to an item. Disable anything you find too op or annoying. + enchantmentBlocklist: [ "binding_curse", "mending", "vanishing_curse" ] + + # The chance to fail reforging an item, which only repairs the item a tiny bit or not at all (0-100) + failReforgeChance: 10 # Default = 10% + + # Whether failed reforging should remove or downgrade the item's enchantments + failReforgeRemovesEnchantments: false # Default = false + + # The chance that an enchantment will be added to the reforged item (0-100) + extraEnchantmentChance: 5 # Default = 5% + + # The maximum number of enchantments the blacksmith will try to add + maxEnchantments: 3 + + # Whether the blacksmith will reforge anvils as a special case + reforgeAnvils: false + + # All settable delays + delaysInSeconds: + # The maximum time for a reforging to finish + maximum: 30 + + # The minimum time for a reforging to finish + minimum: 5 + + # The cool-down period between each reforge + reforgeCoolDown: 60 + + # The title describing the blacksmith's usage/speciality + blacksmithTitle: "blacksmith" + + # All messages used by the NPC + messages: + # The message to display when another player is using the blacksmith + busyPlayerMessage: "&cI'm busy at the moment. Come back later!" + + # The message to display when the blacksmith is working on the reforging + busyReforgeMessage: "&cI'm working on it. Be patient! I'll finish {time}!" + + # The message to display when the blacksmith is still on a cool-down from the previous re-forging + coolDownUnexpiredMessage: "&cYou've already had your chance! Give me a break! I'll be ready {time}!" + + # The message to display when informing a player about the reforging cost + costMessage: "&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!" + + # The message to display when the blacksmith fails to reforge an item + failReforgeMessage: "&cWhoops! Didn't mean to do that! Maybe next time?" + + # The message to display when a player cannot pay for the reforging + insufficientFundsMessage: "&cYou don't have enough money to reforge that item!" + + # The message to display when holding an item the blacksmith is unable to reforge + invalidItemMessage: "&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!" + + # The message to display when presenting a different item than the one just evaluated + itemChangedMessage: "&cThat's not the item you wanted to reforge before!" + + # The message to display once the blacksmith starts re-forging + startReforgeMessage: "&eOk, let's see what I can do..." + + # The message to display once the reforging has successfully finished + successMessage: "There you go! All better!" + + # The message to display if a player is trying to reforge an item with full durability + notDamagedMessage: "&cThat item is not in need of repair" - # The minimum time for a reforging to finish - minimum: 5 - - # The cool-down period between each reforge - reforgeCoolDown: 60 - - # The title describing the blacksmith's usage/speciality - blacksmithTitle: "blacksmith" - - # All messages used by the NPC +# Settings for the scrapper trait +scrapper: + # The settings which apply to all Scrapper NPCs. These can also be changed using the /scrapperconfig command + global: + # Exact time displays the exact number of seconds and minutes remaining as part of the scrapping cool-down and + # scrapping delay messages, instead of just vaguely hinting at the remaining time. + showExactTime: false + + # Whether enchanted salvaged items should return some amount of exp upon salvage + giveExperience: true + # The settings which are set to any new scrapper NPC. To change any of these settings for an existing NPC, you must + # change the Citizens NPC file, or use the /scrapper command + defaults: + # Whether the item will drop materials resulting from scrapping on the ground, instead of putting them into the user's inventory + dropItems: true + + # The chance to fail a salvage, thus destroying the item (0-100) + failSalvageChance: 0 + + # The items a blacksmith is able to salvage. Setting this only allows NPCs to repair the listed items. This should be + # set for each individual NPC, and should not be set here, unless you want to restrict NPCs which have not been set + # up yet. + salvageAbleItems: [ ] messages: - # The message to display when another player is using the blacksmith + # The message to display when another player is using the scrapper busyPlayerMessage: "&cI'm busy at the moment. Come back later!" - - # The message to display when the blacksmith is working on the reforging - busyReforgeMessage: "&cI'm working on it. Be patient! I'll finish {time}!" - + + # The message to display when the blacksmith is working on the salvaging + busySalvageMessage: "&cI'm working on it. Be patient! I'll finish {time}!" + # The message to display when the blacksmith is still on a cool-down from the previous re-forging coolDownUnexpiredMessage: "&cYou've already had your chance! Give me a break! I'll be ready {time}!" - - # The message to display when informing a player about the reforging cost - costMessage: "&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!" - - # The message to display when the blacksmith fails to reforge an item - failReforgeMessage: "&cWhoops! Didn't mean to do that! Maybe next time?" - - # The message to display when a player cannot pay for the reforging - insufficientFundsMessage: "&cYou don't have enough money to reforge that item!" - - # The message to display when holding an item the blacksmith is unable to reforge - invalidItemMessage: "&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!" - - # The message to display when presenting a different item than the one just evaluated - itemChangedMessage: "&cThat's not the item you wanted to reforge before!" - - # The message to display once the blacksmith starts re-forging - startReforgeMessage: "&eOk, let's see what I can do..." - - # The message to display once the reforging has successfully finished - successMessage: "There you go! All better!" - - # The message to display if a player is trying to reforge an item with full durability - notDamagedMessage: "&cThat item is not in need of repair" # The message to display if the player tries to salvage an item the blacksmith cannot salvage cannotSalvageMessage: "&cI'm unable to salvage that item" - + # The message to display if reforging the player's item would result in no salvage tooDamagedForSalvageMessage: "&cThat item is too damaged to be salvaged into anything useful" - + # The message to display when an item is successfully salvaged - successSalvagedMessage: "&cThere you go!" \ No newline at end of file + successSalvagedMessage: "&cThere you go!" + + # The message to display when the blacksmith fails to reforge an item + failSalvageMessage: "&cWhoops! The item broke! Maybe next time?" + + # The message to display when presenting a different item than the one just evaluated + itemChangedMessage: "&cThat's not the item you wanted to salvage before!" + + # The message to display once the blacksmith starts re-forging + startSalvageMessage: "&eOk, let's see what I can do..." \ No newline at end of file