Java Code Examples for com.google.gson.JsonArray.get()

The following are Jave code examples for showing how to use get() of the com.google.gson.JsonArray class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: CustomWorldGen   File: ForgeBlockStateV1.java   View Source Code Vote up 8 votes
public static float[] parseFloatArray(JsonElement e, int length, String prefix)
{
    if (!e.isJsonArray()) throw new JsonParseException(prefix + ": expected an array, got: " + e);
    JsonArray t = e.getAsJsonArray();
    if (t.size() != length) throw new JsonParseException(prefix + ": expected an array of length " + length + ", got: " + t.size());
    float[] ret = new float[length];
    for (int i = 0; i < length; i++)
    {
        try
        {
            ret[i] = t.get(i).getAsNumber().floatValue();
        }
        catch (ClassCastException ex)
        {
            throw new JsonParseException(prefix + " element: expected number, got: " + t.get(i));
        }
    }
    return ret;
}
 
Example 2
Project: smart_commuter   File: GoogleGeocodeSync.java   View Source Code Vote up 6 votes
public String parseAddress(String result){
    JsonParser parser = new JsonParser();
    JsonObject json = (JsonObject) parser.parse(result);

    JsonElement jsonCode = json.get("status");
    String code = jsonCode.getAsString();
    if(! (code.equals("OK"))){
        return null;
    }

    JsonArray jsonArray = json.getAsJsonArray("results");
    JsonElement elm = jsonArray.get(0);
    JsonObject obj = elm.getAsJsonObject();
    JsonElement ob2 = obj.get("formatted_address");
    return ob2.getAsString();
}
 
Example 3
Project: smart_commuter   File: GoogleGeocodeSync.java   View Source Code Vote up 6 votes
public LocationDTO parseLocation(String result){
    JsonParser parser = new JsonParser();
    JsonObject json = (JsonObject) parser.parse(result);

    JsonElement jsonCode = json.get("status");
    String code = jsonCode.getAsString();
    if(! (code.equals("OK"))){
        return null;
    }

    JsonArray jsonArray = json.getAsJsonArray("results");
    JsonElement elm = jsonArray.get(0);
    JsonObject obj = elm.getAsJsonObject();
    JsonObject ob2 = obj.getAsJsonObject("geometry");
    JsonObject obj3 = ob2.getAsJsonObject("location");
    String jsonString = obj3.toString();

    Gson gson = new GsonBuilder().create();
    LocationDTO loc = gson.fromJson(jsonString, LocationDTO.class);

    return loc;
}
 
Example 4
Project: Hub   File: BumperManager.java   View Source Code Vote up 6 votes
@Override
public void loadConfiguration(JsonArray rootJson)
{
    for (int i = 0; i < rootJson.size(); i++)
    {
        JsonElement jsonBumber = rootJson.get(i);

        Bumper bumper = null;

        try
        {
            bumper = new Bumper(this.hub, jsonBumber.getAsString());
        }
        catch (Exception ignored) {}

        if (bumper != null)
        {
            this.interactions.add(bumper);
            this.log(Level.INFO, "Registered bumper at '" + jsonBumber.getAsString());
        }
    }
}
 
Example 5
Project: diorite-configs-java8   File: JsonDeserializationData.java   View Source Code Vote up 6 votes
@Nullable
private JsonElement getElement(JsonElement element, String key)
{
    if (key.isEmpty())
    {
        return element;
    }
    if (element.isJsonArray())
    {
        JsonArray jsonArray = element.getAsJsonArray();
        int i = DioriteMathUtils.asInt(key, - 1);
        if ((i == - 1) || (i < jsonArray.size()))
        {
            return null;
        }
        return jsonArray.get(i);
    }
    if (element.isJsonObject())
    {
        return element.getAsJsonObject().get(key);
    }
    return null;
}
 
