From dce4ea193ad461832094f4368829e927db578265 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 1 Apr 2018 09:36:46 +1000 Subject: [PATCH] #2396: Add way to select reset color when parsing legacy chat --- .../net/md_5/bungee/api/chat/TextComponent.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java index 2f808a85..694719c8 100644 --- a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java +++ b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java @@ -28,6 +28,21 @@ public final class TextComponent extends BaseComponent * @return the components needed to print the message to the client */ public static BaseComponent[] fromLegacyText(String message) + { + return fromLegacyText( message, ChatColor.WHITE ); + } + + /** + * Converts the old formatting system that used + * {@link net.md_5.bungee.api.ChatColor#COLOR_CHAR} into the new json based + * system. + * + * @param message the text to convert + * @param defaultColor color to use when no formatting is to be applied + * (i.e. after ChatColor.RESET). + * @return the components needed to print the message to the client + */ + public static BaseComponent[] fromLegacyText(String message, ChatColor defaultColor) { ArrayList components = new ArrayList(); StringBuilder builder = new StringBuilder(); @@ -79,7 +94,7 @@ public final class TextComponent extends BaseComponent component.setObfuscated( true ); break; case RESET: - format = ChatColor.WHITE; + format = defaultColor; default: component = new TextComponent(); component.setColor( format );