Slower, but more correct

This commit is contained in:
fullwall 2012-12-02 18:22:25 +08:00
parent 93378504ba
commit fda23a1b47
1 changed files with 4 additions and 8 deletions

View File

@ -66,15 +66,11 @@ public class StringHelper {
}
public static String parseColors(String parsed) {
Matcher matcher = COLOR_MATCHER.matcher(parsed);
if (!matcher.matches())
return parsed;
String replace = matcher.group(1) != null ? GROUP_1 : GROUP_2;
return matcher.replaceAll(replace);
Matcher matcher = COLOR_MATCHER.matcher(ChatColor.translateAlternateColorCodes('&', parsed));
return matcher.replaceAll(GROUP);
}
private static String GROUP_1 = ChatColor.COLOR_CHAR + "$1";
private static String GROUP_2 = ChatColor.COLOR_CHAR + "$2";
private static String GROUP = ChatColor.COLOR_CHAR + "$1";
public static String wrap(Object string) {
return wrap(string, parseColors(Setting.MESSAGE_COLOUR.asString()));
@ -97,7 +93,7 @@ public class StringHelper {
String colors = "";
for (ChatColor color : ChatColor.values())
colors += color.getChar();
COLOR_MATCHER = Pattern.compile("&([COLORS])|<([COLORS])>".replace("COLORS", colors),
COLOR_MATCHER = Pattern.compile("\\<([COLORS])\\>".replace("COLORS", colors),
Pattern.CASE_INSENSITIVE);
}
}