Example 6
Project: PackagePlugin   File: MainFrame.java   View Source Code Vote up 6 votes
private void analysisJsonStr(StringBuilder sb, Object json) {
    LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
    Object jo = json;
    if (jo instanceof JsonObject) {
        FileUtil.analysisJson(map, (JsonObject) jo, "");
    } else if (jo instanceof JsonArray) {
        JsonArray ja = (JsonArray) jo;
        Object subjo = ja.get(0);
        if (subjo instanceof JsonObject) {
            FileUtil.analysisJson(map, (JsonObject) subjo, "");
        }
    } else {
        sb.append("**result有误").append(jo);
    }
    analysisMap(map, sb, "");
}
 
Example 7
Project: Backmemed   File: SoundListSerializer.java   View Source Code Vote up 6 votes
private List<Sound> deserializeSounds(JsonObject object)
{
    List<Sound> list = Lists.<Sound>newArrayList();

    if (object.has("sounds"))
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(object, "sounds");

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonElement jsonelement = jsonarray.get(i);

            if (JsonUtils.isString(jsonelement))
            {
                String s = JsonUtils.getString(jsonelement, "sound");
                list.add(new Sound(s, 1.0F, 1.0F, 1, Sound.Type.FILE, false));
            }
            else
            {
                list.add(this.deserializeSound(JsonUtils.getJsonObject(jsonelement, "sound")));
            }
        }
    }

    return list;
}
 
Example 8
Project: vavr-gson   File: OptionConverter.java   View Source Code Vote up 6 votes
@Override
Option<?> fromJsonArray(JsonArray arr, Type type, Type[] subTypes, JsonDeserializationContext ctx) throws JsonParseException {
    if (arr.size() < 1 || arr.size() > 2) {
        throw new JsonParseException("bad json format");
    }
    String status = arr.get(0).getAsString();
    if ("defined".equals(status)) {
        if (arr.size() == 2) {
            Object el = subTypes.length > 0 ? ctx.deserialize(arr.get(1), subTypes[0]) : arr.get(1);
            return Option.some(el);
        } else {
            throw new JsonParseException("expected array size: 2");
        }
    } else {
        return Option.none();
    }
}
 
Example 9
Project: fingerblox   File: ImageDisplayActivity.java   View Source Code Vote up 5 votes
public static MatOfKeyPoint jsonToKeypoints(String json){
    MatOfKeyPoint result = new MatOfKeyPoint();

    JsonParser parser = new JsonParser();
    JsonArray jsonArr = parser.parse(json).getAsJsonArray();

    int size = jsonArr.size();

    KeyPoint[] kpArray = new KeyPoint[size];

    for(int i=0; i<size; i++){
        KeyPoint kp = new KeyPoint();

        JsonObject obj = (JsonObject) jsonArr.get(i);

        kp.pt = new Point(
                obj.get("x").getAsDouble(),
                obj.get("y").getAsDouble()
        );
        kp.class_id = obj.get("class_id").getAsInt();
        kp.size = obj.get("size").getAsFloat();
        kp.angle = obj.get("angle").getAsFloat();
        kp.octave = obj.get("octave").getAsInt();
        kp.response = obj.get("response").getAsFloat();

        kpArray[i] = kp;
    }

    result.fromArray(kpArray);

    return result;
}
 
Example 10
Project: vavr-gson   File: TupleConverter.java   View Source Code Vote up 5 votes
@Override
Tuple fromJsonArray(JsonArray json, Type type, Type[] subTypes, JsonDeserializationContext ctx) {
    if (subTypes.length > 0 && json.size() != subTypes.length) {
        throw new JsonParseException("elements expected: " + subTypes.length);
    }
    Object[] arr = new Object[json.size()];
    for (int i = 0; i < json.size(); i++) {
        JsonElement el = json.get(i);
        arr[i] = subTypes.length > 0 ? ctx.deserialize(el, subTypes[i]) : el;
    }
    switch (json.size()) {
        case 0:
            return Tuple0.instance();
        case 1:
            return Tuple.of(arr[0]);
        case 2:
            return Tuple.of(arr[0], arr[1]);
        case 3:
            return Tuple.of(arr[0], arr[1], arr[2]);
        case 4:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3]);
        case 5:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4]);
        case 6:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]);
        case 7:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6]);
        case 8:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7]);
        default:
            throw new JsonParseException("bad tuple arity");
    }
}
 
