From 83b0229277b8b1f6e813caa04f7957c66576cc0c Mon Sep 17 00:00:00 2001 From: Thinkofdeath Date: Sun, 26 Jan 2014 00:37:33 +0000 Subject: [PATCH] Fix formatting leaking through components when arrays are used + cases where component's extra wouldn't serialize --- .../java/net/md_5/bungee/api/chat/BaseComponent.java | 5 +++-- .../java/net/md_5/bungee/api/chat/TextComponent.java | 12 ++++++++++++ .../net/md_5/bungee/chat/ComponentSerializer.java | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java index aeef2c74..a0436cce 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java @@ -323,7 +323,8 @@ public abstract class BaseComponent return color != null || bold != null || italic != null || underlined != null || strikethrough != null || obfuscated != null - || hoverEvent != null || clickEvent != null; + || hoverEvent != null || clickEvent != null + || (extra != null && extra.size() > 0); } /** @@ -376,6 +377,6 @@ public abstract class BaseComponent @Override public String toString() { - return String.format( "BaseComponent{color=%s, bold=%b, italic=%b, underlined=%b, strikethrough=%b, obfuscated=%b, clickEvent=%s, hoverEvent=%s}", getColor().getName(), isBold(), isItalic(), isUnderlined(), isStrikethrough(), isObfuscated(), getClickEvent(), getHoverEvent() ); + return String.format( "BaseComponent{color=%s, bold=%b, italic=%b, underlined=%b, strikethrough=%b, obfuscated=%b, clickEvent=%s, hoverEvent=%s, extra=%s}", getColor().getName(), isBold(), isItalic(), isUnderlined(), isStrikethrough(), isObfuscated(), getClickEvent(), getHoverEvent(), getExtra() ); } } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java index 10b43910..529ea2bb 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java @@ -7,6 +7,7 @@ import lombok.Setter; import net.md_5.bungee.api.ChatColor; import java.util.ArrayList; +import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -142,6 +143,17 @@ public class TextComponent extends BaseComponent setText( textComponent.getText() ); } + /** + * Creates a TextComponent with blank text and the extras set + * to the passed array + * + * @param extras the extras to set + */ + public TextComponent(BaseComponent ...extras) { + setText( "" ); + setExtra( Arrays.asList(extras) ); + } + @Override protected void toPlainText(StringBuilder builder) { diff --git a/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java b/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java index 3c9df139..d097d408 100644 --- a/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java +++ b/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java @@ -43,7 +43,7 @@ public class ComponentSerializer implements JsonSerializer, JsonD public static String toString(BaseComponent... components) { - return gson.toJson( components ); + return gson.toJson( new TextComponent( components ) ); } @Override