Allow support for #ffffff hex color codes

This commit is contained in:
Aust1n46 2020-06-28 17:23:47 -05:00
parent 3d13056eea
commit 25116631c5

View File

@ -434,6 +434,8 @@ public class Format {
allFormated = chatColorPattern.matcher(allFormated).replaceAll("\u00A7$1"); allFormated = chatColorPattern.matcher(allFormated).replaceAll("\u00A7$1");
allFormated = chatHexColorPattern.matcher(allFormated).replaceAll("\u00A7$1"); allFormated = chatHexColorPattern.matcher(allFormated).replaceAll("\u00A7$1");
allFormated = allFormated.replaceAll("%", "\\%"); allFormated = allFormated.replaceAll("%", "\\%");
allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated);
return allFormated; return allFormated;
} }
@ -517,6 +519,20 @@ public class Format {
return bukkitColorCode.toString(); return bukkitColorCode.toString();
} }
public static String convertHexColorCodeStringToBukkitColorCodeString(String string) {
Pattern pattern = Pattern.compile("(#[0-9a-fA-F]{6})");
Matcher matcher = pattern.matcher(string);
while(matcher.find()) {
int indexStart = matcher.start();
int indexEnd = matcher.end();
String hexColor = string.substring(indexStart, indexEnd);
String bukkitColor = convertHexColorCodeToBukkitColorCode(hexColor);
string = string.replaceAll(hexColor, bukkitColor);
matcher.reset(string);
}
return string;
}
public static String escapeAllRegex(String input) { public static String escapeAllRegex(String input) {
return input.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}").replace("(", "\\(").replace(")", "\\)").replace("|", "\\|").replace("+", "\\+").replace("*", "\\*"); return input.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}").replace("(", "\\(").replace(")", "\\)").replace("|", "\\|").replace("+", "\\+").replace("*", "\\*");
} }