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

@ -12,6 +12,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getCurrentValueMessage;
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getDefaultValueMessage;
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getValueChangedMessage;
/**
@ -55,33 +57,43 @@ public final class ConfigCommandHelper {
public static <K extends Setting> void displayCurrentValue(@NotNull K setting,
@NotNull Settings<K> settings,
@NotNull CommandSender sender) {
String settingValue;
String correctCommandName;
StringFormatter formatter = BlacksmithPlugin.getStringFormatter();
boolean printRawValue = false;
//Find the value of the specified setting
settingValue = String.valueOf(settings.getRawValue(setting));
correctCommandName = setting.getCommandName();
String currentValue = String.valueOf(settings.getRawValue(setting));
String defaultValue = String.valueOf(setting.getDefaultValue());
//For messages, print an additional raw value showing which color codes are used
if (setting.isPerNPC() && setting.isMessage()) {
printRawValue = true;
}
StringFormatter formatter = BlacksmithPlugin.getStringFormatter();
// Display the description of the setting
formatter.displaySuccessMessage(sender, setting.getDescription());
// Display the current value of the setting
formatter.displayNeutralMessage(sender, BlacksmithTranslatableMessage.getCurrentValueMessage(
correctCommandName, settingValue));
// Print the value with any colors displayed as &a-f0-9
// Display the setting's default value
formatter.displayNeutralMessage(sender, getDefaultValueMessage(setting.getCommandName(), defaultValue));
if (printRawValue) {
sender.sendMessage(BlacksmithTranslatableMessage.getRawValueMessage(
settingValue.replace(ChatColor.COLOR_CHAR, '&')));
displayRaw(sender, defaultValue);
}
// Display the current value of the setting
formatter.displayNeutralMessage(sender, getCurrentValueMessage(setting.getCommandName(), currentValue));
if (printRawValue) {
displayRaw(sender, currentValue);
}
}
/**
* Displays a message with formatting codes shown
*
* @param sender <p>The sender to display the raw value to</p>
* @param value <p>The value to display raw</p>
*/
public static void displayRaw(@NotNull CommandSender sender, @NotNull String value) {
sender.sendMessage(BlacksmithTranslatableMessage.getRawValueMessage(
value.replace(ChatColor.COLOR_CHAR, '&')));
}
}