Search in sources :

Example 6 with LevelheadJsonHolder

use of cc.hyperium.mods.levelhead.util.LevelheadJsonHolder in project Hyperium by HyperiumClient.

the class LevelheadGui method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    drawDefaultBackground();
    Levelhead instance = Levelhead.getInstance();
    currentID = 0;
    buttonList.clear();
    drawScaledText(UNDERLINE.toString() + BOLD + "Levelhead " + instance.getVersion(), width / 2, 5, 2, -1, true, true);
    drawScaledText("By Sk1er LLC", width / 2, 30, 1.5, -1, true, true);
    reg(new GuiButton(++currentID, 1, 2, 150, 20, YELLOW + "Mod Status: " + (instance.getDisplayManager().getMasterConfig().isEnabled() ? GREEN + "Enabled" : RED + "Disabled")), button -> {
        instance.getDisplayManager().getMasterConfig().setEnabled(!instance.getDisplayManager().getMasterConfig().isEnabled());
        button.displayString = "Mod Status: " + (instance.getDisplayManager().getMasterConfig().isEnabled() ? GREEN + "Enabled" : RED + "Disabled");
    });
    FontRenderer fontRenderer = mc.fontRendererObj;
    if (purchasingStats) {
        reg(new GuiButton(++currentID, 1, height - 21, 100, 20, "Back"), guiButton -> purchasingStats = false);
        drawScaledText("Purchase Extra Stats", width / 2, 50, 2.0, -1, true, true);
        drawScaledText("These stats can be displayed above players' heads, in lobbies or in tab.", width / 2, 67, 1, -1, true, true);
        LevelheadJsonHolder stats = instance.getPaidData().optJsonObject("stats");
        int pos = 75 - offset;
        for (String key : stats.getKeys()) {
            LevelheadJsonHolder jsonHolder = stats.optJsonObject(key);
            boolean purchased = instance.getPurchaseStatus().optBoolean(key);
            String name = jsonHolder.optString("name");
            if (purchased)
                name += " (Purchased)";
            if (pos > 74 && pos < width - 100) {
                reg(new GuiButton(++currentID, width / 2 - 100, pos, name), guiButton -> {
                    if (!purchased)
                        attemptPurchase(key);
                });
            }
            pos += 22;
        }
    } else {
        reg(new GuiButton(++currentID, 1, 44, 150, 20, YELLOW + "Purchase Extra Stats"), guiButton -> purchasingStats = true);
        if (currentlyBeingEdited == null) {
            currentlyBeingEdited = instance.getDisplayManager().getAboveHead().get(0);
            textField.setText(currentlyBeingEdited.getConfig().getCustomHeader());
        }
        int index = 0;
        DisplayConfig config = currentlyBeingEdited.getConfig();
        int editWidth = 125;
        doGeneral(config, instance, editWidth);
        if (currentlyBeingEdited instanceof AboveHeadDisplay) {
            doHead(config, instance, editWidth, mouseX, mouseY);
            index = 0;
        } else if (currentlyBeingEdited instanceof ChatDisplay) {
            doChat(config, instance, editWidth);
            index = 1;
        } else if (currentlyBeingEdited instanceof TabDisplay) {
            doTab(instance);
            index = 2;
        }
        String[] types = { "Above Head Display", "Chat Display", "Tab Display" };
        drawScaledText(LIGHT_PURPLE + "Levelhead Credits: " + AQUA + instance.getRawPurchases().optInt("remaining_levelhead_credits"), width / 3, height - 90, 1.5D, -1, true, true);
        drawScaledText((currentlyBeingEdited instanceof AboveHeadDisplay ? GREEN : (currentlyBeingEdited instanceof TabDisplay && instance.getLevelheadPurchaseStates().isTab() ? GREEN : (currentlyBeingEdited instanceof ChatDisplay && instance.getLevelheadPurchaseStates().isChat() ? GREEN : RED))) + types[index], width / 3, height - 110, 1.25, new Color(255, 255, 255).getRGB(), true, true);
        int finalIndex = index;
        reg(new GuiButton(++currentID, width / 3 - 65 - 20, height - 115, 20, 20, "<"), guiButton -> {
            if (finalIndex == 0) {
                currentlyBeingEdited = instance.getDisplayManager().getChat();
            } else if (finalIndex == 1) {
                currentlyBeingEdited = instance.getDisplayManager().getTab();
            } else {
                currentlyBeingEdited = instance.getDisplayManager().getAboveHead().get(0);
            }
        });
        reg(new GuiButton(++currentID, width / 3 + 65, height - 115, 20, 20, ">"), guiButton -> {
            if (finalIndex == 0) {
                currentlyBeingEdited = instance.getDisplayManager().getTab();
            } else if (finalIndex == 1) {
                currentlyBeingEdited = instance.getDisplayManager().getAboveHead().get(0);
            } else {
                currentlyBeingEdited = instance.getDisplayManager().getChat();
            }
        });
        if (bigChange) {
            int start = height - 25;
            int i = 0;
            for (String s : "Some changes cannot be applied in real time.\nThey will be applied once you close this GUI".split("\n")) {
                fontRenderer.drawString(s, width - fontRenderer.getStringWidth(s) - 5, start + (i * 10), Color.RED.getRGB(), true);
                i++;
            }
        }
        drawScaledText(LIGHT_PURPLE + "Custom Levelhead Status: " + (isCustom ? GREEN + "Enabled" : RED + "Disabled"), 2, height - 55, 1.25, -1, true, false);
        reg(new GuiButton(++currentID, 2, height - 44, 220, 20, (isCustom ? ChatColor.YELLOW + "Click to change custom Levelhead." : ChatColor.YELLOW + "Click to purchase custom Levelhead")), button -> {
            try {
                if (isCustom) {
                    Minecraft.getMinecraft().displayGuiScreen(new CustomLevelheadConfigurer());
                } else {
                    Desktop.getDesktop().browse(new URI("http://sk1er.club/customlevelhead"));
                }
            } catch (IOException | URISyntaxException e) {
                e.printStackTrace();
            }
        });
        reg(new GuiButton(++currentID, 1, 23, 150, 20, YELLOW + "Purchase Levelhead Credits"), button -> {
            Desktop desktop = Desktop.getDesktop();
            if (desktop != null) {
                try {
                    desktop.browse(new URI("https://purchase.sk1er.club/category/1050972"));
                } catch (IOException | URISyntaxException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    super.drawScreen(mouseX, mouseY, partialTicks);
}
Also used : Levelhead(cc.hyperium.mods.levelhead.Levelhead) ChatColor(cc.hyperium.utils.ChatColor) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 7 with LevelheadJsonHolder

use of cc.hyperium.mods.levelhead.util.LevelheadJsonHolder in project Hyperium by HyperiumClient.

the class LevelheadGui method doHead.

private void doHead(DisplayConfig config, Levelhead instance, int editWidth, int mouseX, int mouseY) {
    List<AboveHeadDisplay> aboveHead = instance.getDisplayManager().getAboveHead();
    textField.drawTextBox();
    if (!textField.getText().equalsIgnoreCase(config.getCustomHeader())) {
        config.setCustomHeader(textField.getText());
        updatePeopleToValues();
    }
    reg(new GuiButton(++currentID, width / 3 - 100, height - 137, 200, 20, YELLOW + "Purchase Additional Above Head Layer"), button -> attemptPurchase("head"));
    reg(new GuiButton(++currentID, width - editWidth * 2 - 3, 29, editWidth, 20, YELLOW + "Editing Layer: " + AQUA + (aboveHead.indexOf(currentlyBeingEdited) + 1)), button -> {
        int i = aboveHead.indexOf(currentlyBeingEdited);
        i++;
        if (i >= aboveHead.size()) {
            i = 0;
        }
        currentlyBeingEdited = aboveHead.get(i);
        textField.setText(currentlyBeingEdited.getConfig().getCustomHeader());
    });
    reg(new GuiButton(++currentID, width - editWidth * 2 - 3, 50, editWidth, 20, YELLOW + "Show On Self: " + AQUA + (currentlyBeingEdited.getConfig().isShowSelf() ? "YES" : "NO")), button -> currentlyBeingEdited.getConfig().setShowSelf(!currentlyBeingEdited.getConfig().isShowSelf()));
    int colorConfigStart = 93 + 2;
    reg(new GuiButton(++currentID, width - editWidth * 2 - 2, colorConfigStart, editWidth, 20, YELLOW + "Header Mode: " + AQUA + getMode(true)), button -> {
        if (config.isHeaderRgb()) {
            config.setHeaderRgb(false);
            config.setHeaderChroma(true);
        } else if (config.isHeaderChroma()) {
            config.setHeaderRgb(false);
            config.setHeaderChroma(false);
        } else {
            config.setHeaderRgb(true);
            config.setHeaderChroma(false);
        }
        updatePeopleToValues();
    });
    if (config.isHeaderRgb()) {
        regSlider(new GuiSlider(++currentID, width - editWidth * 2 - 2, colorConfigStart + 22, editWidth, 20, YELLOW + "Header Red: " + AQUA, "", 0, 255, config.getHeaderRed(), false, true, slider -> {
            config.setHeaderRed(slider.getValueInt());
            updatePeopleToValues();
        }));
        regSlider(new GuiSlider(++currentID, width - editWidth * 2 - 2, colorConfigStart + 44, editWidth, 20, YELLOW + "Header Green: " + AQUA, "", 0, 255, config.getHeaderGreen(), false, true, slider -> {
            config.setHeaderGreen(slider.getValueInt());
            updatePeopleToValues();
        }));
        regSlider(new GuiSlider(++currentID, width - editWidth * 2 - 2, colorConfigStart + 66, editWidth, 20, YELLOW + "Header Blue: " + AQUA, "", 0, 255, config.getHeaderBlue(), false, true, slider -> {
            config.setHeaderBlue(slider.getValueInt());
            updatePeopleToValues();
        }));
    } else if (!config.isHeaderChroma()) {
        reg(new GuiButton(++currentID, width - editWidth * 2 - 2, colorConfigStart + 22, editWidth, 20, config.getHeaderColor() + "Rotate Header Color"), button -> {
            int primaryId = colors.indexOf(removeColorChar(config.getHeaderColor()));
            if (++primaryId == colors.length()) {
                primaryId = 0;
            }
            config.setHeaderColor(COLOR_CHAR + colors.charAt(primaryId));
            updatePeopleToValues();
        });
    }
    reg(new GuiButton(++currentID, width - editWidth - 1, colorConfigStart, editWidth, 20, YELLOW + "Footer Mode: " + AQUA + getMode(false)), button -> {
        updateFooterColorState(config);
        button.displayString = "Footer Mode: " + getMode(false);
        updatePeopleToValues();
    });
    if (config.isFooterRgb()) {
        regSlider(new GuiSlider(++currentID, width - editWidth - 1, colorConfigStart + 22, editWidth, 20, YELLOW + "Footer Red: " + AQUA, "", 0, 255, config.getFooterRed(), false, true, slider -> {
            config.setFooterRed(slider.getValueInt());
            updatePeopleToValues();
        }));
        regSlider(new GuiSlider(++currentID, width - editWidth - 1, colorConfigStart + 44, editWidth, 20, YELLOW + "Footer Green: " + AQUA, "", 0, 255, config.getFooterGreen(), false, true, slider -> {
            config.setFooterGreen(slider.getValueInt());
            updatePeopleToValues();
        }));
        regSlider(new GuiSlider(++currentID, width - editWidth - 1, colorConfigStart + 66, editWidth, 20, YELLOW + "Footer Blue: " + AQUA, "", 0, 255, config.getFooterBlue(), false, true, slider -> {
            config.setFooterBlue(slider.getValueInt());
            updatePeopleToValues();
        }));
    } else if (!config.isFooterChroma()) {
        reg(new GuiButton(++currentID, width - editWidth - 1, colorConfigStart + 22, editWidth, 20, config.getFooterColor() + "Rotate Footer Color"), button -> incrementColor(config, false));
    }
    regSlider(new GuiSlider(++currentID, width - editWidth * 2 - 2, colorConfigStart + 88, editWidth, 20, YELLOW + "Vertical Offset: " + AQUA, "", -50, 100, instance.getDisplayManager().getMasterConfig().getOffset() * 100D, false, true, slider -> instance.getDisplayManager().getMasterConfig().setOffset(slider.getValue() / 100D)));
    regSlider(new GuiSlider(++currentID, width - editWidth - 1, colorConfigStart + 88, editWidth, 20, YELLOW + "Font Size: " + AQUA, "", 1, 20, instance.getDisplayManager().getMasterConfig().getFontSize() * 10D, false, true, slider -> {
        instance.getDisplayManager().getMasterConfig().setFontSize(slider.getValue() / 10D);
        updatePeopleToValues();
    }));
    if (isCustom) {
        reg(new GuiButton(++currentID, width - editWidth * 2 - 2, colorConfigStart + 88 + 22, editWidth * 2 + 1, 20, YELLOW + "Export Colors to Custom Levelhead"), guiButton -> {
            final LevelheadJsonHolder object;
            String encode;
            String url;
            ChatComponentText text;
            ChatStyle style;
            ChatComponentText valueIn;
            ChatStyle style2;
            object = new LevelheadJsonHolder();
            object.put("header_obj", currentlyBeingEdited.getHeaderConfig());
            object.put("footer_obj", currentlyBeingEdited.getFooterConfig());
            try {
                encode = URLEncoder.encode(object.toString(), "UTF-8");
                url = "https://sk1er.club/user?levelhead_color=" + encode;
                text = new ChatComponentText("Click here to update your custom Levelhead colors");
                style = new ChatStyle();
                style.setBold(true);
                style.setColor(EnumChatFormatting.YELLOW);
                style.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
                valueIn = new ChatComponentText("Please be logged in to your Sk1er.club for this to work. Do /levelhead dumpcache after clicking to see new colors!");
                valueIn.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
                style2 = new ChatStyle();
                style2.setColor(EnumChatFormatting.RED);
                valueIn.setChatStyle(style2);
                style.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, valueIn));
                text.setChatStyle(style);
                mc.thePlayer.addChatComponentMessage(valueIn);
                mc.thePlayer.addChatComponentMessage(text);
            } catch (UnsupportedEncodingException e2) {
                e2.printStackTrace();
            }
            mc.displayGuiScreen(null);
        });
    }
    GlStateManager.pushMatrix();
    GlStateManager.color(1, 1, 1);
    RenderHelper.enableStandardItemLighting();
    GlStateManager.enableAlpha();
    GlStateManager.shadeModel(7424);
    GlStateManager.enableAlpha();
    GlStateManager.enableDepth();
    GlStateManager.translate(0, 0, 50);
    ScaledResolution current = new ScaledResolution(mc);
    int posX = current.getScaledWidth() / 3;
    int posY = current.getScaledHeight() / 2;
    GuiInventory.drawEntityOnScreen(posX, posY + 50, 50, posX - mouseX, posY - mouseY, mc.thePlayer);
    GlStateManager.depthFunc(515);
    GlStateManager.resetColor();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.disableDepth();
    GlStateManager.popMatrix();
    drawScaledText("Custom Prefix: ", width - editWidth * 3 / 2 - 3, 77, 1.5, -1, true, true);
}
Also used : net.minecraft.util(net.minecraft.util) Levelhead(cc.hyperium.mods.levelhead.Levelhead) NetworkPlayerInfo(net.minecraft.client.network.NetworkPlayerInfo) java.util(java.util) LevelheadChatRenderer(cc.hyperium.mods.levelhead.renderer.LevelheadChatRenderer) ChatColor(cc.hyperium.utils.ChatColor) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) URISyntaxException(java.net.URISyntaxException) GuiSlider(net.minecraftforge.fml.client.config.GuiSlider) net.minecraft.client.gui(net.minecraft.client.gui) LevelheadPurchaseStates(cc.hyperium.mods.levelhead.purchases.LevelheadPurchaseStates) Minecraft(net.minecraft.client.Minecraft) HoverEvent(net.minecraft.event.HoverEvent) Multithreading(cc.hyperium.mods.sk1ercommon.Multithreading) RenderHelper(net.minecraft.client.renderer.RenderHelper) Hyperium(cc.hyperium.Hyperium) Sk1erMod(cc.hyperium.mods.sk1ercommon.Sk1erMod) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) URI(java.net.URI) ClickEvent(net.minecraft.event.ClickEvent) JsonHolder(cc.hyperium.utils.JsonHolder) GuiInventory(net.minecraft.client.gui.inventory.GuiInventory) GlStateManager(net.minecraft.client.renderer.GlStateManager) IOException(java.io.IOException) Mouse(org.lwjgl.input.Mouse) cc.hyperium.mods.levelhead.display(cc.hyperium.mods.levelhead.display) EnumPlayerModelParts(net.minecraft.entity.player.EnumPlayerModelParts) java.awt(java.awt) Consumer(java.util.function.Consumer) URLEncoder(java.net.URLEncoder) List(java.util.List) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Scoreboard(net.minecraft.scoreboard.Scoreboard) HoverEvent(net.minecraft.event.HoverEvent) ClickEvent(net.minecraft.event.ClickEvent) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder) GuiSlider(net.minecraftforge.fml.client.config.GuiSlider)

