mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Adds a new pattern for CommandReplacements: %{<key>} (#313)
This commit is contained in:
@@ -49,10 +49,12 @@ final class ACFPatterns {
|
||||
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);
|
||||
public static final Pattern REPLACEMENT_PATTERN = Pattern.compile("%\\{.[^\\s]*}");
|
||||
|
||||
|
||||
private ACFPatterns() {
|
||||
}
|
||||
|
||||
private ACFPatterns() {}
|
||||
@SuppressWarnings("Convert2MethodRef")
|
||||
static final Map<String, Pattern> patternCache = ExpiringMap.builder()
|
||||
.maxSize(200)
|
||||
@@ -67,9 +69,7 @@ final class ACFPatterns {
|
||||
* <p>
|
||||
* The {@link #patternCache} does not contain the constant patterns defined in this class.
|
||||
*
|
||||
* @param pattern
|
||||
* The raw pattern in a String.
|
||||
*
|
||||
* @param pattern The raw pattern in a String.
|
||||
* @return The pattern which has been cached.
|
||||
*/
|
||||
public static Pattern getPattern(String pattern) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CommandReplacements {
|
||||
throw new IllegalArgumentException("Must pass a number of arguments divisible by 2.");
|
||||
}
|
||||
for (int i = 0; i < replacements.length; i += 2) {
|
||||
addReplacement(replacements[i], replacements[i+1]);
|
||||
addReplacement(replacements[i], replacements[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ public class CommandReplacements {
|
||||
@Nullable
|
||||
private String addReplacement0(String key, String val) {
|
||||
key = ACFPatterns.PERCENTAGE.matcher(key.toLowerCase(Locale.ENGLISH)).replaceAll("");
|
||||
Pattern pattern = Pattern.compile("%" + Pattern.quote(key) + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
Pattern pattern = Pattern.compile("%\\{" + Pattern.quote(key) + "}|%" + Pattern.quote(key) + "\\b",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
Map.Entry<Pattern, String> entry = new AbstractMap.SimpleImmutableEntry<>(pattern, val);
|
||||
Map.Entry<Pattern, String> replaced = replacements.put(key, entry);
|
||||
@@ -83,8 +84,7 @@ public class CommandReplacements {
|
||||
}
|
||||
|
||||
// check for unregistered replacements
|
||||
Pattern pattern = Pattern.compile("%.[^\\s]*");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
Matcher matcher = ACFPatterns.REPLACEMENT_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
this.manager.log(LogLevel.ERROR, "Found unregistered replacement: " + matcher.group());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user