mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Update to 1.16.2
This commit is contained in:
41
patches/api/0028-ChatColor-conveniences.patch
Normal file
41
patches/api/0028-ChatColor-conveniences.patch
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user