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.");
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations