From c71d664a79837ede7db4ee71544bfcb0f4853628 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 5 May 2024 15:51:46 +0200 Subject: [PATCH] Fixes a NullPointerException and the default value of successSalvagedMessage --- .../blacksmith/command/EditCommand.java | 2 +- .../config/scrapper/ScrapperSetting.java | 2 +- .../BlacksmithTranslatableMessage.java | 19 ++++++++++++++----- src/main/resources/config.yml | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java b/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java index d2f7cce..a88f350 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java @@ -131,7 +131,7 @@ public abstract class EditCommand, L extends Setting> i } settings.changeValue(setting, newValue); 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 CitizensAPI.getNPCRegistry().saveToStore(); } diff --git a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java index e758daa..3aaa42c 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java @@ -117,7 +117,7 @@ public enum ScrapperSetting implements Setting { /** * 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), /** diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java index 3265bcd..eb41541 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java @@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.formatting; import net.knarcraft.blacksmith.BlacksmithPlugin; import net.knarcraft.knarlib.formatting.StringReplacer; import net.knarcraft.knarlib.formatting.TranslatableMessage; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -145,7 +146,8 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @param rawValue

The raw value to display

* @return

The message to display

*/ - public static String getRawValueMessage(String rawValue) { + @NotNull + public static String getRawValueMessage(@NotNull String rawValue) { return BlacksmithPlugin.getStringFormatter().replacePlaceholder(BlacksmithTranslatableMessage.RAW_VALUE, "{rawValue}", rawValue); } @@ -157,7 +159,8 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @param newValue

The new value of the setting

* @return

The string to display to a user

*/ - 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, List.of("{setting}", "{newValue}"), List.of(setting, newValue)); } @@ -171,7 +174,9 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @param newValue

The new value of the setting

* @return

The string to display to a user

*/ - 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( BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED)); stringReplacer.add("{setting}", setting); @@ -188,7 +193,8 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @param currentValue

The current value of the setting

* @return

The string to display to a user

*/ - 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, List.of("{setting}", "{currentValue}"), List.of(setting, currentValue)); @@ -203,7 +209,9 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @param currentValue

The current value of the setting

* @return

The string to display to a user

*/ - 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( BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM)); stringReplacer.add("{setting}", setting); @@ -214,6 +222,7 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { } @Override + @NotNull public TranslatableMessage[] getAllMessages() { return BlacksmithTranslatableMessage.values(); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 669b256..37e7c4e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -182,7 +182,7 @@ scrapper: tooDamagedForSalvageMessage: "&cThat item is too damaged to be salvaged into anything useful" # 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 failSalvageMessage: "&cWhoops! The item broke! Maybe next time?"