From 967b9f2ce37601ab7f9424048547c192d4771b7f Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 22 Aug 2020 19:48:25 +0200 Subject: [PATCH] Fix hologram for hex colored item names --- .../de/epiceric/shopchest/nms/JsonBuilder.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java b/src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java index 1cfe7ae..0079d7c 100644 --- a/src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java +++ b/src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java @@ -109,7 +109,8 @@ public class JsonBuilder { } } - private static final Pattern PART_PATTERN = Pattern.compile("(([§][a-fA-Fk-oK-OrR0-9])+)([^§]*)"); + private static final Pattern PART_PATTERN = Pattern.compile("((§(?:[a-fA-Fk-oK-OrR0-9]|#[a-fA-F0-9]{6}))+)([^§]*)"); + private static final Pattern HEX_PATTERN = Pattern.compile("(§[a-fA-F0-9]){6}"); private Part rootPart; private ShopChest plugin; @@ -145,6 +146,12 @@ public class JsonBuilder { } public static Part parse(String text) { + Matcher hexMatcher = HEX_PATTERN.matcher(text); + while (hexMatcher.find()) { + String hexCode = hexMatcher.group(0).replace("§", ""); + text = text.replace(hexMatcher.group(0), "§#" + hexCode); + } + Matcher matcher = PART_PATTERN.matcher(text); if (!matcher.find()) { @@ -200,7 +207,11 @@ public class JsonBuilder { part.removeValue("color"); break; default: - part.setValue("color", new Part(ChatColor.getByChar(f).name().toLowerCase())); + if (f.startsWith("#")) { + part.setValue("color", new Part(f)); + } else { + part.setValue("color", new Part(ChatColor.getByChar(f).name().toLowerCase())); + } } }