com.betafase.mcmanager.utils.spiget.PluginInfoRequest.java Source code

Java tutorial

Introduction

Here is the source code for com.betafase.mcmanager.utils.spiget.PluginInfoRequest.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.betafase.mcmanager.utils.spiget;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.Map;

/**
 *
 * @author dbrosch
 */
public class PluginInfoRequest extends ServerRequest {

    public PluginInfoRequest(String path, Map<String, String> params) {
        super(path, params);
    }

    public PluginInfoRequest(String path) {
        super(path);
    }

    public SpigetPlugin[] getPlugins() {
        try {
            JsonArray a = getAsJsonElement().getAsJsonArray();
            ArrayList<SpigetPlugin> list = new ArrayList<>();
            for (JsonElement e : a.getAsJsonArray()) {
                JsonObject o = e.getAsJsonObject();
                int id = o.get("id").getAsInt();
                SpigetPlugin pl = new SpigetPlugin(id);
                list.add(pl);
            }
            return list.toArray(new SpigetPlugin[list.size()]);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new SpigetPlugin[0];
    }

}