diff --git a/src/main/java/net/knarcraft/knarlib/formatting/Translator.java b/src/main/java/net/knarcraft/knarlib/formatting/Translator.java index 1692c55..858910d 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/Translator.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/Translator.java @@ -31,6 +31,7 @@ public final class Translator { private final List messageCategories = new ArrayList<>(); private Map translatedMessages; private Map backupTranslatedMessages; + private ColorConversion colorConversion = ColorConversion.RGB; /** * Registers all translatable messages in the given message category @@ -44,6 +45,23 @@ public final class Translator { messageCategories.add(translatableMessage); } + /** + * Sets the color conversion to use for translated messages + * + *

See {@link net.knarcraft.knarlib.property.ColorConversion} and + * {@link net.knarcraft.knarlib.util.ColorHelper#translateColorCodes(String, ColorConversion)} for details, but + * basically, this allows setting which color codes should be converted, and which should not be.

+ * + * @param colorConversion

The color conversion to be used

+ */ + public void setColorConversion(ColorConversion colorConversion) { + if (colorConversion != null) { + this.colorConversion = colorConversion; + } else { + throw new IllegalArgumentException("Color conversion cannot be null"); + } + } + /** * Loads the languages used by this translator * @@ -77,7 +95,7 @@ public final class Translator { } else { translatedMessage = translatableMessage.toString(); } - return ColorHelper.translateColorCodes(translatedMessage, ColorConversion.RGB); + return ColorHelper.translateColorCodes(translatedMessage, colorConversion); } /** @@ -115,7 +133,8 @@ public final class Translator { try { Bukkit.getLogger().log(Level.INFO, "Loading custom strings..."); - return loadTranslatableMessages(language, new BufferedReader(new InputStreamReader(new FileInputStream(strings)))); + return loadTranslatableMessages(language, new BufferedReader(new InputStreamReader( + new FileInputStream(strings)))); } catch (FileNotFoundException e) { Bukkit.getLogger().log(Level.WARNING, "Unable to load custom messages"); return null;