From 1de3f83083b35e6d5f4ed1ec2f4f1b2fa00bf430 Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Fri, 17 Jul 2020 19:05:52 +0200 Subject: [PATCH] Support hex colors in getLastColors (#3922) --- ...-Support-hex-colors-in-getLastColors.patch | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Spigot-API-Patches/0218-Support-hex-colors-in-getLastColors.patch diff --git a/Spigot-API-Patches/0218-Support-hex-colors-in-getLastColors.patch b/Spigot-API-Patches/0218-Support-hex-colors-in-getLastColors.patch new file mode 100644 index 000000000..a3117a437 --- /dev/null +++ b/Spigot-API-Patches/0218-Support-hex-colors-in-getLastColors.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gerrygames +Date: Thu, 16 Jul 2020 10:40:10 +0200 +Subject: [PATCH] Support hex colors in getLastColors + + +diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java +index 44d597d7a6f66a18b8037e971170ff7cea5e825f..4594701d77c5d0f744bece871b98d9f6f73eb5a7 100644 +--- a/src/main/java/org/bukkit/ChatColor.java ++++ b/src/main/java/org/bukkit/ChatColor.java +@@ -363,6 +363,7 @@ public enum ChatColor { + return new String(b); + } + ++ private static final Pattern HEX_COLOR_PATTERN = Pattern.compile(COLOR_CHAR + "x(?>" + COLOR_CHAR + "[0-9a-f]){6}", Pattern.CASE_INSENSITIVE); // Paper - Support hex colors in getLastColors + /** + * Gets the ChatColors used at the end of the given input string. + * +@@ -380,6 +381,15 @@ public enum ChatColor { + for (int index = length - 1; index > -1; index--) { + char section = input.charAt(index); + if (section == COLOR_CHAR && index < length - 1) { ++ // Paper start - Support hex colors ++ if (index > 11 && input.charAt(index - 12) == COLOR_CHAR && (input.charAt(index - 11) == 'x' || input.charAt(index - 11) == 'X')) { ++ String color = input.substring(index - 12, index + 2); ++ if (HEX_COLOR_PATTERN.matcher(color).matches()) { ++ result = color + result; ++ break; ++ } ++ } ++ // Paper end + char c = input.charAt(index + 1); + ChatColor color = getByChar(c); +