Fix formatting leaking through components when arrays are used + cases where component's extra wouldn't serialize

This commit is contained in:
Thinkofdeath 2014-01-26 00:37:33 +00:00
parent 5f7963b0c4
commit 83b0229277
3 changed files with 16 additions and 3 deletions

View File

@ -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() );
}
}

View File

@ -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)
{

View File

@ -43,7 +43,7 @@ public class ComponentSerializer implements JsonSerializer<BaseComponent>, JsonD
public static String toString(BaseComponent... components)
{
return gson.toJson( components );
return gson.toJson( new TextComponent( components ) );
}
@Override