Skip to content

Commit

Permalink
Update TextUtils.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Oct 5, 2024
1 parent 90b152f commit d7462c6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/me/qscbm/slimefun4/utils/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"));
}
}

0 comments on commit d7462c6

Please sign in to comment.