Search in sources :

Example 1 with JsonElement

use of net.minecraft.util.com.google.gson.JsonElement in project mc-dev by Bukkit.

the class ServerStatisticManager method a.

public Map a(String s) {
    JsonElement jsonelement = (new JsonParser()).parse(s);
    if (!jsonelement.isJsonObject()) {
        return Maps.newHashMap();
    } else {
        JsonObject jsonobject = jsonelement.getAsJsonObject();
        HashMap hashmap = Maps.newHashMap();
        Iterator iterator = jsonobject.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry entry = (Entry) iterator.next();
            Statistic statistic = StatisticList.getStatistic((String) entry.getKey());
            if (statistic != null) {
                StatisticWrapper statisticwrapper = new StatisticWrapper();
                if (((JsonElement) entry.getValue()).isJsonPrimitive() && ((JsonElement) entry.getValue()).getAsJsonPrimitive().isNumber()) {
                    statisticwrapper.a(((JsonElement) entry.getValue()).getAsInt());
                } else if (((JsonElement) entry.getValue()).isJsonObject()) {
                    JsonObject jsonobject1 = ((JsonElement) entry.getValue()).getAsJsonObject();
                    if (jsonobject1.has("value") && jsonobject1.get("value").isJsonPrimitive() && jsonobject1.get("value").getAsJsonPrimitive().isNumber()) {
                        statisticwrapper.a(jsonobject1.getAsJsonPrimitive("value").getAsInt());
                    }
                    if (jsonobject1.has("progress") && statistic.l() != null) {
                        try {
                            Constructor constructor = statistic.l().getConstructor(new Class[0]);
                            IJsonStatistic ijsonstatistic = (IJsonStatistic) constructor.newInstance(new Object[0]);
                            ijsonstatistic.a(jsonobject1.get("progress"));
                            statisticwrapper.a(ijsonstatistic);
                        } catch (Throwable throwable) {
                            b.warn("Invalid statistic progress in " + this.d, throwable);
                        }
                    }
                }
                hashmap.put(statistic, statisticwrapper);
            } else {
                b.warn("Invalid statistic in " + this.d + ": Don\'t know what " + (String) entry.getKey() + " is");
            }
        }
        return hashmap;
    }
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) JsonElement(net.minecraft.util.com.google.gson.JsonElement) Constructor(java.lang.reflect.Constructor) Iterator(java.util.Iterator) JsonObject(net.minecraft.util.com.google.gson.JsonObject) JsonParser(net.minecraft.util.com.google.gson.JsonParser)

Example 2 with JsonElement

use of net.minecraft.util.com.google.gson.JsonElement in project mc-dev by Bukkit.

the class BanEntrySerializer method a.

public UserCacheEntry a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) {
    if (jsonelement.isJsonObject()) {
        JsonObject jsonobject = jsonelement.getAsJsonObject();
        JsonElement jsonelement1 = jsonobject.get("name");
        JsonElement jsonelement2 = jsonobject.get("uuid");
        JsonElement jsonelement3 = jsonobject.get("expiresOn");
        if (jsonelement1 != null && jsonelement2 != null) {
            String s = jsonelement2.getAsString();
            String s1 = jsonelement1.getAsString();
            Date date = null;
            if (jsonelement3 != null) {
                try {
                    date = UserCache.a.parse(jsonelement3.getAsString());
                } catch (ParseException parseexception) {
                    date = null;
                }
            }
            if (s1 != null && s != null) {
                UUID uuid;
                try {
                    uuid = UUID.fromString(s);
                } catch (Throwable throwable) {
                    return null;
                }
                UserCacheEntry usercacheentry = new UserCacheEntry(this.a, new GameProfile(uuid, s1), date, (GameProfileLookup) null);
                return usercacheentry;
            } else {
                return null;
            }
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : GameProfile(net.minecraft.util.com.mojang.authlib.GameProfile) JsonElement(net.minecraft.util.com.google.gson.JsonElement) JsonObject(net.minecraft.util.com.google.gson.JsonObject) ParseException(java.text.ParseException) UUID(java.util.UUID) Date(java.util.Date)

Example 3 with JsonElement

use of net.minecraft.util.com.google.gson.JsonElement in project mc-dev by Bukkit.

the class AchievementSet method a.

public void a(JsonElement jsonelement) {
    if (jsonelement.isJsonArray()) {
        Iterator iterator = jsonelement.getAsJsonArray().iterator();
        while (iterator.hasNext()) {
            JsonElement jsonelement1 = (JsonElement) iterator.next();
            this.add(jsonelement1.getAsString());
        }
    }
}
Also used : JsonElement(net.minecraft.util.com.google.gson.JsonElement) Iterator(java.util.Iterator)

Example 4 with JsonElement

use of net.minecraft.util.com.google.gson.JsonElement 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)

Aggregations

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