mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes:26c37d99d5create random seeds for features using SecureRandom589bf2f1bfUpgrade gson to 2.8.8 (Closes #6370)0a6103597bGet entity default attributes (#6449)40057019e0Correctly inflate villager activation bounding box (#6798)e5f9241d15Left handed API (#6775)40ee63496cAdd advancement display API (#6175)9d570042edAdd ItemFactory#getMonsterEgg API (#6772)55ca459515rename method to getSpawnEggbb397ba74cAdd critical damage API (#6275)f47aeafe00Add Horse Animation API (#5599)7a0886180fAT & Mapping fixes (#6809)5553432644docs: Update gradle instructions for Java 16 (#6811) [ci skip]a1f49e4c60Fix command suggestion leak (#6592)9472d38f3cFix method name for Critical damage (#6813)
92 lines
3.2 KiB
Diff
92 lines
3.2 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 4594701d77c5d0f744bece871b98d9f6f73eb5a7..0aa79a9fbd5861d217a877a36e985e18fba6256f 100644
|
|
--- a/src/main/java/org/bukkit/ChatColor.java
|
|
+++ b/src/main/java/org/bukkit/ChatColor.java
|
|
@@ -2,6 +2,7 @@ package org.bukkit;
|
|
|
|
import com.google.common.collect.Maps;
|
|
import java.util.Map;
|
|
+import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import org.apache.commons.lang.Validate;
|
|
import org.jetbrains.annotations.Contract;
|
|
@@ -413,4 +414,72 @@ public enum ChatColor {
|
|
BY_CHAR.put(color.code, color);
|
|
}
|
|
}
|
|
+
|
|
+ // Purpur start
|
|
+ /**
|
|
+ * Convert legacy string into a string ready to be parsed by MiniMessage
|
|
+ *
|
|
+ * @param str Legacy string
|
|
+ * @return MiniMessage ready string
|
|
+ */
|
|
+ @NotNull
|
|
+ public static String toMM(@NotNull String str) {
|
|
+ StringBuilder sb = new StringBuilder(str);
|
|
+ Matcher m = STRIP_COLOR_PATTERN.matcher(sb);
|
|
+ while (m.find()) {
|
|
+ sb.replace(m.start(), m.end(), sb.substring(m.start(), m.end()).toLowerCase());
|
|
+ }
|
|
+ return sb.toString()
|
|
+ .replace("&0", "<black>")
|
|
+ .replace("&1", "<dark_blue>")
|
|
+ .replace("&2", "<dark_green>")
|
|
+ .replace("&3", "<dark_aqua>")
|
|
+ .replace("&4", "<dark_red>")
|
|
+ .replace("&5", "<dark_purple>")
|
|
+ .replace("&6", "<gold>")
|
|
+ .replace("&7", "<grey>")
|
|
+ .replace("&8", "<dark_grey>")
|
|
+ .replace("&9", "<blue>")
|
|
+ .replace("&a", "<green>")
|
|
+ .replace("&b", "<aqua>")
|
|
+ .replace("&c", "<red>")
|
|
+ .replace("&d", "<light_purple>")
|
|
+ .replace("&e", "<yellow>")
|
|
+ .replace("&f", "<white>")
|
|
+ .replace("&k", "<obf>")
|
|
+ .replace("&l", "<b>")
|
|
+ .replace("&m", "<st>")
|
|
+ .replace("&n", "<u>")
|
|
+ .replace("&o", "<i>")
|
|
+ .replace("&r", "<r>");
|
|
+ }
|
|
+
|
|
+ @Deprecated
|
|
+ public static final Pattern HEX_PATTERN = Pattern.compile("(#[A-Fa-f0-9]{6})");
|
|
+
|
|
+ @Deprecated
|
|
+ @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;
|
|
+ }
|
|
+
|
|
+ @Deprecated
|
|
+ @Nullable
|
|
+ public static String color(@Nullable String str) {
|
|
+ return color(str, true);
|
|
+ }
|
|
+
|
|
+ @Deprecated
|
|
+ @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
|
|
}
|