Fixes reforge-able items and displaying color formatting codes
This commit is contained in:
parent
a6e9163dbd
commit
f058f4eec8
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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 <p>The input string to escape color codes for</p>
|
||||
* @return <p>The input string with color codes escaped</p>
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user