From 25116631c57115af0a3b7cb33fcddd238b34087f Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Sun, 28 Jun 2020 17:23:47 -0500 Subject: [PATCH] Allow support for #ffffff hex color codes --- .../Aust1n46/chat/utilities/Format.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MineverseChat/mineverse/Aust1n46/chat/utilities/Format.java b/MineverseChat/mineverse/Aust1n46/chat/utilities/Format.java index 531ffce..03e80cb 100644 --- a/MineverseChat/mineverse/Aust1n46/chat/utilities/Format.java +++ b/MineverseChat/mineverse/Aust1n46/chat/utilities/Format.java @@ -434,6 +434,8 @@ public class Format { allFormated = chatColorPattern.matcher(allFormated).replaceAll("\u00A7$1"); allFormated = chatHexColorPattern.matcher(allFormated).replaceAll("\u00A7$1"); allFormated = allFormated.replaceAll("%", "\\%"); + + allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated); return allFormated; } @@ -517,6 +519,20 @@ public class Format { 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) { return input.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}").replace("(", "\\(").replace(")", "\\)").replace("|", "\\|").replace("+", "\\+").replace("*", "\\*"); }