Search in sources :

Example 11 with JsonHolder

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

the class KeystrokesSettings method save.

public void save() {
    try {
        if (!configFile.getParentFile().exists())
            configFile.getParentFile().mkdirs();
        if (!configFile.exists() && !configFile.createNewFile())
            return;
        BetterJsonObject object = new BetterJsonObject();
        object.addProperty("x", x);
        object.addProperty("y", y);
        object.addProperty("leftClick", leftClick);
        object.addProperty("red", red);
        object.addProperty("green", green);
        object.addProperty("blue", blue);
        object.addProperty("pressedRed", pressedRed);
        object.addProperty("pressedGreen", pressedGreen);
        object.addProperty("pressedBlue", pressedBlue);
        object.addProperty("scale", getScale());
        object.addProperty("fadeTime", getFadeTime());
        object.addProperty("enabled", enabled);
        object.addProperty("chroma", chroma);
        object.addProperty("mouseButtons", mouseButtons);
        object.addProperty("showCPS", showCPS);
        object.addProperty("showCPSOnButtons", showCPSOnButtons);
        object.addProperty("showSpacebar", showSpacebar);
        object.addProperty("showSneak", showingSneak);
        object.addProperty("showFps", showingFPS);
        object.addProperty("keyBackground", keyBackground);
        object.addProperty("showingWASD", showingWASD);
        object.addProperty("literalKeys", literalKeys);
        object.addProperty("keyBackgroundOpacity", keyBackgroundOpacity);
        object.addProperty("keyBackgroundRed", keyBackgroundRed);
        object.addProperty("keyBackgroundGreen", keyBackgroundGreen);
        object.addProperty("keyBackgroundBlue", keyBackgroundBlue);
        object.addProperty("arrowKeys", arrowKeys);
        JsonArray keys = new JsonArray();
        theMod.getRenderer().getCustomKeys().forEach(wrapper -> {
            JsonHolder holder = new JsonHolder();
            holder.put("key", wrapper.getKey().getKey());
            holder.put("type", wrapper.getKey().getType());
            holder.put("xOffset", wrapper.getxOffset());
            holder.put("yOffset", wrapper.getyOffset());
            keys.add(holder.getObject());
        });
        object.getData().add("custom", keys);
        object.writeToFile(configFile);
    } catch (Exception ex) {
        Hyperium.LOGGER.warn(String.format("Could not save config file! (\"%s\")", configFile.getName()));
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonHolder(cc.hyperium.utils.JsonHolder) BetterJsonObject(cc.hyperium.utils.BetterJsonObject)

Example 12 with JsonHolder

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

the class CapesGui method drawScreen.

// 22x17
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    try {
        if (!texturesImage.isEmpty()) {
            texturesImage.forEach((s, value) -> {
                if (!textures.containsKey(s))
                    textures.put(s, new DynamicTexture(value));
            });
        }
        super.drawScreen(mouseX, mouseY, partialTicks);
        int oldScale = mc.gameSettings.guiScale;
        mc.gameSettings.guiScale = 2;
        ScaledResolution current = new ScaledResolution(Minecraft.getMinecraft());
        mc.gameSettings.guiScale = oldScale;
        float v = 2F / (oldScale);
        GlStateManager.scale(v, v, v);
        int blockWidth = 128;
        int blockHeight = 256;
        int blocksPerLine = (int) (current.getScaledWidth() / (1.5D * blockWidth));
        if (blocksPerLine % 2 == 1)
            blocksPerLine--;
        JsonHolder capeAtlas = PurchaseApi.getInstance().getCapeAtlas();
        int totalRows = (capeAtlas.getKeys().size() / blocksPerLine + (capeAtlas.getKeys().size() % blocksPerLine == 0 ? 0 : 1));
        int row = 0;
        int pos = 1;
        int printY = 15 - offset;
        GlStateManager.scale(2F, 2F, 2F);
        fontRendererObj.drawString("Capes", (current.getScaledWidth() / 2F - fontRendererObj.getStringWidth("Capes")) / 2, printY / 2F, new Color(249, 99, 0).getRGB(), true);
        String s1;
        try {
            s1 = PurchaseApi.getInstance().getSelf().getPurchaseSettings().optJSONObject("cape").optString("type");
        } catch (NullPointerException ignored) {
            return;
        }
        String s2 = capeAtlas.optJSONObject(s1).optString("name");
        if (s2.isEmpty())
            s2 = "NONE";
        String text = "Active Cape: " + s2;
        fontRendererObj.drawString(text, (current.getScaledWidth() / 2F - fontRendererObj.getStringWidth(text)) / 2, (printY + 20) / 2F, new Color(249, 99, 0).getRGB(), true);
        text = "Need more credits? Click here";
        int stringWidth1 = fontRendererObj.getStringWidth(text);
        int i2 = current.getScaledWidth() / 2 - stringWidth1;
        int i3 = printY + 40;
        fontRendererObj.drawString(text, i2 / 2F, i3 / 2F, new Color(97, 132, 249).getRGB(), true);
        GuiBlock block1 = new GuiBlock(i2, i2 + stringWidth1 * 2, i3, i3 + 15);
        GlStateManager.scale(.5F, .5F, .5F);
        actions.put(block1, () -> {
            Desktop desktop = Desktop.getDesktop();
            if (desktop != null) {
                try {
                    desktop.browse(new URL("https://purchase.sk1er.club/category/1125808").toURI());
                } catch (IOException | URISyntaxException e) {
                    e.printStackTrace();
                }
            }
        });
        printY += 25;
        printY += 35;
        int scaledWidth = current.getScaledWidth();
        RenderUtils.drawSmoothRect(scaledWidth / 2 - (blockWidth + 16) * blocksPerLine / 2, printY - 4, scaledWidth / 2 + (blockWidth + 16) * blocksPerLine / 2, printY + (blockHeight + 16) * totalRows + 4, new Color(53, 106, 110).getRGB());
        for (String s : capeAtlas.getKeys()) {
            JsonHolder cape = capeAtlas.optJSONObject(s);
            if (cape.optBoolean("private"))
                continue;
            if (pos > blocksPerLine) {
                pos = 1;
                row++;
            }
            int thisBlocksCenter = (int) (scaledWidth / 2 - ((blocksPerLine / 2) - pos + .5) * (blockWidth + 16));
            int thisTopY = printY + row * (16 + blockHeight);
            RenderUtils.drawSmoothRect(thisBlocksCenter - blockWidth / 2, thisTopY, (thisBlocksCenter + blockWidth / 2), thisTopY + blockHeight, -1);
            DynamicTexture dynamicTexture = textures.get(s);
            if (dynamicTexture != null) {
                int imgW = 120;
                int imgH = 128;
                GlStateManager.bindTexture(dynamicTexture.getGlTextureId());
                float capeScale = .75F;
                int topLeftX = (int) (thisBlocksCenter - imgW / (2F / capeScale));
                int topLeftY = thisTopY + 4;
                GlStateManager.translate(topLeftX, topLeftY, 0);
                GlStateManager.scale(capeScale, capeScale, capeScale);
                drawTexturedModalRect(0, 0, imgW / 12, 0, imgW, imgH * 2);
                GlStateManager.scale(1F / capeScale, 1F / capeScale, 1F / capeScale);
                GlStateManager.translate(-topLeftX, -topLeftY, 0);
            }
            String nameCape = cape.optString("name");
            GlStateManager.scale(2F, 2F, 2F);
            int x = thisBlocksCenter - fontRendererObj.getStringWidth(nameCape);
            fontRendererObj.drawString(nameCape, x / 2F, (thisTopY - 8 + blockHeight / 2F + 64 + 16) / 2, new Color(249, 99, 0).getRGB(), true);
            GlStateManager.scale(.5F, .5F, .5F);
            if (cosmeticCallback.getKeys().size() == 0 || purchasing) {
                String string = "Loading";
                fontRendererObj.drawString(string, thisBlocksCenter - fontRendererObj.getStringWidth(string), (thisTopY - 8 + (blockHeight >> 1) + 64 + 48), new Color(91, 102, 249).getRGB(), true);
                return;
            }
            JsonHolder jsonHolder = cosmeticCallback.optJSONObject(s);
            boolean purchased = jsonHolder.optBoolean("purchased");
            if (purchased) {
                String string = "Purchased";
                int widthThing3 = fontRendererObj.getStringWidth(string) / 2;
                int leftThing3 = thisBlocksCenter - widthThing3;
                int topThing3 = thisTopY - 8 + blockHeight / 2 + 64 + 36;
                fontRendererObj.drawString(string, leftThing3, topThing3, new Color(41, 249, 18).getRGB(), true);
                if (s.equalsIgnoreCase(s1)) {
                    string = "Active";
                    int stringWidth = fontRendererObj.getStringWidth(string);
                    int i = thisBlocksCenter - stringWidth;
                    int i1 = thisTopY - 8 + blockHeight / 2 + 64 + 48;
                    GlStateManager.scale(2F, 2F, 2F);
                    fontRendererObj.drawString(string, i / 2F, i1 / 2F, new Color(249, 55, 241).getRGB(), true);
                } else {
                    int stringWidth = fontRendererObj.getStringWidth(string);
                    int i = thisBlocksCenter - stringWidth;
                    int i1 = thisTopY - 8 + blockHeight / 2 + 64 + 48;
                    string = "Make Active";
                    GuiBlock block = new GuiBlock(i, i + stringWidth * 2, i1, i1 + 20);
                    actions.put(block, () -> {
                        JsonHolder purchaseSettings = PurchaseApi.getInstance().getSelf().getPurchaseSettings();
                        if (!purchaseSettings.has("cape")) {
                            purchaseSettings.put("cape", new JsonHolder());
                        }
                        purchaseSettings.optJSONObject("cape").put("type", s);
                        NettyClient client = NettyClient.getClient();
                        if (client != null) {
                            client.write(ServerCrossDataPacket.build(new JsonHolder().put("internal", true).put("set_cape", true).put("value", s)));
                        }
                        Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("You may need to switch worlds to update your cape.");
                    });
                    GlStateManager.scale(2F, 2F, 2F);
                    fontRendererObj.drawString(string, i / 2F, i1 / 2F, new Color(249, 55, 241).getRGB(), true);
                }
                GlStateManager.scale(.5F, .5F, .5F);
            } else {
                if (jsonHolder.optBoolean("enough")) {
                    String string = "Click to purchase";
                    int stringWidth = fontRendererObj.getStringWidth(string);
                    int left = thisBlocksCenter - stringWidth / 2;
                    int i = thisTopY - 8 + blockHeight / 2 + 64 + 48;
                    fontRendererObj.drawString(string, left, i, new Color(249, 76, 238).getRGB(), true);
                    GuiBlock block = new GuiBlock(left, left + stringWidth, i, i + 10);
                    actions.put(block, () -> {
                        Hyperium.LOGGER.debug("Attempting to purchase " + s);
                        purchasing = true;
                        Integer integer = intMap.computeIfAbsent(s, s3 -> ++purchaseIds);
                        GuiYesNo gui = new GuiYesNo(this, "Purchase " + s, "", integer);
                        Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(gui);
                        ids.put(integer, () -> {
                            GeneralChatHandler.instance().sendMessage("Attempting to purchase " + s);
                            NettyClient client = NettyClient.getClient();
                            if (client != null) {
                                client.write(ServerCrossDataPacket.build(new JsonHolder().put("internal", true).put("cosmetic_purchase", true).put("value", s)));
                            }
                        });
                    });
                } else {
                    String string = "Insufficient Credits";
                    int stringWidth = fontRendererObj.getStringWidth(string);
                    int left = thisBlocksCenter - stringWidth / 2;
                    int i = thisTopY - 8 + blockHeight / 2 + 64 + 48;
                    fontRendererObj.drawString(string, left, i, new Color(249, 9, 0).getRGB(), true);
                }
            }
            pos++;
        }
        GlStateManager.scale(1F / v, 1F / v, 1F / v);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) GuiYesNo(net.minecraft.client.gui.GuiYesNo) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NettyClient(cc.hyperium.netty.NettyClient) ScaledResolution(net.minecraft.client.gui.ScaledResolution)

Example 13 with JsonHolder

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

the class VampireZStats method getPreview.

@Override
public List<StatsDisplayItem> getPreview(HypixelApiPlayer player) {
    List<StatsDisplayItem> stats = new ArrayList<>();
    JsonHolder vampireZ = player.getStats(GameType.VAMPIREZ);
    stats.add(new DisplayLine(bold("Coins: ", vampireZ.optInt("coins"))));
    return stats;
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) DisplayLine(cc.hyperium.handlers.handlers.stats.display.DisplayLine) StatsDisplayItem(cc.hyperium.handlers.handlers.stats.display.StatsDisplayItem) ArrayList(java.util.ArrayList)

Example 14 with JsonHolder

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

the class WarlordsStats method getDeepStats.

@Override
public List<StatsDisplayItem> getDeepStats(HypixelApiPlayer player) {
    List<StatsDisplayItem> stats = getPreview(player);
    JsonHolder warlords = player.getStats(GameType.BATTLEGROUND);
    stats.add(new DisplayLine(bold("Wins: ", warlords.optInt("wins"))));
    stats.add(new DisplayLine(bold("K/D: ", WebsiteUtils.buildRatio(warlords.optInt("kills"), warlords.optInt("deaths")))));
    stats.add(new DisplayLine(bold("W/L: ", WebsiteUtils.buildRatio(warlords.optInt("wins"), warlords.optInt("losses")))));
    return stats;
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) DisplayLine(cc.hyperium.handlers.handlers.stats.display.DisplayLine) StatsDisplayItem(cc.hyperium.handlers.handlers.stats.display.StatsDisplayItem)

Example 15 with JsonHolder

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

the class WarlordsStats method getPreview.

@Override
public List<StatsDisplayItem> getPreview(HypixelApiPlayer player) {
    List<StatsDisplayItem> stats = new ArrayList<>();
    JsonHolder warlords = player.getStats(GameType.BATTLEGROUND);
    stats.add(new DisplayLine(bold("Coins: ", warlords.optInt("coins"))));
    stats.add(new DisplayLine(bold("Kills: ", warlords.optInt("kills"))));
    stats.add(new DisplayLine(bold("Assists: ", warlords.optInt("assists"))));
    stats.add(new DisplayLine(bold("Deaths: ", warlords.optInt("deaths"))));
    return stats;
}
Also used : JsonHolder(cc.hyperium.utils.JsonHolder) DisplayLine(cc.hyperium.handlers.handlers.stats.display.DisplayLine) StatsDisplayItem(cc.hyperium.handlers.handlers.stats.display.StatsDisplayItem) ArrayList(java.util.ArrayList)

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