Search in sources :

Example 1 with JsonObject

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

the class ServerPingPlayerSampleSerializer method a.

public JsonElement a(ServerPingPlayerSample serverpingplayersample, Type type, JsonSerializationContext jsonserializationcontext) {
    JsonObject jsonobject = new JsonObject();
    jsonobject.addProperty("max", Integer.valueOf(serverpingplayersample.a()));
    jsonobject.addProperty("online", Integer.valueOf(serverpingplayersample.b()));
    if (serverpingplayersample.c() != null && serverpingplayersample.c().length > 0) {
        JsonArray jsonarray = new JsonArray();
        for (int i = 0; i < serverpingplayersample.c().length; ++i) {
            JsonObject jsonobject1 = new JsonObject();
            UUID uuid = serverpingplayersample.c()[i].getId();
            jsonobject1.addProperty("id", uuid == null ? "" : uuid.toString());
            jsonobject1.addProperty("name", serverpingplayersample.c()[i].getName());
            jsonarray.add(jsonobject1);
        }
        jsonobject.add("sample", jsonarray);
    }
    return jsonobject;
}
Also used : JsonArray(net.minecraft.util.com.google.gson.JsonArray) JsonObject(net.minecraft.util.com.google.gson.JsonObject) UUID(java.util.UUID)

Example 2 with JsonObject

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

the class ServerPingServerDataSerializer method a.

public JsonElement a(ServerPingServerData serverpingserverdata, Type type, JsonSerializationContext jsonserializationcontext) {
    JsonObject jsonobject = new JsonObject();
    jsonobject.addProperty("name", serverpingserverdata.a());
    jsonobject.addProperty("protocol", Integer.valueOf(serverpingserverdata.b()));
    return jsonobject;
}
Also used : JsonObject(net.minecraft.util.com.google.gson.JsonObject)

Example 3 with JsonObject

use of net.minecraft.util.com.google.gson.JsonObject 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 4 with JsonObject

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

the class ServerStatisticManager method a.

public static String a(Map map) {
    JsonObject jsonobject = new JsonObject();
    Iterator iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry entry = (Entry) iterator.next();
        if (((StatisticWrapper) entry.getValue()).b() != null) {
            JsonObject jsonobject1 = new JsonObject();
            jsonobject1.addProperty("value", Integer.valueOf(((StatisticWrapper) entry.getValue()).a()));
            try {
                jsonobject1.add("progress", ((StatisticWrapper) entry.getValue()).b().a());
            } catch (Throwable throwable) {
                b.warn("Couldn\'t save statistic " + ((Statistic) entry.getKey()).e() + ": error serializing progress", throwable);
            }
            jsonobject.add(((Statistic) entry.getKey()).name, jsonobject1);
        } else {
            jsonobject.addProperty(((Statistic) entry.getKey()).name, Integer.valueOf(((StatisticWrapper) entry.getValue()).a()));
        }
    }
    return jsonobject.toString();
}
Also used : Entry(java.util.Map.Entry) Iterator(java.util.Iterator) JsonObject(net.minecraft.util.com.google.gson.JsonObject)

Example 5 with JsonObject

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

the class JsonListEntrySerializer method a.

public JsonElement a(JsonListEntry jsonlistentry, Type type, JsonSerializationContext jsonserializationcontext) {
    JsonObject jsonobject = new JsonObject();
    jsonlistentry.a(jsonobject);
    return jsonobject;
}
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