use of net.minecraft.util.com.google.gson.JsonObject in project mc-dev by Bukkit.
the class ChatModifierSerializer method a.
public ChatModifier a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) {
if (jsonelement.isJsonObject()) {
ChatModifier chatmodifier = new ChatModifier();
JsonObject jsonobject = jsonelement.getAsJsonObject();
if (jsonobject == null) {
return null;
} else {
if (jsonobject.has("bold")) {
ChatModifier.a(chatmodifier, Boolean.valueOf(jsonobject.get("bold").getAsBoolean()));
}
if (jsonobject.has("italic")) {
ChatModifier.b(chatmodifier, Boolean.valueOf(jsonobject.get("italic").getAsBoolean()));
}
if (jsonobject.has("underlined")) {
ChatModifier.c(chatmodifier, Boolean.valueOf(jsonobject.get("underlined").getAsBoolean()));
}
if (jsonobject.has("strikethrough")) {
ChatModifier.d(chatmodifier, Boolean.valueOf(jsonobject.get("strikethrough").getAsBoolean()));
}
if (jsonobject.has("obfuscated")) {
ChatModifier.e(chatmodifier, Boolean.valueOf(jsonobject.get("obfuscated").getAsBoolean()));
}
if (jsonobject.has("color")) {
ChatModifier.a(chatmodifier, (EnumChatFormat) jsondeserializationcontext.deserialize(jsonobject.get("color"), EnumChatFormat.class));
}
JsonObject jsonobject1;
JsonPrimitive jsonprimitive;
if (jsonobject.has("clickEvent")) {
jsonobject1 = jsonobject.getAsJsonObject("clickEvent");
if (jsonobject1 != null) {
jsonprimitive = jsonobject1.getAsJsonPrimitive("action");
EnumClickAction enumclickaction = jsonprimitive == null ? null : EnumClickAction.a(jsonprimitive.getAsString());
JsonPrimitive jsonprimitive1 = jsonobject1.getAsJsonPrimitive("value");
String s = jsonprimitive1 == null ? null : jsonprimitive1.getAsString();
if (enumclickaction != null && s != null && enumclickaction.a()) {
ChatModifier.a(chatmodifier, new ChatClickable(enumclickaction, s));
}
}
}
if (jsonobject.has("hoverEvent")) {
jsonobject1 = jsonobject.getAsJsonObject("hoverEvent");
if (jsonobject1 != null) {
jsonprimitive = jsonobject1.getAsJsonPrimitive("action");
EnumHoverAction enumhoveraction = jsonprimitive == null ? null : EnumHoverAction.a(jsonprimitive.getAsString());
IChatBaseComponent ichatbasecomponent = (IChatBaseComponent) jsondeserializationcontext.deserialize(jsonobject1.get("value"), IChatBaseComponent.class);
if (enumhoveraction != null && ichatbasecomponent != null && enumhoveraction.a()) {
ChatModifier.a(chatmodifier, new ChatHoverable(enumhoveraction, ichatbasecomponent));
}
}
}
return chatmodifier;
}
} else {
return null;
}
}
use of net.minecraft.util.com.google.gson.JsonObject in project mc-dev by Bukkit.
the class ChatSerializer method a.
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);
}
}
return jsonobject;
}
}
use of net.minecraft.util.com.google.gson.JsonObject in project mc-dev by Bukkit.
the class ChatSerializer method a.
private void a(ChatModifier chatmodifier, JsonObject jsonobject, JsonSerializationContext jsonserializationcontext) {
JsonElement jsonelement = jsonserializationcontext.serialize(chatmodifier);
if (jsonelement.isJsonObject()) {
JsonObject jsonobject1 = (JsonObject) jsonelement;
Iterator iterator = jsonobject1.entrySet().iterator();
while (iterator.hasNext()) {
Entry entry = (Entry) iterator.next();
jsonobject.add((String) entry.getKey(), (JsonElement) entry.getValue());
}
}
}
use of net.minecraft.util.com.google.gson.JsonObject in project mc-dev by Bukkit.
the class JsonListEntrySerializer method a.
public JsonListEntry a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) {
if (jsonelement.isJsonObject()) {
JsonObject jsonobject = jsonelement.getAsJsonObject();
JsonListEntry jsonlistentry = this.a.a(jsonobject);
return jsonlistentry;
} else {
return null;
}
}
Aggregations