diff --git a/src/main/java/com/onarandombox/MultiverseCore/localization/MessageProvider.java b/src/main/java/com/onarandombox/MultiverseCore/localization/MessageProvider.java index cc92e167..c35307df 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/localization/MessageProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/localization/MessageProvider.java @@ -17,18 +17,20 @@ public interface MessageProvider { * Returns a message (as {@link String}) for the specified key (as {@link MultiverseMessage}). * * @param key The key + * @param args Args for String.format() * @return The message */ - public String getMessage(MultiverseMessage key); + public String getMessage(MultiverseMessage key, Object... args); /** * Returns a message (as {@link String}) in a specified {@link Locale} for the specified key (as {@link MultiverseMessage}). * * @param key The Key * @param locale The {@link Locale} + * @param args Args for String.format() * @return The message */ - public String getMessage(MultiverseMessage key, Locale locale); + public String getMessage(MultiverseMessage key, Locale locale, Object... args); /** * Returns the Locale this MessageProvider is currently using. diff --git a/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java b/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java index bc35bedc..d7f3a98a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java @@ -46,6 +46,13 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider { + locale.toString(), locale); } + public String format(String string, Object... args) { + // Replaces & with the Section character + string = string.replaceAll("&", Character.toString((char) 167)); + + return String.format(string, args); + } + /** * {@inheritDoc} */ @@ -106,26 +113,26 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider { * {@inheritDoc} */ @Override - public String getMessage(MultiverseMessage key) { + public String getMessage(MultiverseMessage key, Object... args) { if (!isLocaleLoaded(locale)) { - return key.getDefault(); + return format(key.getDefault(), args); } else - return messages.get(locale).get(key); + return format(messages.get(locale).get(key), args); } /** * {@inheritDoc} */ @Override - public String getMessage(MultiverseMessage key, Locale locale) { + public String getMessage(MultiverseMessage key, Locale locale, Object... args) { try { maybeLoadLocale(locale); } catch (LocalizationLoadingException e) { e.printStackTrace(); return getMessage(key); } - return messages.get(locale).get(key); + return format(messages.get(locale).get(key), args); } /**