From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Fri, 10 Jul 2020 12:43:25 -0500
Subject: [PATCH] ChatColor conveniences


diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java
index 4594701d77c5d0f744bece871b98d9f6f73eb5a7..499b222dee1f11d497a29a9a263a5596401ca1eb 100644
--- a/src/main/java/org/bukkit/ChatColor.java
+++ b/src/main/java/org/bukkit/ChatColor.java
@@ -413,4 +413,30 @@ public enum ChatColor {
             BY_CHAR.put(color.code, color);
         }
     }
+
+    // Purpur start
+    public static final Pattern HEX_PATTERN = Pattern.compile("(#[A-Fa-f0-9]{6})");
+
+    @Nullable
+    public static String replaceHex(@Nullable String str) {
+        if (str != null) {
+            java.util.regex.Matcher matcher = HEX_PATTERN.matcher(str);
+            while (matcher.find()) {
+                String group = matcher.group(1);
+                str = str.replace(group, net.md_5.bungee.api.ChatColor.of(group).toString());
+            }
+        }
+        return str;
+    }
+
+    @Nullable
+    public static String color(@Nullable String str) {
+        return color(str, true);
+    }
+
+    @Nullable
+    public static String color(@Nullable String str, boolean parseHex) {
+        return str != null ? net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', parseHex ? replaceHex(str) : str) : str;
+    }
+    // Purpur end
 }
