Fixes a NullPointerException and the default value of successSalvagedMessage
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2024-05-05 15:51:46 +02:00
parent 2612f4f7d8
commit c71d664a79
4 changed files with 17 additions and 8 deletions

View File

@ -131,7 +131,7 @@ public abstract class EditCommand<K extends CustomTrait<L>, L extends Setting> i
} }
settings.changeValue(setting, newValue); settings.changeValue(setting, newValue);
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender, BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
getValueChangedMessage(setting.getCommandName(), newValue)); getValueChangedMessage(setting.getCommandName(), String.valueOf(newValue)));
//Save the changes immediately to prevent data loss on server crash //Save the changes immediately to prevent data loss on server crash
CitizensAPI.getNPCRegistry().saveToStore(); CitizensAPI.getNPCRegistry().saveToStore();
} }

View File

@ -117,7 +117,7 @@ public enum ScrapperSetting implements Setting {
/** /**
* The message displayed if a salvage is successful * The message displayed if a salvage is successful
*/ */
SUCCESS_SALVAGE_MESSAGE("successSalvagedMessage", SettingValueType.STRING, "&cThere you go!", SUCCESS_SALVAGE_MESSAGE("successSalvagedMessage", SettingValueType.STRING, "There you go!",
"The message to display when an item is successfully salvaged", true, true), "The message to display when an item is successfully salvaged", true, true),
/** /**

View File

@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.formatting;
import net.knarcraft.blacksmith.BlacksmithPlugin; import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.knarlib.formatting.StringReplacer; import net.knarcraft.knarlib.formatting.StringReplacer;
import net.knarcraft.knarlib.formatting.TranslatableMessage; import net.knarcraft.knarlib.formatting.TranslatableMessage;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
@ -145,7 +146,8 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
* @param rawValue <p>The raw value to display</p> * @param rawValue <p>The raw value to display</p>
* @return <p>The message to display</p> * @return <p>The message to display</p>
*/ */
public static String getRawValueMessage(String rawValue) { @NotNull
public static String getRawValueMessage(@NotNull String rawValue) {
return BlacksmithPlugin.getStringFormatter().replacePlaceholder(BlacksmithTranslatableMessage.RAW_VALUE, return BlacksmithPlugin.getStringFormatter().replacePlaceholder(BlacksmithTranslatableMessage.RAW_VALUE,
"{rawValue}", rawValue); "{rawValue}", rawValue);
} }
@ -157,7 +159,8 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
* @param newValue <p>The new value of the setting</p> * @param newValue <p>The new value of the setting</p>
* @return <p>The string to display to a user</p> * @return <p>The string to display to a user</p>
*/ */
public static String getValueChangedMessage(String setting, String newValue) { @NotNull
public static String getValueChangedMessage(@NotNull String setting, @NotNull String newValue) {
return BlacksmithPlugin.getStringFormatter().replacePlaceholders(BlacksmithTranslatableMessage.VALUE_CHANGED, return BlacksmithPlugin.getStringFormatter().replacePlaceholders(BlacksmithTranslatableMessage.VALUE_CHANGED,
List.of("{setting}", "{newValue}"), List.of(setting, newValue)); List.of("{setting}", "{newValue}"), List.of(setting, newValue));
} }
@ -171,7 +174,9 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
* @param newValue <p>The new value of the setting</p> * @param newValue <p>The new value of the setting</p>
* @return <p>The string to display to a user</p> * @return <p>The string to display to a user</p>
*/ */
public static String getItemValueChangedMessage(String setting, ItemType itemType, String item, String newValue) { @NotNull
public static String getItemValueChangedMessage(@NotNull String setting, @NotNull ItemType itemType,
@NotNull String item, @NotNull String newValue) {
StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage( StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage(
BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED)); BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED));
stringReplacer.add("{setting}", setting); stringReplacer.add("{setting}", setting);
@ -188,7 +193,8 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
* @param currentValue <p>The current value of the setting</p> * @param currentValue <p>The current value of the setting</p>
* @return <p>The string to display to a user</p> * @return <p>The string to display to a user</p>
*/ */
public static String getCurrentValueMessage(String setting, String currentValue) { @NotNull
public static String getCurrentValueMessage(@NotNull String setting, @NotNull String currentValue) {
return BlacksmithPlugin.getStringFormatter().replacePlaceholders(BlacksmithTranslatableMessage.CURRENT_VALUE, return BlacksmithPlugin.getStringFormatter().replacePlaceholders(BlacksmithTranslatableMessage.CURRENT_VALUE,
List.of("{setting}", "{currentValue}"), List.of("{setting}", "{currentValue}"),
List.of(setting, currentValue)); List.of(setting, currentValue));
@ -203,7 +209,9 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
* @param currentValue <p>The current value of the setting</p> * @param currentValue <p>The current value of the setting</p>
* @return <p>The string to display to a user</p> * @return <p>The string to display to a user</p>
*/ */
public static String getItemCurrentValueMessage(String setting, ItemType itemType, String item, String currentValue) { @NotNull
public static String getItemCurrentValueMessage(@NotNull String setting, @NotNull ItemType itemType,
@NotNull String item, @NotNull String currentValue) {
StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage( StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage(
BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM)); BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM));
stringReplacer.add("{setting}", setting); stringReplacer.add("{setting}", setting);
@ -214,6 +222,7 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
} }
@Override @Override
@NotNull
public TranslatableMessage[] getAllMessages() { public TranslatableMessage[] getAllMessages() {
return BlacksmithTranslatableMessage.values(); return BlacksmithTranslatableMessage.values();
} }

View File

@ -182,7 +182,7 @@ scrapper:
tooDamagedForSalvageMessage: "&cThat item is too damaged to be salvaged into anything useful" tooDamagedForSalvageMessage: "&cThat item is too damaged to be salvaged into anything useful"
# The message to display when an item is successfully salvaged # The message to display when an item is successfully salvaged
successSalvagedMessage: "&cThere you go!" successSalvagedMessage: "There you go!"
# The message to display when the scrapper fails to salvage an item # The message to display when the scrapper fails to salvage an item
failSalvageMessage: "&cWhoops! The item broke! Maybe next time?" failSalvageMessage: "&cWhoops! The item broke! Maybe next time?"