Example 11
Project: zooracle   File: OpenCVUtils.java   View Source Code Vote up 5 votes
public static MatOfKeyPoint keypointsFromJson(String json){
    MatOfKeyPoint result = new MatOfKeyPoint();

    JsonParser parser = new JsonParser();
    JsonArray jsonArr = parser.parse(json).getAsJsonArray();        

    int size = jsonArr.size();

    KeyPoint[] kpArray = new KeyPoint[size];

    for(int i=0; i<size; i++){
        KeyPoint kp = new KeyPoint(); 

        JsonObject obj = (JsonObject) jsonArr.get(i);

        Point point = new Point( 
                obj.get("x").getAsDouble(), 
                obj.get("y").getAsDouble() 
        );          

        kp.pt       = point;
        kp.class_id = obj.get("class_id").getAsInt();
        kp.size     =     obj.get("size").getAsFloat();
        kp.angle    =    obj.get("angle").getAsFloat();
        kp.octave   =   obj.get("octave").getAsInt();
        kp.response = obj.get("response").getAsFloat();

        kpArray[i] = kp;
    }

    result.fromArray(kpArray);

    return result;
}
 
Example 12
Project: Backmemed   File: CustomEntityModelParser.java   View Source Code Vote up 5 votes
public static CustomEntityRenderer parseEntityRender(JsonObject obj, String path)
{
    ConnectedParser connectedparser = new ConnectedParser("CustomEntityModels");
    String s = connectedparser.parseName(path);
    String s1 = connectedparser.parseBasePath(path);
    String s2 = Json.getString(obj, "texture");
    int[] aint = Json.parseIntArray(obj.get("textureSize"), 2);
    float f = Json.getFloat(obj, "shadowSize", -1.0F);
    JsonArray jsonarray = (JsonArray)obj.get("models");
    checkNull(jsonarray, "Missing models");
    Map map = new HashMap();
    List list = new ArrayList();

    for (int i = 0; i < jsonarray.size(); ++i)
    {
        JsonObject jsonobject = (JsonObject)jsonarray.get(i);
        processBaseId(jsonobject, map);
        processExternalModel(jsonobject, map, s1);
        processId(jsonobject, map);
        CustomModelRenderer custommodelrenderer = parseCustomModelRenderer(jsonobject, aint, s1);

        if (custommodelrenderer != null)
        {
            list.add(custommodelrenderer);
        }
    }

    CustomModelRenderer[] acustommodelrenderer = (CustomModelRenderer[])((CustomModelRenderer[])list.toArray(new CustomModelRenderer[list.size()]));
    ResourceLocation resourcelocation = null;

    if (s2 != null)
    {
        resourcelocation = getResourceLocation(s1, s2, ".png");
    }

    CustomEntityRenderer customentityrenderer = new CustomEntityRenderer(s, s1, resourcelocation, acustommodelrenderer, f);
    return customentityrenderer;
}
 
