Search in sources :

Example 1 with LevelheadJsonHolder

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

the class LevelheadGui method attemptPurchase.

private void attemptPurchase(String key) {
    Levelhead instance = Levelhead.getInstance();
    LevelheadJsonHolder paidData = instance.getPaidData();
    Hyperium.LOGGER.debug(paidData);
    LevelheadJsonHolder extraDisplays = paidData.optJsonObject("extra_displays");
    LevelheadJsonHolder stats = paidData.optJsonObject("stats");
    boolean found;
    boolean display = false;
    String name = null;
    String description = null;
    int cost = 0;
    LevelheadJsonHolder seed = null;
    boolean single = false;
    if (extraDisplays.has(key)) {
        seed = extraDisplays.optJsonObject(key);
    } else if (stats.has(key)) {
        seed = stats.optJsonObject(key);
    }
    found = seed != null;
    if (seed != null) {
        name = seed.optString("name");
        description = seed.optString("description");
        cost = seed.optInt("cost");
        single = seed.optBoolean("single");
    }
    int remainingLevelheadCredits = instance.getRawPurchases().optInt("remaining_levelhead_credits");
    if (remainingLevelheadCredits < cost) {
        mc.displayGuiScreen(null);
        Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("Insufficient Levelhead credits! " + name + " costs " + cost + " credits but you only have " + remainingLevelheadCredits);
        Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("You can purchase more Levelhead credits here: https://purchase.sk1er.club/category/1050972");
        return;
    }
    if (instance.getAuth().isFailed()) {
        mc.displayGuiScreen(null);
        Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("Could not verify your identity. Please restart your client. If the issue persists, contact Sk1er.");
        return;
    }
    if (found) {
        String finalName = name;
        ids.put(key.hashCode(), () -> {
            Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("Attempting to purchase: " + finalName);
            Multithreading.runAsync(() -> {
                LevelheadJsonHolder jsonHolder = new LevelheadJsonHolder(Sk1erMod.getInstance().rawWithAgent("https://api.sk1er.club/levelhead_purchase?access_token=" + instance.getAuth().getAccessKey() + "&request=" + key + "&hash=" + instance.getAuth().getHash()));
                if (jsonHolder.optBoolean("success")) {
                    instance.refreshPurchaseStates();
                    Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("Successfully purchased: " + finalName);
                } else {
                    Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("Failed to purchase: " + finalName + ". Cause: " + jsonHolder.optString("cause"));
                }
            });
        });
        GuiYesNo gui = new GuiYesNo(this, "Purchase " + finalName, "Description:" + " " + description + ". This item may be purchased " + (single ? "one time" : "many times") + ". Type: " + (display ? "Display" : "Extra Stat"), "Purchase for " + cost + " credits", "Cancel", key.hashCode());
        Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(gui);
    } else {
        Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("Could not find package: " + key + ". Please contact Sk1er immediately.");
    }
}
Also used : Levelhead(cc.hyperium.mods.levelhead.Levelhead) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder)

Example 2 with LevelheadJsonHolder

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

the class Levelhead method init.

@Override
public AbstractMod init() {
    instance = this;
    LevelheadJsonHolder jsonHolder = new LevelheadJsonHolder();
    try {
        jsonHolder = new LevelheadJsonHolder(FileUtils.readFileToString(new File(Hyperium.folder, "levelhead.json")));
    } catch (Exception e) {
        e.printStackTrace();
    }
    displayManager = new DisplayManager(jsonHolder, new File(Hyperium.folder, "levelhead.json"));
    Multithreading.runAsync(() -> types = new LevelheadJsonHolder(rawWithAgent("https://api.sk1er.club/levelhead_config")));
    Sk1erMod sk1erMod = new Sk1erMod("LEVEL_HEAD", VERSION, object -> {
        count = object.optInt("count");
        wait = object.optInt("wait", Integer.MAX_VALUE);
        if (count == 0 || wait == Integer.MAX_VALUE) {
            Hyperium.LOGGER.warn("An error occurred whilst loading loading internal Levelhead info.");
        }
    });
    sk1erMod.checkStatus();
    auth = new MojangAuth();
    Multithreading.runAsync(() -> {
        auth.auth();
        if (auth.isFailed()) {
            Hyperium.LOGGER.warn("Failed to authenticate with Levelhead: {}", auth.getFailedMessage());
        }
    });
    userUuid = Minecraft.getMinecraft().getSession().getProfile().getId();
    Hyperium.INSTANCE.getHandlers().getCommandHandler().registerCommand(new LevelheadCommand());
    Hyperium.INSTANCE.getHandlers().getCommandHandler().registerCommand(new CustomLevelheadCommand());
    LevelheadChatRenderer levelheadChatRenderer = new LevelheadChatRenderer(this);
    EventBus.INSTANCE.register(this);
    EventBus.INSTANCE.register(levelheadChatRenderer);
    EventBus.INSTANCE.register(new AboveHeadRenderer(this));
    Multithreading.runAsync(this::refreshPurchaseStates);
    Multithreading.runAsync(this::refreshRawPurchases);
    Multithreading.runAsync(this::refreshPaidData);
    return this;
}
Also used : Sk1erMod(cc.hyperium.mods.sk1ercommon.Sk1erMod) AboveHeadRenderer(cc.hyperium.mods.levelhead.renderer.AboveHeadRenderer) MojangAuth(cc.hyperium.mods.levelhead.auth.MojangAuth) CustomLevelheadCommand(cc.hyperium.mods.levelhead.command.CustomLevelheadCommand) LevelheadCommand(cc.hyperium.mods.levelhead.command.LevelheadCommand) DisplayManager(cc.hyperium.mods.levelhead.display.DisplayManager) LevelheadChatRenderer(cc.hyperium.mods.levelhead.renderer.LevelheadChatRenderer) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder) File(java.io.File) CustomLevelheadCommand(cc.hyperium.mods.levelhead.command.CustomLevelheadCommand)

