Makes it possible to edit reforgeAbleItems globally #17

This commit is contained in:
Kristian Knarvik 2023-01-11 01:54:52 +01:00
parent 8423eabc57
commit bd00a59d08
4 changed files with 19 additions and 13 deletions

View File

@ -40,13 +40,6 @@ public class BlackSmithConfigCommand implements CommandExecutor {
}
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
//Changing reforge-able items' default isn't recommended
if (commandName.equalsIgnoreCase(NPCSetting.REFORGE_ABLE_ITEMS.getCommandName())) {
BlacksmithPlugin.getStringFormatter().displayErrorMessage(sender,
BlacksmithTranslatableMessage.DEFAULT_REFORGE_ABLE_ITEMS_UNCHANGEABLE);
return false;
}
//Find which global setting the user has specified, if any
GlobalSetting detectedGlobalSetting = null;
for (GlobalSetting globalSetting : GlobalSetting.values()) {

View File

@ -92,6 +92,11 @@ public class GlobalSettings {
defaultNPCSettings.put(npcSetting, newValue);
}
save();
if (npcSetting == NPCSetting.REFORGE_ABLE_ITEMS) {
loadReforgeAbleItems();
} else if (npcSetting == NPCSetting.ENCHANTMENT_BLOCKLIST) {
loadEnchantmentBlocklist();
}
}
/**
@ -482,9 +487,23 @@ public class GlobalSettings {
defaultNPCSettings.put(setting, root.getRaw(setting.getPath()));
}
}
loadReforgeAbleItems();
loadEnchantmentBlocklist();
}
/**
* Loads reforgeAble items from the current value
*/
private void loadReforgeAbleItems() {
defaultReforgeAbleMaterials.clear();
defaultReforgeAbleMaterials.addAll(NPCSettings.getReforgeAbleItems(ConfigHelper.asStringList(
defaultNPCSettings.get(NPCSetting.REFORGE_ABLE_ITEMS))));
}
/**
* Loads the enchantment blocklist from the current value
*/
private void loadEnchantmentBlocklist() {
defaultEnchantmentBlocklist.clear();
defaultEnchantmentBlocklist.addAll(NPCSettings.getEnchantmentBlocklist(ConfigHelper.asStringList(
defaultNPCSettings.get(NPCSetting.ENCHANTMENT_BLOCKLIST))));

View File

@ -52,11 +52,6 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
*/
NO_NPC_SELECTED,
/**
* The message displayed if trying to change the default value of reforge-able item using commands
*/
DEFAULT_REFORGE_ABLE_ITEMS_UNCHANGEABLE,
/**
* The message displayed if a string list is required, but something else is given
*/

View File

@ -7,7 +7,6 @@ en:
ITEM_TYPE_MATERIAL: "material"
RAW_VALUE: "Raw value: {rawValue}"
NO_NPC_SELECTED: "You must select an NPC before running this command"
DEFAULT_REFORGE_ABLE_ITEMS_UNCHANGEABLE: "Changing reforge-able items globally will make every new blacksmith unable to reforge anything not in the list, unless it's changed for the individual NPC. If you really want to change this, change it manually."
INPUT_STRING_LIST_REQUIRED: "A string list is required!"
INPUT_PERCENTAGE_REQUIRED: "You specified a value which isn't between 0 and 100!"
INPUT_STRING_REQUIRED: "A non-empty string is required!"