Search in sources :

Example 1 with JsonHolder

use of cc.hyperium.utils.JsonHolder in project Hyperium by HyperiumClient.

the class HypixelApiGuild method getInOrder.

public List<GuildPlayer> getInOrder() {
    List<GuildPlayer> players = new ArrayList<>();
    for (JsonElement element : getMembers()) {
        players.add(new GuildPlayer(new JsonHolder(element.getAsJsonObject())));
    }
    players.sort(Comparator.comparingInt(o -> getPriorityForRank(o.getRank())));
    Collections.reverse(players);
    return players;
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) JsonHolder(cc.hyperium.utils.JsonHolder) JsonElement(com.google.gson.JsonElement) JsonArray(com.google.gson.JsonArray) List(java.util.List) Comparator(java.util.Comparator) WebsiteUtils(club.sk1er.website.utils.WebsiteUtils) Collections(java.util.Collections) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList)

Example 2 with JsonHolder

use of cc.hyperium.utils.JsonHolder in project Hyperium by HyperiumClient.

the class PurchaseApi method get.

public JsonHolder get(String url) {
    url = url.replace(" ", "%20");
    HttpURLConnection connection = null;
    try {
        URL u = new URL(url);
        connection = (HttpURLConnection) u.openConnection();
        connection.setRequestMethod("GET");
        connection.setUseCaches(true);
        connection.addRequestProperty("User-Agent", "Mozilla/4.76 Hyperium ");
        connection.setReadTimeout(15000);
        connection.setConnectTimeout(15000);
        connection.setDoOutput(true);
        InputStream is = connection.getInputStream();
        return new JsonHolder(IOUtils.toString(is, StandardCharsets.UTF_8));
    } catch (Exception ignored) {
    } finally {
        if (connection != null)
            connection.disconnect();
    }
    JsonObject object = new JsonObject();
    object.addProperty("success", false);
    object.addProperty("cause", "Exception");
    return new JsonHolder(object);
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with JsonHolder

use of cc.hyperium.utils.JsonHolder in project Hyperium by HyperiumClient.

the class StaffUtils method getBoosters.

private static HashMap<UUID, StaffSettings> getBoosters() throws IOException {
    HashMap<UUID, StaffSettings> boosters = new HashMap<>();
    String raw = HttpUtil.get(new URL("https://api.github.com/gists/b070e7f75a9083d2e211caffa0c772cc"));
    String content = new JsonHolder(raw).optJSONObject("files").optJSONObject("boosters.json").optString("content");
    JsonParser parser = new JsonParser();
    JsonArray array = parser.parse(content).getAsJsonArray();
    int bound = array.size();
    for (int i = 0; i < bound; i++) {
        JsonObject item = array.get(i).getAsJsonObject();
        UUID uuid = UUID.fromString(item.get("uuid").getAsString());
        String colourStr = item.get("color").getAsString().toUpperCase();
        DotColour colour = colourStr.equals("CHROMA") ? new DotColour(true, ChatColor.WHITE) : new DotColour(false, ChatColor.valueOf(colourStr));
        boosters.put(uuid, new StaffSettings(colour));
    }
    return boosters;
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) JsonArray(com.google.gson.JsonArray) StaffSettings(cc.hyperium.utils.staff.StaffSettings) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) UUID(java.util.UUID) URL(java.net.URL) JsonParser(com.google.gson.JsonParser)

Example 4 with JsonHolder

use of cc.hyperium.utils.JsonHolder in project Hyperium by HyperiumClient.

the class GeneralChatHandler method post.

public void post() {
    JsonHolder data = new JsonHolder(new JsonParser().parse(new InputStreamReader(GeneralChatHandler.class.getResourceAsStream("/remoteresources/chat_regex.json"))).getAsJsonObject());
    HyperiumChatHandler.regexPatterns = new EnumMap<>(HyperiumChatHandler.ChatRegexType.class);
    for (HyperiumChatHandler.ChatRegexType type : HyperiumChatHandler.ChatRegexType.values()) {
        if (!data.has(type.name().toLowerCase())) {
            Hyperium.LOGGER.error("Could not find chat regex type " + type.name().toLowerCase() + " in the remote file.");
            continue;
        }
        HyperiumChatHandler.regexPatterns.put(type, Pattern.compile(data.optString(type.name().toLowerCase())));
    }
    posted = true;
    for (HyperiumChatHandler chatHandler : handlerList) {
        chatHandler.callback(data);
    }
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) InputStreamReader(java.io.InputStreamReader) JsonParser(com.google.gson.JsonParser)

Example 5 with JsonHolder

use of cc.hyperium.utils.JsonHolder in project Hyperium by HyperiumClient.

the class HypixelAPI method getFrontendNameOfQuest.

public String getFrontendNameOfQuest(String backendName) {
    JsonHolder quests = QUESTS.optJSONObject("quests");
    List<JsonArray> arrays = quests.getKeys().stream().map(quests::optJSONArray).collect(Collectors.toList());
    for (JsonArray array : arrays) {
        for (JsonElement element : array) {
            JsonHolder holder = new JsonHolder(element.getAsJsonObject());
            if (holder.optString("id").equalsIgnoreCase(backendName))
                return holder.optString("name");
        }
    }
    return backendName;
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement)

Aggregations

JsonHolder (cc.hyperium.utils.JsonHolder)81 DisplayLine (cc.hyperium.handlers.handlers.stats.display.DisplayLine)42 StatsDisplayItem (cc.hyperium.handlers.handlers.stats.display.StatsDisplayItem)42 ArrayList (java.util.ArrayList)34 NettyClient (cc.hyperium.netty.NettyClient)13 DisplayTable (cc.hyperium.handlers.handlers.stats.display.DisplayTable)10 JsonArray (com.google.gson.JsonArray)9 JsonElement (com.google.gson.JsonElement)8 HyperiumPurchase (cc.hyperium.purchases.HyperiumPurchase)5 JsonObject (com.google.gson.JsonObject)5 URL (java.net.URL)5 UUID (java.util.UUID)5 HashMap (java.util.HashMap)4 InvokeEvent (cc.hyperium.event.InvokeEvent)3 PurchaseLoadEvent (cc.hyperium.event.network.PurchaseLoadEvent)3 AbstractAnimationHandler (cc.hyperium.handlers.handlers.animation.AbstractAnimationHandler)3 DisplayItem (cc.hyperium.mods.chromahud.api.DisplayItem)3 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 GuiButton (net.minecraft.client.gui.GuiButton)3