Example 3 with LevelheadJsonHolder

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

the class Levelhead method buildTag.

private LevelheadTag buildTag(LevelheadJsonHolder object, UUID uuid, LevelheadDisplay display, boolean allowOverride) {
    LevelheadTag value = new LevelheadTag(uuid);
    LevelheadJsonHolder headerObj = new LevelheadJsonHolder();
    LevelheadJsonHolder footerObj = new LevelheadJsonHolder();
    LevelheadJsonHolder construct = new LevelheadJsonHolder();
    if (object.has("header_obj") && allowOverride) {
        headerObj = object.optJsonObject("header_obj");
        headerObj.put("custom", true);
    }
    if (object.has("footer_obj") && allowOverride) {
        footerObj = object.optJsonObject("footer_obj");
        footerObj.put("custom", true);
    }
    if (object.has("header") && allowOverride) {
        headerObj.put("header", object.optString("header"));
        headerObj.put("custom", true);
    }
    headerObj.merge(display.getHeaderConfig(), !allowOverride);
    footerObj.merge(display.getFooterConfig().put("footer", object.optString("strlevel", format.format(object.getInt("level")))), !allowOverride);
    construct.put("exclude", object.optBoolean("exclude"));
    construct.put("header", headerObj).put("footer", footerObj);
    construct.put("exclude", object.optBoolean("exclude"));
    construct.put("custom", object.optJsonObject("custom"));
    value.construct(construct);
    return value;
}
Also used : NullLevelheadTag(cc.hyperium.mods.levelhead.renderer.NullLevelheadTag) LevelheadTag(cc.hyperium.mods.levelhead.renderer.LevelheadTag) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder)

Example 4 with LevelheadJsonHolder

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

the class Levelhead method allowedTypes.

public HashMap<String, String> allowedTypes() {
    List<String> keys = types.getKeys();
    HashMap<String, String> data = keys.stream().collect(Collectors.toMap(key -> key, key -> types.optJsonObject(key).optString("name"), (a, b) -> b, HashMap::new));
    LevelheadJsonHolder stats = paidData.optJsonObject("stats");
    stats.getKeys().stream().filter(s -> purchaseStatus.optBoolean(s)).forEach(s -> data.put(s, stats.optJsonObject(s).optString("name")));
    return data;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) DisplayManager(cc.hyperium.mods.levelhead.display.DisplayManager) LevelheadChatRenderer(cc.hyperium.mods.levelhead.renderer.LevelheadChatRenderer) MojangAuth(cc.hyperium.mods.levelhead.auth.MojangAuth) URL(java.net.URL) ChatColor(cc.hyperium.utils.ChatColor) CustomLevelheadCommand(cc.hyperium.mods.levelhead.command.CustomLevelheadCommand) HashMap(java.util.HashMap) LevelheadPurchaseStates(cc.hyperium.mods.levelhead.purchases.LevelheadPurchaseStates) Charset(java.nio.charset.Charset) Minecraft(net.minecraft.client.Minecraft) Multithreading(cc.hyperium.mods.sk1ercommon.Multithreading) Hyperium(cc.hyperium.Hyperium) Sk1erMod(cc.hyperium.mods.sk1ercommon.Sk1erMod) LevelheadDisplay(cc.hyperium.mods.levelhead.display.LevelheadDisplay) InvokeEvent(cc.hyperium.event.InvokeEvent) EventBus(cc.hyperium.event.EventBus) NullLevelheadTag(cc.hyperium.mods.levelhead.renderer.NullLevelheadTag) TickEvent(cc.hyperium.event.client.TickEvent) DecimalFormat(java.text.DecimalFormat) FileUtils(org.apache.commons.io.FileUtils) UUID(java.util.UUID) AboveHeadDisplay(cc.hyperium.mods.levelhead.display.AboveHeadDisplay) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) AbstractMod(cc.hyperium.mods.AbstractMod) java.awt(java.awt) IOUtils(org.apache.commons.io.IOUtils) LevelheadTag(cc.hyperium.mods.levelhead.renderer.LevelheadTag) List(java.util.List) DisplayConfig(cc.hyperium.mods.levelhead.display.DisplayConfig) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder) LevelheadCommand(cc.hyperium.mods.levelhead.command.LevelheadCommand) AboveHeadRenderer(cc.hyperium.mods.levelhead.renderer.AboveHeadRenderer) InputStream(java.io.InputStream) LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder)

Example 5 with LevelheadJsonHolder

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

the class LevelheadDisplay method getHeaderConfig.

public LevelheadJsonHolder getHeaderConfig() {
    LevelheadJsonHolder holder = new LevelheadJsonHolder();
    holder.put("chroma", config.isHeaderChroma());
    holder.put("rgb", config.isHeaderRgb());
    holder.put("red", config.getHeaderRed());
    holder.put("green", config.getHeaderGreen());
    holder.put("blue", config.getHeaderBlue());
    holder.put("alpha", config.getHeaderAlpha());
    holder.put("color", config.getHeaderColor());
    holder.put("header", config.getCustomHeader() + ": ");
    return holder;
}
Also used : LevelheadJsonHolder(cc.hyperium.mods.levelhead.util.LevelheadJsonHolder)

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