mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 03:25:13 +01:00
Slower, but more correct
This commit is contained in:
parent
51bfe23f98
commit
6f8c4a7e58
@ -66,15 +66,11 @@ public class StringHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String parseColors(String parsed) {
|
public static String parseColors(String parsed) {
|
||||||
Matcher matcher = COLOR_MATCHER.matcher(parsed);
|
Matcher matcher = COLOR_MATCHER.matcher(ChatColor.translateAlternateColorCodes('&', parsed));
|
||||||
if (!matcher.matches())
|
return matcher.replaceAll(GROUP);
|
||||||
return parsed;
|
|
||||||
String replace = matcher.group(1) != null ? GROUP_1 : GROUP_2;
|
|
||||||
return matcher.replaceAll(replace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String GROUP_1 = ChatColor.COLOR_CHAR + "$1";
|
private static String GROUP = ChatColor.COLOR_CHAR + "$1";
|
||||||
private static String GROUP_2 = ChatColor.COLOR_CHAR + "$2";
|
|
||||||
|
|
||||||
public static String wrap(Object string) {
|
public static String wrap(Object string) {
|
||||||
return wrap(string, parseColors(Setting.MESSAGE_COLOUR.asString()));
|
return wrap(string, parseColors(Setting.MESSAGE_COLOUR.asString()));
|
||||||
@ -97,7 +93,7 @@ public class StringHelper {
|
|||||||
String colors = "";
|
String colors = "";
|
||||||
for (ChatColor color : ChatColor.values())
|
for (ChatColor color : ChatColor.values())
|
||||||
colors += color.getChar();
|
colors += color.getChar();
|
||||||
COLOR_MATCHER = Pattern.compile("&([COLORS])|<([COLORS])>".replace("COLORS", colors),
|
COLOR_MATCHER = Pattern.compile("\\<([COLORS])\\>".replace("COLORS", colors),
|
||||||
Pattern.CASE_INSENSITIVE);
|
Pattern.CASE_INSENSITIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user