Manually wrap serialized components in an extra text component to work around a 1.9 change (Fixes #1770)

This commit is contained in:
Thinkofdeath 2016-03-01 22:47:11 +00:00
parent b6671cd00c
commit fc64a6c2ff

View File

@ -39,12 +39,17 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
public static String toString(BaseComponent component) public static String toString(BaseComponent component)
{ {
return gson.toJson( 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 ) + "]}";
} }
public static String toString(BaseComponent... components) public static String toString(BaseComponent... components)
{ {
return gson.toJson( new TextComponent( components ) ); // See above
return "{\"text\":\"\", \"extra\": [" + gson.toJson( new TextComponent( components ) ) + "]}";
} }
@Override @Override