Makes /blacksmith for an unset value display the default value instead of "null"

This commit is contained in:
Kristian Knarvik 2022-10-07 16:17:32 +02:00
parent 878ad3aa67
commit fb483a4c2a

View File

@ -2,6 +2,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.SettingValueType;
import net.knarcraft.blacksmith.formatting.StringFormatter;
@ -48,7 +49,7 @@ public class BlackSmithEditCommand implements CommandExecutor {
if (npcSetting.getValueType() == SettingValueType.STRING && args.length > 2) {
newValue = String.join(" ", Arrays.asList(args).subList(1, args.length));
}
return changeNPCSetting(blacksmithTrait, npcSetting, newValue, sender);
return displayOrChangeNPCSetting(blacksmithTrait, npcSetting, newValue, sender);
}
}
return false;
@ -63,11 +64,15 @@ public class BlackSmithEditCommand implements CommandExecutor {
* @param sender <p>The command sender to notify about results</p>
* @return <p>True if everything went successfully</p>
*/
private boolean changeNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, String newValue,
CommandSender sender) {
private boolean displayOrChangeNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, String newValue,
CommandSender sender) {
if (newValue == null) {
//Display the current value of the setting
String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting));
//Displays the default value, if no custom value has been specified
if (rawValue == null || rawValue.equalsIgnoreCase("null")) {
rawValue = String.valueOf(BlacksmithPlugin.getInstance().getSettings().getRawValue(npcSetting));
}
displaySuccessMessage(sender, TranslatableMessage.getCurrentValueMessage(npcSetting.getCommandName(), rawValue));
if (npcSetting.getPath().startsWith("defaults.messages")) {
sender.sendMessage(TranslatableMessage.getRawValueMessage(