process {@@i18n.strings} in all command replacements

This commit is contained in:
Aikar
2017-07-18 22:35:45 -04:00
parent f3b8b6034e
commit 1f7a412783
3 changed files with 23 additions and 1 deletions
@@ -45,6 +45,7 @@ final class ACFPatterns {
public static final Pattern NON_PRINTABLE_CHARACTERS = Pattern.compile("[^\\x20-\\x7F]");
public static final Pattern EQUALS = Pattern.compile("=");
public static final Pattern FORMATTER = Pattern.compile("<c(?<color>\\d+)>(?<msg>.+?)</c\\1>", Pattern.CASE_INSENSITIVE);
public static final Pattern I18N_STRING = Pattern.compile("\\{@@(?<key>.+?)}", Pattern.CASE_INSENSITIVE);
@@ -76,6 +76,6 @@ public class CommandReplacements {
text = entry.getKey().matcher(text).replaceAll(entry.getValue());
}
return text;
return manager.getLocales().replaceI18NStrings(text);
}
}
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
@SuppressWarnings("WeakerAccess")
public class Locales {
@@ -100,4 +101,24 @@ public class Locales {
return message;
}
public String replaceI18NStrings(String message) {
if (message == null) {
return null;
}
Matcher matcher = ACFPatterns.I18N_STRING.matcher(message);
if (!matcher.matches()) {
return message;
}
CommandIssuer issuer = CommandManager.getCurrentCommandIssuer();
matcher.reset();
StringBuffer sb = new StringBuffer(message.length());
while (matcher.find()) {
MessageKey key = MessageKey.of(matcher.group("key"));
matcher.appendReplacement(sb, Matcher.quoteReplacement(getMessage(issuer, key)));
}
matcher.appendTail(sb);
return sb.toString();
}
}