Example 8 with LevelheadJsonHolder

use of cc.hyperium.mods.levelhead.util.LevelheadJsonHolder in project Hyperium by HyperiumClient.

the class Levelhead method fetch.

public void fetch(UUID uuid, LevelheadDisplay display, boolean allowOverride) {
    if (updates >= count) {
        waitUntil = System.currentTimeMillis() + 1000 * wait;
        updates = 0;
        return;
    }
    updates++;
    display.getCache().put(uuid, new NullLevelheadTag(null));
    String type = display.getConfig().getType();
    if (purchaseStatus.has(type) && !purchaseStatus.optBoolean(type)) {
        LevelheadJsonHolder fakeValue = new LevelheadJsonHolder();
        fakeValue.put("header", "Error");
        fakeValue.put("strlevel", "Item '" + type + "' not purchased. If you believe this is an error, contact Sk1er");
        fakeValue.put("success", true);
        display.getCache().put(uuid, buildTag(fakeValue, uuid, display, allowOverride));
        return;
    }
    Multithreading.runAsync(() -> {
        String raw = rawWithAgent("https://api.sk1er.club/levelheadv5/" + trimUuid(uuid) + "/" + type + "/" + trimUuid(Minecraft.getMinecraft().getSession().getProfile().getId()) + "/" + VERSION + "/" + auth.getHash() + "/" + display.getPosition().name());
        LevelheadJsonHolder object = new LevelheadJsonHolder(raw);
        if (!object.optBoolean("success")) {
            object.put("strlevel", "Error");
        }
        if (!allowOverride) {
            object.put("strlevel", object.optString("level"));
            object.remove("header_obj");
            object.remove("footer_obj");
        }
        LevelheadTag value = buildTag(object, uuid, display, allowOverride);
        display.getCache().put(uuid, value);
        display.getTrueValueCache().put(uuid, object.optString("strlevel"));
    });
    Multithreading.POOL.submit(this::clearCache);
}
Also used : NullLevelheadTag(cc.hyperium.mods.levelhead.renderer.NullLevelheadTag) LevelheadTag(cc.hyperium.mods.levelhead.renderer.LevelheadTag) NullLevelheadTag(cc.hyperium.mods.levelhead.renderer.NullLevelheadTag) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder)

