-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
Colorizer.java
31 lines (24 loc) · 935 Bytes
/
Colorizer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package net.aufdemrand.denizen.utilities.command.messaging;
import org.bukkit.ChatColor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Colorizer {
public static String parseColors(String parsed) {
Matcher matcher = COLOR_MATCHER.matcher(ChatColor.translateAlternateColorCodes('&', parsed));
return matcher.replaceAll(GROUP);
}
public static String stripColors(String parsed) {
Matcher matcher = COLOR_MATCHER.matcher(parsed);
return matcher.replaceAll("");
}
private static Pattern COLOR_MATCHER;
private static String GROUP = ChatColor.COLOR_CHAR + "$1";
static {
String colors = "<([";
for (ChatColor color : ChatColor.values()) {
colors += color.getChar();
}
colors += "])>";
COLOR_MATCHER = Pattern.compile(colors, Pattern.CASE_INSENSITIVE);
}
}