Example 13
Project: CustomWorldGen   File: AnimationMetadataSectionSerializer.java   View Source Code Vote up 4 votes
public AnimationMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    List<AnimationFrame> list = Lists.<AnimationFrame>newArrayList();
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "metadata section");
    int i = JsonUtils.getInt(jsonobject, "frametime", 1);

    if (i != 1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid default frame time");
    }

    if (jsonobject.has("frames"))
    {
        try
        {
            JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "frames");

            for (int j = 0; j < jsonarray.size(); ++j)
            {
                JsonElement jsonelement = jsonarray.get(j);
                AnimationFrame animationframe = this.parseAnimationFrame(j, jsonelement);

                if (animationframe != null)
                {
                    list.add(animationframe);
                }
            }
        }
        catch (ClassCastException classcastexception)
        {
            throw new JsonParseException("Invalid animation->frames: expected array, was " + jsonobject.get("frames"), classcastexception);
        }
    }

    int k = JsonUtils.getInt(jsonobject, "width", -1);
    int l = JsonUtils.getInt(jsonobject, "height", -1);

    if (k != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)k, "Invalid width");
    }

    if (l != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)l, "Invalid height");
    }

    boolean flag = JsonUtils.getBoolean(jsonobject, "interpolate", false);
    return new AnimationMetadataSection(list, k, l, i, flag);
}
 
Example 14
Project: DecompiledMinecraft   File: AnimationMetadataSectionSerializer.java   View Source Code Vote up 4 votes
public AnimationMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    List<AnimationFrame> list = Lists.<AnimationFrame>newArrayList();
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "metadata section");
    int i = JsonUtils.getInt(jsonobject, "frametime", 1);

    if (i != 1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid default frame time");
    }

    if (jsonobject.has("frames"))
    {
        try
        {
            JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "frames");

            for (int j = 0; j < jsonarray.size(); ++j)
            {
                JsonElement jsonelement = jsonarray.get(j);
                AnimationFrame animationframe = this.parseAnimationFrame(j, jsonelement);

                if (animationframe != null)
                {
                    list.add(animationframe);
                }
            }
        }
        catch (ClassCastException classcastexception)
        {
            throw new JsonParseException("Invalid animation->frames: expected array, was " + jsonobject.get("frames"), classcastexception);
        }
    }

    int k = JsonUtils.getInt(jsonobject, "width", -1);
    int l = JsonUtils.getInt(jsonobject, "height", -1);

    if (k != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)k, "Invalid width");
    }

    if (l != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)l, "Invalid height");
    }

    boolean flag = JsonUtils.getBoolean(jsonobject, "interpolate", false);
    return new AnimationMetadataSection(list, k, l, i, flag);
}
 
Example 15
Project: DecompiledMinecraft   File: SoundListSerializer.java   View Source Code Vote up 4 votes
public SoundList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "entry");
    SoundList soundlist = new SoundList();
    soundlist.setReplaceExisting(JsonUtils.getBoolean(jsonobject, "replace", false));
    SoundCategory soundcategory = SoundCategory.getCategory(JsonUtils.getString(jsonobject, "category", SoundCategory.MASTER.getCategoryName()));
    soundlist.setSoundCategory(soundcategory);
    Validate.notNull(soundcategory, "Invalid category", new Object[0]);

    if (jsonobject.has("sounds"))
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sounds");

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonElement jsonelement = jsonarray.get(i);
            SoundList.SoundEntry soundlist$soundentry = new SoundList.SoundEntry();

            if (JsonUtils.isString(jsonelement))
            {
                soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonelement, "sound"));
            }
            else
            {
                JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonelement, "sound");
                soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonobject1, "name"));

                if (jsonobject1.has("type"))
                {
                    SoundList.SoundEntry.Type soundlist$soundentry$type = SoundList.SoundEntry.Type.getType(JsonUtils.getString(jsonobject1, "type"));
                    Validate.notNull(soundlist$soundentry$type, "Invalid type", new Object[0]);
                    soundlist$soundentry.setSoundEntryType(soundlist$soundentry$type);
                }

                if (jsonobject1.has("volume"))
                {
                    float f = JsonUtils.getFloat(jsonobject1, "volume");
                    Validate.isTrue(f > 0.0F, "Invalid volume", new Object[0]);
                    soundlist$soundentry.setSoundEntryVolume(f);
                }

                if (jsonobject1.has("pitch"))
                {
                    float f1 = JsonUtils.getFloat(jsonobject1, "pitch");
                    Validate.isTrue(f1 > 0.0F, "Invalid pitch", new Object[0]);
                    soundlist$soundentry.setSoundEntryPitch(f1);
                }

                if (jsonobject1.has("weight"))
                {
                    int j = JsonUtils.getInt(jsonobject1, "weight");
                    Validate.isTrue(j > 0, "Invalid weight", new Object[0]);
                    soundlist$soundentry.setSoundEntryWeight(j);
                }

                if (jsonobject1.has("stream"))
                {
                    soundlist$soundentry.setStreaming(JsonUtils.getBoolean(jsonobject1, "stream"));
                }
            }

            soundlist.getSoundList().add(soundlist$soundentry);
        }
    }

    return soundlist;
}
 
