From d7462c6a2dc1e1ad3294571aff079abf96870024 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Sat, 5 Oct 2024 14:04:46 +0800 Subject: [PATCH] Update TextUtils.java --- src/main/java/me/qscbm/slimefun4/utils/TextUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/qscbm/slimefun4/utils/TextUtils.java b/src/main/java/me/qscbm/slimefun4/utils/TextUtils.java index 76b5d02b2f..aec63958da 100644 --- a/src/main/java/me/qscbm/slimefun4/utils/TextUtils.java +++ b/src/main/java/me/qscbm/slimefun4/utils/TextUtils.java @@ -5,9 +5,11 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import java.util.regex.Matcher; import java.util.regex.Pattern; public class TextUtils { + private static final Pattern COLOR_PATTERN = Pattern.compile("&([\\da-zA-Z])"); private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)[§&][0-9A-FK-ORX]"); public static String toPlainText(Component component) { @@ -23,6 +25,6 @@ public static String toLegacyText(Component component) { } public static TextComponent fromText(String text) { - return LegacyComponentSerializer.legacyAmpersand().deserialize(text.replaceAll("§", "&")); + return LegacyComponentSerializer.legacyAmpersand().deserialize(COLOR_PATTERN.matcher(text).replaceAll("§$1")); } }