Search in sources :

Example 6 with JsonHolder

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

the class Leaderboard method forceFetch.

public void forceFetch() {
    JsonHolder leaderboard = null;
    try {
        leaderboard = HypixelAPI.INSTANCE.getLeaderboardWithID(id).get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
    List<LeaderboardEntry> data = new ArrayList<>();
    for (JsonElement element : leaderboard.optJSONArray("data")) {
        JsonHolder holder = new JsonHolder(element.getAsJsonObject());
        data.add(new LeaderboardEntry(holder.optInt("pos"), holder.optString("value"), holder.optString("uuid"), holder.optString("display")));
    }
    entries = data;
    loaded = true;
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with JsonHolder

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

the class ShopTab method addComponents.

private void addComponents() {
    CollapsibleTabComponent infoTab = new CollapsibleTabComponent(this, new ArrayList<>(), "Info");
    infoTab.setCollapsed(false);
    infoTab.addChild(new LabelComponent(this, new ArrayList<>(), "Total Credits: " + personData.optInt("total_credits")));
    infoTab.addChild(new LabelComponent(this, new ArrayList<>(), "Remaining Credits: " + personData.optInt("remaining_credits")));
    infoTab.addChild(new ButtonComponent(this, new ArrayList<>(), "Capes", () -> Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(new CapesGui())));
    infoTab.addChild(new ButtonComponent(this, new ArrayList<>(), "Particles", () -> new ParticleGui().show()));
    infoTab.addChild(new ButtonComponent(this, new ArrayList<>(), "Open in browser", () -> {
        Desktop desktop = Desktop.getDesktop();
        if (desktop != null) {
            try {
                desktop.browse(new URI("https://hyperium.sk1er.club"));
            } catch (IOException | URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }));
    infoTab.addChild(new ButtonComponent(this, new ArrayList<>(), "Purchase credits", () -> {
        Desktop desktop = Desktop.getDesktop();
        if (desktop != null) {
            try {
                desktop.browse(new URI("https://purchase.sk1er.club/category/1125808"));
            } catch (IOException | URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }));
    infoTab.addChild(new ButtonComponent(this, new ArrayList<>(), "Refresh", this::refreshData));
    CollapsibleTabComponent purchaseTab = new CollapsibleTabComponent(this, Arrays.asList("Purchase", "Shop"), "Purchase");
    cosmeticCallback.getKeys().forEach(key -> {
        JsonHolder cosmetic = cosmeticCallback.optJSONObject(key);
        if (cosmetic.optBoolean("cape") || key.toLowerCase().startsWith("particle") || cosmetic.optString("name").toLowerCase().endsWith("animation")) {
            return;
        }
        CollapsibleTabComponent purchase = new CollapsibleTabComponent(this, new ArrayList<>(), cosmetic.optString("name"));
        purchase.addChild(new LabelComponent(this, new ArrayList<>(), cosmetic.optString("name") + " (" + cosmetic.optInt("cost") + " credits)"));
        purchase.addChild(new LabelComponent(this, new ArrayList<>(), cosmetic.optString("description")));
        purchase.addChild(new ButtonComponent(this, new ArrayList<>(), cosmetic.optBoolean("purchased") ? "PURCHASED" : "PURCHASE", () -> {
            if (cosmetic.optBoolean("purchased")) {
                Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("You have already purchased " + cosmetic.optString("name") + ".");
                return;
            }
            Hyperium.LOGGER.info("Attempting to purchase {}", key);
            NettyClient client = NettyClient.getClient();
            if (client != null) {
                client.write(ServerCrossDataPacket.build(new JsonHolder().put("internal", true).put("cosmetic_purchase", true).put("value", key)));
            }
        }));
        purchaseTab.addChild(purchase);
    });
    components.addAll(Arrays.asList(infoTab, purchaseTab));
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) NettyClient(cc.hyperium.netty.NettyClient) CapesGui(cc.hyperium.gui.CapesGui) ArrayList(java.util.ArrayList) CollapsibleTabComponent(cc.hyperium.gui.hyperium.components.CollapsibleTabComponent) ParticleGui(cc.hyperium.gui.ParticleGui) URI(java.net.URI) ButtonComponent(cc.hyperium.gui.hyperium.components.ButtonComponent) LabelComponent(cc.hyperium.gui.hyperium.components.LabelComponent)

Example 8 with JsonHolder

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

the class ChromaHUD method saveState.

/*
    Saves current state of all elements to file
     */
public void saveState() {
    JsonHolder master = new JsonHolder();
    boolean enabled = true;
    master.put("enabled", enabled);
    JsonArray elementArray = new JsonArray();
    master.putArray("elements", elementArray);
    getDisplayElements().forEach(element -> {
        JsonHolder tmp = element.getData();
        JsonArray items = new JsonArray();
        for (DisplayItem item : element.getDisplayItems()) {
            JsonHolder raw = item.getData();
            raw.put("type", item.getType());
            items.add(raw.getObject());
        }
        elementArray.add(tmp.getObject());
        tmp.putArray("items", items);
    });
    try {
        if (!suggestedConfigurationFile.exists())
            suggestedConfigurationFile.createNewFile();
        FileWriter fw = new FileWriter(suggestedConfigurationFile);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(master.toString());
        bw.close();
        fw.close();
    } catch (Exception ignored) {
    }
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) JsonArray(com.google.gson.JsonArray) DisplayItem(cc.hyperium.mods.chromahud.api.DisplayItem)

Example 9 with JsonHolder

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

the class ChromaHUD method setup.

public void setup() {
    JsonHolder data = new JsonHolder();
    try {
        if (!suggestedConfigurationFile.exists()) {
            if (!suggestedConfigurationFile.getParentFile().exists()) {
                suggestedConfigurationFile.getParentFile().mkdirs();
            }
            saveState();
        }
        FileReader fr = new FileReader(suggestedConfigurationFile);
        BufferedReader br = new BufferedReader(fr);
        data = new JsonHolder(br.lines().collect(Collectors.joining()));
        fr.close();
        br.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ChromaHUDApi.getInstance().post(data);
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder)

Example 10 with JsonHolder

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

the class ChromaHUD method registerConfigElements.

private void registerConfigElements() {
    ChromaHUDApi.getInstance().registerButtonConfig("COORDS", new ButtonConfig((guiButton, displayItem) -> {
        CordsDisplay displayItem1 = (CordsDisplay) displayItem;
        displayItem1.state = displayItem1.state == 1 ? 0 : 1;
        guiButton.displayString = ChatColor.RED.toString() + "Make " + (((CordsDisplay) displayItem).state == 1 ? "Horizontal" : "Vertical");
    }, new GuiButton(0, 0, 0, "Coords State"), (guiButton, displayItem) -> guiButton.displayString = ChatColor.RED.toString() + "Make " + (((CordsDisplay) displayItem).state == 1 ? "Horizontal" : "Vertical")));
    ChromaHUDApi.getInstance().registerButtonConfig("COORDS", new ButtonConfig((guiButton, displayItem) -> {
        CordsDisplay displayItem1 = (CordsDisplay) displayItem;
        displayItem1.precision += 1;
        if (displayItem1.precision > 4)
            displayItem1.precision = 0;
        int next = displayItem1.precision + 1;
        if (next > 4)
            next = 0;
        guiButton.displayString = ChatColor.RED.toString() + "Change to " + next + " decimal" + (next != 1 ? "s" : "");
    }, new GuiButton(0, 0, 0, "Coords Precision"), (guiButton, displayItem) -> {
        int next = ((CordsDisplay) displayItem).precision + 1;
        if (next > 4)
            next = 0;
        guiButton.displayString = ChatColor.RED.toString() + "Change to " + next + " decimal" + (next != 1 ? "s" : "");
    }));
    ChromaHUDApi.getInstance().registerButtonConfig("POTION", new ButtonConfig((guiButton, displayItem) -> {
        PotionEffects potionEffects = (PotionEffects) displayItem;
        potionEffects.togglePotionIcon();
        guiButton.displayString = ChatColor.RED + "Toggle Potion Icon";
    }, new GuiButton(0, 0, 0, "Potion Icons"), (guiButton, displayItem) -> guiButton.displayString = ChatColor.RED.toString() + "Toggle Potion Icon"));
    ChromaHUDApi.getInstance().registerButtonConfig("DIRECTION", new ButtonConfig((guiButton, displayItem) -> {
        DirectionHUD directionHUD = (DirectionHUD) displayItem;
        directionHUD.toggleShortDirection();
        guiButton.displayString = ChatColor.RED + "Toggle Short Direction";
    }, new GuiButton(0, 0, 0, "Short Directions"), ((guiButton, displayItem) -> guiButton.displayString = ChatColor.RED + "Toggle Short Direction")));
    ChromaHUDApi.getInstance().registerButtonConfig("ARMOUR_HUD", new ButtonConfig((guiButton, displayItem) -> {
        ArmourHud item = (ArmourHud) displayItem;
        item.toggleDurability();
        guiButton.displayString = ChatColor.RED.toString() + "Toggle Durability";
    }, new GuiButton(0, 0, 0, "Armour Hud Durability"), (guiButton, displayItem) -> guiButton.displayString = ChatColor.RED.toString() + "Toggle Durability"));
    ChromaHUDApi.getInstance().registerButtonConfig("ARMOUR_HUD", new ButtonConfig((guiButton, displayItem) -> {
        ArmourHud item = (ArmourHud) displayItem;
        item.toggleHand();
        guiButton.displayString = ChatColor.RED.toString() + "Toggle Held Item";
    }, new GuiButton(0, 0, 0, "Armour Hud Hand"), (guiButton, displayItem) -> guiButton.displayString = ChatColor.RED.toString() + "Toggle Held Item"));
    ChromaHUDApi.getInstance().registerButtonConfig("ARMOUR_HUD", new ButtonConfig((guiButton, displayItem) -> {
        ArmourHud item = (ArmourHud) displayItem;
        item.setArmourOnTop(!item.isArmourOnTop());
        guiButton.displayString = ChatColor.RED.toString() + "Toggle Armour On Top";
    }, new GuiButton(0, 0, 0, "Armour Hud Hand"), (guiButton, displayItem) -> guiButton.displayString = ChatColor.RED.toString() + "Toggle Armour On Top"));
    GuiTextField textTextField = new GuiTextField(1, Minecraft.getMinecraft().fontRendererObj, 0, 0, 200, 20);
    ChromaHUDApi.getInstance().registerTextConfig("TEXT", new TextConfig((guiTextField, displayItem) -> ((TextItem) displayItem).setText(guiTextField.getText()), textTextField, (guiTextField, displayItem) -> guiTextField.setText(((TextItem) displayItem).getText())));
    ChromaHUDApi.getInstance().registerTextConfig("TIME", new TextConfig((guiTextField, displayItem) -> ((TimeHud) displayItem).setFormat(guiTextField.getText()), textTextField, (guiTextField, displayItem) -> guiTextField.setText(((TimeHud) displayItem).getFormat())));
    ChromaHUDApi.getInstance().registerStringConfig("TIME", new StringConfig("Accepted Formats\n" + "YY - Year\n" + "MM - Month\n" + "dd - Day\n" + "HH - Hour\n" + "mm - Minute\n" + "ss - Second\n" + "For more options, Google \"Date Format\""));
    ChromaHUDApi.getInstance().registerButtonConfig("SCOREBOARD", new ButtonConfig((guiButton, displayItem) -> displayItem.getData().put("numbers", !displayItem.getData().optBoolean("numbers")), new GuiButton(0, 0, 0, "Toggle Number"), (guiButton, displayItem) -> {
    }));
    ChromaHUDApi.getInstance().registerTextConfig("SPRINT_STATUS", new TextConfig((guiTextField, displayItem) -> ((ToggleSprintStatus) displayItem).setSprintEnabledText(guiTextField.getText()), textTextField, (guiTextField, displayItem) -> guiTextField.setText(((ToggleSprintStatus) displayItem).getStatusText())));
    ChromaHUDApi.getInstance().registerButtonConfig("COINS", new ButtonConfig((guiButton, displayItem) -> {
        JsonHolder data = displayItem.getData();
        int state = data.optInt("state");
        state++;
        if (state < 0 || state > 2) {
            state = 0;
        }
        data.put("state", state);
    }, new GuiButton(0, 0, 0, "Toggle Number"), (guiButton, displayItem) -> {
        JsonHolder data = displayItem.getData();
        int state = data.optInt("state");
        if (state < 0 || state > 2)
            state = 0;
        if (state == 0)
            guiButton.displayString = "Daily Coins";
        if (state == 1)
            guiButton.displayString = "Monthly Coins";
        if (state == 2)
            guiButton.displayString = "Lifetime Coins";
    }));
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) GuiTextField(net.minecraft.client.gui.GuiTextField) StringConfig(cc.hyperium.mods.chromahud.api.StringConfig) DisplayItem(cc.hyperium.mods.chromahud.api.DisplayItem) GuiButton(net.minecraft.client.gui.GuiButton) EventBus(cc.hyperium.event.EventBus) TextConfig(cc.hyperium.mods.chromahud.api.TextConfig) cc.hyperium.mods.chromahud.displayitems.chromahud(cc.hyperium.mods.chromahud.displayitems.chromahud) ChatColor(cc.hyperium.utils.ChatColor) ButtonConfig(cc.hyperium.mods.chromahud.api.ButtonConfig) ToggleSprintStatus(cc.hyperium.mods.chromahud.displayitems.hyperium.ToggleSprintStatus) Collectors(java.util.stream.Collectors) AbstractMod(cc.hyperium.mods.AbstractMod) JsonArray(com.google.gson.JsonArray) List(java.util.List) java.io(java.io) Minecraft(net.minecraft.client.Minecraft) GeneralConfigGui(cc.hyperium.mods.chromahud.gui.GeneralConfigGui) Hyperium(cc.hyperium.Hyperium) CommandChromaHUD(cc.hyperium.mods.chromahud.commands.CommandChromaHUD) JsonHolder(cc.hyperium.utils.JsonHolder) ButtonConfig(cc.hyperium.mods.chromahud.api.ButtonConfig) GuiTextField(net.minecraft.client.gui.GuiTextField) TextConfig(cc.hyperium.mods.chromahud.api.TextConfig) ToggleSprintStatus(cc.hyperium.mods.chromahud.displayitems.hyperium.ToggleSprintStatus) GuiButton(net.minecraft.client.gui.GuiButton) StringConfig(cc.hyperium.mods.chromahud.api.StringConfig)

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