Example 16
Project: BaseClient   File: PlayerItemParser.java   View Source Code Vote up 4 votes
public static PlayerItemModel parseItemModel(JsonObject p_parseItemModel_0_)
{
    String s = Json.getString(p_parseItemModel_0_, "type");

    if (!Config.equals(s, "PlayerItem"))
    {
        throw new JsonParseException("Unknown model type: " + s);
    }
    else
    {
        int[] aint = Json.parseIntArray(p_parseItemModel_0_.get("textureSize"), 2);
        checkNull(aint, "Missing texture size");
        Dimension dimension = new Dimension(aint[0], aint[1]);
        boolean flag = Json.getBoolean(p_parseItemModel_0_, "usePlayerTexture", false);
        JsonArray jsonarray = (JsonArray)p_parseItemModel_0_.get("models");
        checkNull(jsonarray, "Missing elements");
        Map map = new HashMap();
        List list = new ArrayList();
        new ArrayList();

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonObject jsonobject = (JsonObject)jsonarray.get(i);
            String s1 = Json.getString(jsonobject, "baseId");

            if (s1 != null)
            {
                JsonObject jsonobject1 = (JsonObject)map.get(s1);

                if (jsonobject1 == null)
                {
                    Config.warn("BaseID not found: " + s1);
                    continue;
                }

                for (Entry<String, JsonElement> entry : jsonobject1.entrySet())
                {
                    if (!jsonobject.has((String)entry.getKey()))
                    {
                        jsonobject.add((String)entry.getKey(), (JsonElement)entry.getValue());
                    }
                }
            }

            String s2 = Json.getString(jsonobject, "id");

            if (s2 != null)
            {
                if (!map.containsKey(s2))
                {
                    map.put(s2, jsonobject);
                }
                else
                {
                    Config.warn("Duplicate model ID: " + s2);
                }
            }

            PlayerItemRenderer playeritemrenderer = parseItemRenderer(jsonobject, dimension);

            if (playeritemrenderer != null)
            {
                list.add(playeritemrenderer);
            }
        }

        PlayerItemRenderer[] aplayeritemrenderer = (PlayerItemRenderer[])((PlayerItemRenderer[])list.toArray(new PlayerItemRenderer[list.size()]));
        return new PlayerItemModel(dimension, flag, aplayeritemrenderer);
    }
}
 
Example 17
Project: BaseClient   File: TextureMetadataSectionSerializer.java   View Source Code Vote up 4 votes
public TextureMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    boolean flag = JsonUtils.getBoolean(jsonobject, "blur", false);
    boolean flag1 = JsonUtils.getBoolean(jsonobject, "clamp", false);
    List<Integer> list = Lists.<Integer>newArrayList();

    if (jsonobject.has("mipmaps"))
    {
        try
        {
            JsonArray jsonarray = jsonobject.getAsJsonArray("mipmaps");

            for (int i = 0; i < jsonarray.size(); ++i)
            {
                JsonElement jsonelement = jsonarray.get(i);

                if (jsonelement.isJsonPrimitive())
                {
                    try
                    {
                        list.add(Integer.valueOf(jsonelement.getAsInt()));
                    }
                    catch (NumberFormatException numberformatexception)
                    {
                        throw new JsonParseException("Invalid texture->mipmap->" + i + ": expected number, was " + jsonelement, numberformatexception);
                    }
                }
                else if (jsonelement.isJsonObject())
                {
                    throw new JsonParseException("Invalid texture->mipmap->" + i + ": expected number, was " + jsonelement);
                }
            }
        }
        catch (ClassCastException classcastexception)
        {
            throw new JsonParseException("Invalid texture->mipmaps: expected array, was " + jsonobject.get("mipmaps"), classcastexception);
        }
    }

    return new TextureMetadataSection(flag, flag1, list);
}
 
