Files
Purpur/patches/api/0030-ChatColor-conveniences.patch
William Blake Galbreath ee5fe2fbdc Updated Upstream (Paper)
Upstream has released updates that appears to apply and compile correctly

Paper Changes:
108efeee Fix zero reputation deleting villagers (#3857)
7db30ebd Use consistent priorities for light tasks
1de3f830 Support hex colors in getLastColors (#3922)
018d8602 Fix SPIGOT-5989 (#3920)
45909954 Fix moveToWorld worldserver reference (#3929)
9c16c413 [Auto] Updated Upstream (CraftBukkit)
45ffc2bf Move range check for block placing up (#3917)
2020-07-17 14:56:51 -05:00

42 lines
1.4 KiB
Diff

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 4594701d..499b222d 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
}