Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #14 from SpigotMC/master
Browse files Browse the repository at this point in the history
Remove an optimization for simple components. Removes a workaround ne…
  • Loading branch information
Zartec committed Mar 17, 2016
2 parents 0b7a16d + aaddc9f commit 03488cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,12 @@ public static BaseComponent[] parse(String json)

public static String toString(BaseComponent component)
{
// 1.9 Requires the first component to not be a plain string which can
// happen if a text component has no formatting. This optimization is
// still useful when nested more so we just manually wrap everything in
// an extra text component.
return "{\"text\":\"\", \"extra\": [" + gson.toJson( component ) + "]}";
return gson.toJson( component );
}

public static String toString(BaseComponent... components)
{
// See above
return "{\"text\":\"\", \"extra\": [" + gson.toJson( new TextComponent( components ) ) + "]}";
return gson.toJson( new TextComponent( components ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
Expand All @@ -31,12 +30,11 @@ public TextComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializa
public JsonElement serialize(TextComponent src, Type typeOfSrc, JsonSerializationContext context)
{
List<BaseComponent> extra = src.getExtra();
if ( !src.hasFormatting() && ( extra == null || extra.isEmpty() ) )
JsonObject object = new JsonObject();
if ( src.hasFormatting() || ( extra != null && !extra.isEmpty() ) )
{
return new JsonPrimitive( src.getText() );
serialize( object, src, context );
}
JsonObject object = new JsonObject();
serialize( object, src, context );
object.addProperty( "text", src.getText() );
return object;
}
Expand Down

0 comments on commit 03488cd

Please sign in to comment.