Example 18
Project: BaseClient   File: PlayerItemParser.java   View Source Code Vote up 4 votes
public static PlayerItemModel parseItemModel(JsonObject p_parseItemModel_0_)
{
    String s = Json.getString(p_parseItemModel_0_, "type");

    if (!Config.equals(s, "PlayerItem"))
    {
        throw new JsonParseException("Unknown model type: " + s);
    }
    else
    {
        int[] aint = Json.parseIntArray(p_parseItemModel_0_.get("textureSize"), 2);
        checkNull(aint, "Missing texture size");
        Dimension dimension = new Dimension(aint[0], aint[1]);
        boolean flag = Json.getBoolean(p_parseItemModel_0_, "usePlayerTexture", false);
        JsonArray jsonarray = (JsonArray)p_parseItemModel_0_.get("models");
        checkNull(jsonarray, "Missing elements");
        Map map = new HashMap();
        List list = new ArrayList();
        new ArrayList();

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonObject jsonobject = (JsonObject)jsonarray.get(i);
            String s1 = Json.getString(jsonobject, "baseId");

            if (s1 != null)
            {
                JsonObject jsonobject1 = (JsonObject)map.get(s1);

                if (jsonobject1 == null)
                {
                    Config.warn("BaseID not found: " + s1);
                    continue;
                }

                for (Entry<String, JsonElement> entry : jsonobject1.entrySet())
                {
                    if (!jsonobject.has((String)entry.getKey()))
                    {
                        jsonobject.add((String)entry.getKey(), (JsonElement)entry.getValue());
                    }
                }
            }

            String s2 = Json.getString(jsonobject, "id");

            if (s2 != null)
            {
                if (!map.containsKey(s2))
                {
                    map.put(s2, jsonobject);
                }
                else
                {
                    Config.warn("Duplicate model ID: " + s2);
                }
            }

            PlayerItemRenderer playeritemrenderer = parseItemRenderer(jsonobject, dimension);

            if (playeritemrenderer != null)
            {
                list.add(playeritemrenderer);
            }
        }

        PlayerItemRenderer[] aplayeritemrenderer = (PlayerItemRenderer[])((PlayerItemRenderer[])list.toArray(new PlayerItemRenderer[list.size()]));
        return new PlayerItemModel(dimension, flag, aplayeritemrenderer);
    }
}
 
