mirror of
https://github.com/aikar/commands.git
synced 2026-07-01 18:48:25 +00:00
process {@@i18n.strings} in all command replacements
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user