Makes edit commands display the default value if no value is provided

This commit is contained in:
2024-05-07 13:54:45 +02:00
parent cb477cafb5
commit 75744ccdd0
4 changed files with 71 additions and 28 deletions

View File

@ -8,6 +8,7 @@ import net.knarcraft.blacksmith.config.SettingValueType;
import net.knarcraft.blacksmith.config.Settings;
import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage;
import net.knarcraft.blacksmith.trait.CustomTrait;
import net.knarcraft.blacksmith.util.ConfigCommandHelper;
import net.knarcraft.blacksmith.util.InputParsingHelper;
import net.knarcraft.blacksmith.util.TypeValidationHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
@ -22,6 +23,7 @@ import java.util.Arrays;
import java.util.logging.Level;
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getCurrentValueMessage;
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getDefaultValueMessage;
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getValueChangedMessage;
/**
@ -159,25 +161,33 @@ public abstract class EditCommand<K extends CustomTrait<L>, L extends Setting> i
StringFormatter formatter = BlacksmithPlugin.getStringFormatter();
//Find the value of the specified setting
String commandName = setting.getCommandName();
String currentValue = String.valueOf(settings.getRawValue(setting));
String defaultValue = String.valueOf(setting.getDefaultValue());
String marker = formatter.getUnFormattedMessage(BlacksmithTranslatableMessage.SETTING_OVERRIDDEN_MARKER);
boolean isMessage = setting.isMessage();
boolean isSet = !InputParsingHelper.isEmpty(currentValue);
// Display the description for how this setting is used
formatter.displaySuccessMessage(sender, setting.getDescription());
String rawValue = String.valueOf(settings.getRawValue(setting));
if (InputParsingHelper.isEmpty(rawValue)) {
//Display the default value, if no custom value has been specified
rawValue = String.valueOf(globalSettings.getRawValue(setting));
formatter.displayNeutralMessage(sender,
getCurrentValueMessage(setting.getCommandName(), rawValue));
} else {
//Add a marker if the value has been customized
String marker = BlacksmithPlugin.getStringFormatter().getUnFormattedMessage(
BlacksmithTranslatableMessage.SETTING_OVERRIDDEN_MARKER);
formatter.displayNeutralMessage(sender,
getCurrentValueMessage(setting.getCommandName(), rawValue) + marker);
// Display the default value
formatter.displayNeutralMessage(sender, getDefaultValueMessage(commandName, defaultValue));
if (isMessage) {
ConfigCommandHelper.displayRaw(sender, defaultValue);
}
if (setting.isMessage()) {
sender.sendMessage(BlacksmithTranslatableMessage.getRawValueMessage(
rawValue.replace(ChatColor.COLOR_CHAR, '&')));
if (!isSet) {
//Display the global value, if no custom value has been specified
currentValue = String.valueOf(globalSettings.getRawValue(setting));
}
// Display the value with a marker if it's customized
formatter.displayNeutralMessage(sender, getCurrentValueMessage(commandName, currentValue) + (isSet ? marker : ""));
if (isMessage) {
ConfigCommandHelper.displayRaw(sender, currentValue);
}
}