The message to translate
- * @returnThe message, in the language specified in the configuration
- */ - public static @NotNull String translate(TranslatableMessage translatableMessage) { - return BlacksmithPlugin.getTranslator().getTranslatedMessage(translatableMessage); - } - /** * Gets settings for the blacksmith plugin's blacksmiths * @@ -118,15 +107,6 @@ public class BlacksmithPlugin extends JavaPlugin { this.getConfig().getString("language", "en")); } - /** - * Gets the translator to use for translation - * - * @returnThe translator to use
- */ - public static @NotNull Translator getTranslator() { - return BlacksmithPlugin.translator; - } - /** * Gets the string formatter to use for formatting * @@ -136,6 +116,15 @@ public class BlacksmithPlugin extends JavaPlugin { return BlacksmithPlugin.stringFormatter; } + /** + * Gets the translator to use for translation + * + * @returnThe translator to use
+ */ + public static @NotNull Translator getTranslator() { + return BlacksmithPlugin.translator; + } + @Override public void onDisable() { getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled."); diff --git a/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java b/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java index eb51c81..9ecd469 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java @@ -170,7 +170,8 @@ public abstract class EditCommandThe message to display
*/ public static String getRawValueMessage(String rawValue) { - return StringFormatter.replacePlaceholder(BlacksmithPlugin.translate( - BlacksmithTranslatableMessage.RAW_VALUE), "{rawValue}", rawValue); + return BlacksmithPlugin.getStringFormatter().replacePlaceholder(BlacksmithTranslatableMessage.RAW_VALUE, + "{rawValue}", rawValue); } /** @@ -156,9 +158,8 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @returnThe string to display to a user
*/ public static String getValueChangedMessage(String setting, String newValue) { - return StringFormatter.replacePlaceholders(BlacksmithPlugin.translate( - BlacksmithTranslatableMessage.VALUE_CHANGED), new String[]{"{setting}", "{newValue}"}, - new String[]{setting, newValue}); + return BlacksmithPlugin.getStringFormatter().replacePlaceholders(BlacksmithTranslatableMessage.VALUE_CHANGED, + List.of("{setting}", "{newValue}"), List.of(setting, newValue)); } /** @@ -171,10 +172,13 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @returnThe string to display to a user
*/ public static String getItemValueChangedMessage(String setting, ItemType itemType, String item, String newValue) { - return StringFormatter.replacePlaceholders(BlacksmithPlugin.translate( - BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED), - new String[]{"{setting}", "{itemType}", "{item}", "{newValue}"}, - new String[]{setting, itemType.getItemTypeName(), item, newValue}); + StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnformattedMessage( + BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED)); + stringReplacer.add("{setting}", setting); + stringReplacer.add("{itemType}", itemType.getItemTypeName()); + stringReplacer.add("{item}", item); + stringReplacer.add("{newValue}", newValue); + return stringReplacer.replace(); } /** @@ -185,9 +189,9 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @returnThe string to display to a user
*/ public static String getCurrentValueMessage(String setting, String currentValue) { - return StringFormatter.replacePlaceholders(BlacksmithPlugin.translate( - BlacksmithTranslatableMessage.CURRENT_VALUE), new String[]{"{setting}", "{currentValue}"}, - new String[]{setting, currentValue}); + return BlacksmithPlugin.getStringFormatter().replacePlaceholders(BlacksmithTranslatableMessage.CURRENT_VALUE, + List.of("{setting}", "{currentValue}"), + List.of(setting, currentValue)); } /** @@ -200,10 +204,13 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @returnThe string to display to a user
*/ public static String getItemCurrentValueMessage(String setting, ItemType itemType, String item, String currentValue) { - return StringFormatter.replacePlaceholders(BlacksmithPlugin.translate( - BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM), - new String[]{"{setting}", "{itemType}", "{item}", "{currentValue}"}, - new String[]{setting, itemType.getItemTypeName(), item, currentValue}); + StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnformattedMessage( + BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM)); + stringReplacer.add("{setting}", setting); + stringReplacer.add("{itemType}", itemType.getItemTypeName()); + stringReplacer.add("{item}", item); + stringReplacer.add("{currentValue}", currentValue); + return stringReplacer.replace(); } @Override diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java b/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java index 235754a..392c471 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java @@ -1,6 +1,7 @@ package net.knarcraft.blacksmith.formatting; import net.knarcraft.blacksmith.BlacksmithPlugin; +import net.knarcraft.knarlib.formatting.StringFormatter; /** * An enum representing all item types used in messages @@ -16,9 +17,11 @@ public enum ItemType { * @returnThe name of this item type
*/ public String getItemTypeName() { + StringFormatter stringFormatter = BlacksmithPlugin.getStringFormatter(); return switch (this) { - case MATERIAL -> BlacksmithPlugin.translate(BlacksmithTranslatableMessage.ITEM_TYPE_MATERIAL); - case ENCHANTMENT -> BlacksmithPlugin.translate(BlacksmithTranslatableMessage.ITEM_TYPE_ENCHANTMENT); + case MATERIAL -> stringFormatter.getUnformattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_MATERIAL); + case ENCHANTMENT -> + stringFormatter.getUnformattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_ENCHANTMENT); }; } diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java b/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java index 51a625c..0d8b870 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java @@ -53,7 +53,8 @@ public final class TimeFormatter { * @returnText describing the time interval
*/ private static String getMessageFromInterval(TimeInterval interval) { - String text = BlacksmithPlugin.translate(BlacksmithTranslatableMessage.valueOf(interval.name())); + String text = BlacksmithPlugin.getStringFormatter().getUnformattedMessage( + BlacksmithTranslatableMessage.valueOf(interval.name())); //Choose a random entry if a comma-separated list is provided if (text.contains(",")) { diff --git a/src/main/java/net/knarcraft/blacksmith/util/ConfigHelper.java b/src/main/java/net/knarcraft/blacksmith/util/ConfigHelper.java index 62369c9..8ae38e7 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/ConfigHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/ConfigHelper.java @@ -25,8 +25,8 @@ public final class ConfigHelper { if (value == null) { return new ArrayList<>(); } - if (value instanceof String) { - return List.of(((String) value).split(",")); + if (value instanceof String string) { + return List.of((string).split(",")); } else if (value instanceof List> list) { List