}
}
public JsonElement a(IChatBaseComponent ichatbasecomponent, Type type, JsonSerializationContext jsonserializationcontext) {
if (ichatbasecomponent instanceof ChatComponentText && ichatbasecomponent.getChatModifier().g() && ichatbasecomponent.a().isEmpty()) {
return new JsonPrimitive(((ChatComponentText) ichatbasecomponent).g());
} else {
JsonObject jsonobject = new JsonObject();
if (!ichatbasecomponent.getChatModifier().g()) {
this.a(ichatbasecomponent.getChatModifier(), jsonobject, jsonserializationcontext);
}
if (!ichatbasecomponent.a().isEmpty()) {
JsonArray jsonarray = new JsonArray();
Iterator iterator = ichatbasecomponent.a().iterator();
while (iterator.hasNext()) {
IChatBaseComponent ichatbasecomponent1 = (IChatBaseComponent) iterator.next();
jsonarray.add(this.a(ichatbasecomponent1, (Type) ichatbasecomponent1.getClass(), jsonserializationcontext));
}
jsonobject.add("extra", jsonarray);
}
if (ichatbasecomponent instanceof ChatComponentText) {
jsonobject.addProperty("text", ((ChatComponentText) ichatbasecomponent).g());
} else {
if (!(ichatbasecomponent instanceof ChatMessage)) {
throw new IllegalArgumentException("Don\'t know how to serialize " + ichatbasecomponent + " as a Component");
}
ChatMessage chatmessage = (ChatMessage) ichatbasecomponent;
jsonobject.addProperty("translate", chatmessage.i());
if (chatmessage.j() != null && chatmessage.j().length > 0) {
JsonArray jsonarray1 = new JsonArray();
Object[] aobject = chatmessage.j();
int i = aobject.length;
for (int j = 0; j < i; ++j) {
Object object = aobject[j];
if (object instanceof IChatBaseComponent) {
jsonarray1.add(this.a((IChatBaseComponent) object, (Type) object.getClass(), jsonserializationcontext));
} else {
jsonarray1.add(new JsonPrimitive(String.valueOf(object)));
}
}
jsonobject.add("with", jsonarray1);
}