diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java index 2d3d946..d679ee6 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithConfigCommand.java @@ -8,8 +8,8 @@ import net.knarcraft.blacksmith.config.SettingValueType; import net.knarcraft.blacksmith.manager.ItemType; import net.knarcraft.blacksmith.manager.Message; import net.knarcraft.blacksmith.util.InputParsingHelper; -import net.knarcraft.blacksmith.util.MessageFormatter; import net.knarcraft.blacksmith.util.TypeValidationHelper; +import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.command.Command; @@ -67,17 +67,20 @@ public class BlackSmithConfigCommand implements CommandExecutor { if (args.length == 1) { //TODO: See if there's a way to remove this duplication + String rawValue; + String correctCommandName; if (detectedGlobalSetting != null) { - displaySuccessMessage(sender, Message.getCurrentValueMessage(detectedGlobalSetting.getCommandName(), - MessageFormatter.escapeColorCodes(String.valueOf(settings.getRawValue(detectedGlobalSetting))))); - return true; + rawValue = String.valueOf(settings.getRawValue(detectedGlobalSetting)); + correctCommandName = detectedGlobalSetting.getCommandName(); } else if (detectedNPCSetting != null) { - displaySuccessMessage(sender, Message.getCurrentValueMessage(detectedNPCSetting.getCommandName(), - MessageFormatter.escapeColorCodes(String.valueOf(settings.getRawValue(detectedNPCSetting))))); - return true; + rawValue = String.valueOf(settings.getRawValue(detectedNPCSetting)); + correctCommandName = detectedNPCSetting.getCommandName(); } else { return false; } + displaySuccessMessage(sender, Message.getCurrentValueMessage(correctCommandName, rawValue)); + sender.sendMessage("Raw value: " + rawValue.replace(ChatColor.COLOR_CHAR, '&')); + return true; } else if (args.length == 2 && isSpecialCase(commandName)) { if (displaySpecialCaseValue(args[1], sender, detectedGlobalSetting, settings)) { return true; diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java index 45e6999..82f1483 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithEditCommand.java @@ -58,8 +58,9 @@ public class BlackSmithEditCommand implements CommandExecutor { CommandSender sender) { if (newValue == null) { //Display the current value of the setting - displaySuccessMessage(sender, Message.getCurrentValueMessage(npcSetting.getCommandName(), - MessageFormatter.escapeColorCodes(String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting))))); + String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting)); + displaySuccessMessage(sender, Message.getCurrentValueMessage(npcSetting.getCommandName(), rawValue)); + sender.sendMessage("Raw value: " + rawValue.replace(ChatColor.COLOR_CHAR, '&')); return true; } else { boolean isValidType = TypeValidationHelper.isValid(npcSetting.getValueType(), newValue, sender); diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java index 200e917..65a86dd 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java @@ -24,8 +24,10 @@ public enum NPCSetting { -----------*/ BUSY_WITH_PLAYER_MESSAGE("defaults.messages.busy-with-player", SettingValueType.STRING, "&cI'm busy at the moment. Come back later!", "busyPlayerMessage"), + //TODO: Add placeholder for remaining time? BUSY_WITH_REFORGE_MESSAGE("defaults.messages.busy-with-reforge", SettingValueType.STRING, "&cI'm working on it. Be patient!", "busyReforgeMessage"), + //TODO: Add placeholder for remaining time? COOL_DOWN_UNEXPIRED_MESSAGE("defaults.messages.cool-down-not-expired", SettingValueType.STRING, "&cYou've already had your chance! Give me a break!", "coolDownUnexpiredMessage"), COST_MESSAGE( diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java index 54f047c..45cb55c 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/NPCSettings.java @@ -64,8 +64,11 @@ public class NPCSettings { public void changeSetting(NPCSetting setting, Object newValue) { if (setting == NPCSetting.REFORGE_ABLE_ITEMS) { newValue = replaceReforgeAblePlaceholders(newValue); + currentValues.put(setting, newValue); + updateReforgeAbleItems(); + } else { + currentValues.put(setting, newValue); } - currentValues.put(setting, newValue); } /** @@ -346,20 +349,20 @@ public class NPCSettings { */ private void updateReforgeAbleItems() { this.reforgeAbleItems.clear(); - List reforgeAbleItems = (List) currentValues.get(NPCSetting.REFORGE_ABLE_ITEMS); - if (reforgeAbleItems == null) { + String newReforgeAbleItems = (String) currentValues.get(NPCSetting.REFORGE_ABLE_ITEMS); + if (newReforgeAbleItems == null) { return; } - for (Object item : reforgeAbleItems) { - if (item == null) { + for (String item : newReforgeAbleItems.split(",")) { + if (item == null || item.equalsIgnoreCase("null")) { continue; } - Material material = Material.matchMaterial(String.valueOf(item)); + Material material = Material.matchMaterial(item.replace('-', '_')); if (material != null && BlacksmithTrait.isRepairable(new ItemStack(material, 1))) { this.reforgeAbleItems.add(material); } else { - BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to verify " + material + + BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to verify " + item + " as a valid reforge-able item"); } } diff --git a/src/main/java/net/knarcraft/blacksmith/config/SmithPreset.java b/src/main/java/net/knarcraft/blacksmith/config/SmithPreset.java index 6a34833..c076be4 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/SmithPreset.java +++ b/src/main/java/net/knarcraft/blacksmith/config/SmithPreset.java @@ -43,7 +43,8 @@ public enum SmithPreset { */ public static String replacePlaceholder(String possiblePlaceholder) { for (SmithPreset smithPreset : SmithPreset.values()) { - if (possiblePlaceholder.equalsIgnoreCase("preset:" + smithPreset.name())) { + if (possiblePlaceholder.replace('-', '_').equalsIgnoreCase("preset:" + + smithPreset.name())) { return String.join(",", smithPreset.getMaterialNames()); } } diff --git a/src/main/java/net/knarcraft/blacksmith/util/MessageFormatter.java b/src/main/java/net/knarcraft/blacksmith/util/MessageFormatter.java index 2bfbad3..0d8458d 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/MessageFormatter.java +++ b/src/main/java/net/knarcraft/blacksmith/util/MessageFormatter.java @@ -49,17 +49,6 @@ public final class MessageFormatter { sender.sendMessage(ChatColor.DARK_RED + getFormattedMessage(message)); } - /** - * Escapes color codes to prevent them from being shown - * - * @param input

The input string to escape color codes for

- * @return

The input string with color codes escaped

- */ - public static String escapeColorCodes(String input) { - //TODO: Find a working way of escaping color codes - return translateColors(input).replace(String.valueOf(ChatColor.COLOR_CHAR), "&&&"); - } - /** * Gets the formatted version of any chat message *