Example 9 with LevelheadJsonHolder

use of cc.hyperium.mods.levelhead.util.LevelheadJsonHolder in project Hyperium by HyperiumClient.

the class Levelhead method refreshPurchaseStates.

public synchronized void refreshPurchaseStates() {
    purchaseStatus = new LevelheadJsonHolder(rawWithAgent("https://api.sk1er.club/levelhead_purchase_status/" + Minecraft.getMinecraft().getSession().getProfile().getId().toString()));
    levelheadPurchaseStates.setChat(purchaseStatus.optBoolean("chat"));
    levelheadPurchaseStates.setTab(purchaseStatus.optBoolean("tab"));
    levelheadPurchaseStates.setExtraHead(purchaseStatus.optInt("head"));
    DisplayManager displayManager = this.displayManager;
    while (displayManager.getAboveHead().size() <= levelheadPurchaseStates.getExtraHead()) {
        displayManager.getAboveHead().add(new AboveHeadDisplay(new DisplayConfig()));
    }
    displayManager.adjustIndexes();
}
Also used : DisplayManager(cc.hyperium.mods.levelhead.display.DisplayManager) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder) DisplayConfig(cc.hyperium.mods.levelhead.display.DisplayConfig) AboveHeadDisplay(cc.hyperium.mods.levelhead.display.AboveHeadDisplay)

