From 0db18eade862f7d633038b0ab24d674a7210fb4e Mon Sep 17 00:00:00 2001 From: AlessioDP Date: Tue, 25 Aug 2020 02:15:46 +0200 Subject: [PATCH] Color HEX support for ConfigUtil (#1379) * Added HEX support to ConfigUtil --- .../java/me/blackvein/quests/util/ConfigUtil.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main/src/main/java/me/blackvein/quests/util/ConfigUtil.java b/main/src/main/java/me/blackvein/quests/util/ConfigUtil.java index b87810f47..b288ce7f8 100644 --- a/main/src/main/java/me/blackvein/quests/util/ConfigUtil.java +++ b/main/src/main/java/me/blackvein/quests/util/ConfigUtil.java @@ -14,6 +14,8 @@ package me.blackvein.quests.util; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -188,6 +190,17 @@ public class ConfigUtil { parsed = parsed.replace("", ChatColor.RESET.toString()); parsed = parsed.replace("
", "\n"); parsed = ChatColor.translateAlternateColorCodes('&', parsed); + + Matcher matcher = Pattern.compile("(?i)<#([0-9A-F]{6})>").matcher(parsed); + while (matcher.find()) { + StringBuilder hex = new StringBuilder(); + hex.append(ChatColor.COLOR_CHAR + "x"); + char[] chars = matcher.group(1).toCharArray(); + for (int index = 0; index < chars.length; index++) { + hex.append(ChatColor.COLOR_CHAR).append(Character.toLowerCase(chars[index])); + } + parsed = parsed.replace(matcher.group(), hex.toString()); + } return parsed; } }