Skip to content

Commit

Permalink
allow uppercase letters in keybind format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 23, 2023
1 parent 558814b commit 3b58130
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -520,7 +520,7 @@ public static BaseComponent[] parseInternal(String str, ChatColor baseColor, boo
ScoreComponent component = new ScoreComponent(unescape(innardBase.get(1)), unescape(innardParts.get(0)), unescape(innardParts.get(1)));
lastText.addExtra(component);
}
else if (innardType.equals("keybind") && Utilities.matchesNamespacedKey(innardBase.get(1))) {
else if (innardType.equals("keybind") && Utilities.matchesNamespacedKeyButCaseInsensitive(innardBase.get(1))) {
KeybindComponent component = new KeybindComponent();
component.setKeybind(unescape(innardBase.get(1)));
lastText.addExtra(component);
Expand Down
Expand Up @@ -54,6 +54,16 @@ public static String namespacedKeyToString(NamespacedKey key) {
return key.getNamespace().equals(NamespacedKey.MINECRAFT) ? key.getKey() : key.toString();
}

public static boolean matchesNamespacedKeyButCaseInsensitive(String input) {
int colonIndex = input.indexOf(':');
if (colonIndex == -1) {
return namespaceMatcherButCaseInsensitive.isOnlyMatches(input);
}
return namespaceMatcherButCaseInsensitive.isOnlyMatches(input.substring(0, colonIndex)) && namespaceMatcherButCaseInsensitive.isOnlyMatches(input.substring(colonIndex + 1));
}

public static AsciiMatcher namespaceMatcherButCaseInsensitive = new AsciiMatcher(AsciiMatcher.LETTERS_LOWER + AsciiMatcher.LETTERS_UPPER + ".-_/" + AsciiMatcher.DIGITS);

public static boolean matchesNamespacedKey(String input) {
int colonIndex = input.indexOf(':');
if (colonIndex == -1) {
Expand Down

0 comments on commit 3b58130

Please sign in to comment.