Example 10 with LevelheadJsonHolder

use of cc.hyperium.mods.levelhead.util.LevelheadJsonHolder in project Hyperium by HyperiumClient.

the class Levelhead method rawWithAgent.

private String rawWithAgent(String url) {
    Hyperium.LOGGER.debug("Fetching " + url);
    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 (SK1ER LEVEL HEAD V" + VERSION + ")");
        connection.setReadTimeout(15000);
        connection.setConnectTimeout(15000);
        connection.setDoOutput(true);
        InputStream is = connection.getInputStream();
        return IOUtils.toString(is, Charset.defaultCharset());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (connection != null)
            connection.disconnect();
    }
    return new LevelheadJsonHolder().put("success", false).put("cause", "API_DOWN").toString();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder) URL(java.net.URL)

Aggregations

LevelheadJsonHolder (cc.hyperium.mods.levelhead.util.LevelheadJsonHolder)15 ChatColor (cc.hyperium.utils.ChatColor)4 Hyperium (cc.hyperium.Hyperium)3 Levelhead (cc.hyperium.mods.levelhead.Levelhead)3 DisplayManager (cc.hyperium.mods.levelhead.display.DisplayManager)3 LevelheadChatRenderer (cc.hyperium.mods.levelhead.renderer.LevelheadChatRenderer)3 LevelheadTag (cc.hyperium.mods.levelhead.renderer.LevelheadTag)3 NullLevelheadTag (cc.hyperium.mods.levelhead.renderer.NullLevelheadTag)3 Sk1erMod (cc.hyperium.mods.sk1ercommon.Sk1erMod)3 File (java.io.File)3 IOException (java.io.IOException)3 List (java.util.List)3 MojangAuth (cc.hyperium.mods.levelhead.auth.MojangAuth)2 CustomLevelheadCommand (cc.hyperium.mods.levelhead.command.CustomLevelheadCommand)2 LevelheadCommand (cc.hyperium.mods.levelhead.command.LevelheadCommand)2 AboveHeadDisplay (cc.hyperium.mods.levelhead.display.AboveHeadDisplay)2 DisplayConfig (cc.hyperium.mods.levelhead.display.DisplayConfig)2 LevelheadPurchaseStates (cc.hyperium.mods.levelhead.purchases.LevelheadPurchaseStates)2 AboveHeadRenderer (cc.hyperium.mods.levelhead.renderer.AboveHeadRenderer)2 Multithreading (cc.hyperium.mods.sk1ercommon.Multithreading)2