Example 19
Project: BaseClient   File: SoundListSerializer.java   View Source Code Vote up 4 votes
public SoundList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "entry");
    SoundList soundlist = new SoundList();
    soundlist.setReplaceExisting(JsonUtils.getBoolean(jsonobject, "replace", false));
    SoundCategory soundcategory = SoundCategory.getCategory(JsonUtils.getString(jsonobject, "category", SoundCategory.MASTER.getCategoryName()));
    soundlist.setSoundCategory(soundcategory);
    Validate.notNull(soundcategory, "Invalid category", new Object[0]);

    if (jsonobject.has("sounds"))
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sounds");

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonElement jsonelement = jsonarray.get(i);
            SoundList.SoundEntry soundlist$soundentry = new SoundList.SoundEntry();

            if (JsonUtils.isString(jsonelement))
            {
                soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonelement, "sound"));
            }
            else
            {
                JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonelement, "sound");
                soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonobject1, "name"));

                if (jsonobject1.has("type"))
                {
                    SoundList.SoundEntry.Type soundlist$soundentry$type = SoundList.SoundEntry.Type.getType(JsonUtils.getString(jsonobject1, "type"));
                    Validate.notNull(soundlist$soundentry$type, "Invalid type", new Object[0]);
                    soundlist$soundentry.setSoundEntryType(soundlist$soundentry$type);
                }

                if (jsonobject1.has("volume"))
                {
                    float f = JsonUtils.getFloat(jsonobject1, "volume");
                    Validate.isTrue(f > 0.0F, "Invalid volume", new Object[0]);
                    soundlist$soundentry.setSoundEntryVolume(f);
                }

                if (jsonobject1.has("pitch"))
                {
                    float f1 = JsonUtils.getFloat(jsonobject1, "pitch");
                    Validate.isTrue(f1 > 0.0F, "Invalid pitch", new Object[0]);
                    soundlist$soundentry.setSoundEntryPitch(f1);
                }

                if (jsonobject1.has("weight"))
                {
                    int j = JsonUtils.getInt(jsonobject1, "weight");
                    Validate.isTrue(j > 0, "Invalid weight", new Object[0]);
                    soundlist$soundentry.setSoundEntryWeight(j);
                }

                if (jsonobject1.has("stream"))
                {
                    soundlist$soundentry.setStreaming(JsonUtils.getBoolean(jsonobject1, "stream"));
                }
            }

            soundlist.getSoundList().add(soundlist$soundentry);
        }
    }

    return soundlist;
}
 
Example 20
Project: Backmemed   File: PlayerItemParser.java   View Source Code Vote up 4 votes
public static PlayerItemModel parseItemModel(JsonObject p_parseItemModel_0_)
{
    String s = Json.getString(p_parseItemModel_0_, "type");

    if (!Config.equals(s, "PlayerItem"))
    {
        throw new JsonParseException("Unknown model type: " + s);
    }
    else
    {
        int[] aint = Json.parseIntArray(p_parseItemModel_0_.get("textureSize"), 2);
        checkNull(aint, "Missing texture size");
        Dimension dimension = new Dimension(aint[0], aint[1]);
        boolean flag = Json.getBoolean(p_parseItemModel_0_, "usePlayerTexture", false);
        JsonArray jsonarray = (JsonArray)p_parseItemModel_0_.get("models");
        checkNull(jsonarray, "Missing elements");
        Map map = new HashMap();
        List list = new ArrayList();
        new ArrayList();

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonObject jsonobject = (JsonObject)jsonarray.get(i);
            String s1 = Json.getString(jsonobject, "baseId");

            if (s1 != null)
            {
                JsonObject jsonobject1 = (JsonObject)map.get(s1);

                if (jsonobject1 == null)
                {
                    Config.warn("BaseID not found: " + s1);
                    continue;
                }

                for (Entry<String, JsonElement> entry : jsonobject1.entrySet())
                {
                    if (!jsonobject.has((String)entry.getKey()))
                    {
                        jsonobject.add((String)entry.getKey(), (JsonElement)entry.getValue());
                    }
                }
            }

            String s2 = Json.getString(jsonobject, "id");

            if (s2 != null)
            {
                if (!map.containsKey(s2))
                {
                    map.put(s2, jsonobject);
                }
                else
                {
                    Config.warn("Duplicate model ID: " + s2);
                }
            }

            PlayerItemRenderer playeritemrenderer = parseItemRenderer(jsonobject, dimension);

            if (playeritemrenderer != null)
            {
                list.add(playeritemrenderer);
            }
        }

        PlayerItemRenderer[] aplayeritemrenderer = (PlayerItemRenderer[])((PlayerItemRenderer[])list.toArray(new PlayerItemRenderer[list.size()]));
        return new PlayerItemModel(dimension, flag, aplayeritemrenderer);
    }
}