Search in sources :

Example 11 with JsonObject

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;
    }
}
Also used : JsonPrimitive(net.minecraft.util.com.google.gson.JsonPrimitive) JsonObject(net.minecraft.util.com.google.gson.JsonObject)

Example 12 with JsonObject

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;
    }
}
Also used : JsonArray(net.minecraft.util.com.google.gson.JsonArray) Type(java.lang.reflect.Type) JsonPrimitive(net.minecraft.util.com.google.gson.JsonPrimitive) Iterator(java.util.Iterator) JsonObject(net.minecraft.util.com.google.gson.JsonObject) JsonObject(net.minecraft.util.com.google.gson.JsonObject)

Example 13 with 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());
        }
    }
}
Also used : Entry(java.util.Map.Entry) JsonElement(net.minecraft.util.com.google.gson.JsonElement) Iterator(java.util.Iterator) JsonObject(net.minecraft.util.com.google.gson.JsonObject)

Example 14 with JsonObject

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;
    }
}
Also used : JsonObject(net.minecraft.util.com.google.gson.JsonObject)

Aggregations

JsonObject (net.minecraft.util.com.google.gson.JsonObject)14 Iterator (java.util.Iterator)4 Entry (java.util.Map.Entry)3 UUID (java.util.UUID)3 JsonArray (net.minecraft.util.com.google.gson.JsonArray)3 JsonElement (net.minecraft.util.com.google.gson.JsonElement)3 JsonPrimitive (net.minecraft.util.com.google.gson.JsonPrimitive)2 GameProfile (net.minecraft.util.com.mojang.authlib.GameProfile)2 Constructor (java.lang.reflect.Constructor)1 Type (java.lang.reflect.Type)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 JsonParser (net.minecraft.util.com.google.gson.JsonParser)1