diff options
author | nea <nea@nea.moe> | 2023-01-19 15:45:18 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-01-19 15:45:18 +0100 |
commit | 3ebdac823fdb5dcbbbf80b36c9370878a1cbb1d2 (patch) | |
tree | e754ecf7ff8a9ae6b361781e12c14b7b0f934fd7 | |
parent | 82d3c94ddd024d38bd594787c2779a3cc1935462 (diff) | |
download | NotEnoughUpdates-pvlevel.tar.gz NotEnoughUpdates-pvlevel.tar.bz2 NotEnoughUpdates-pvlevel.zip |
Make use of new collections api in collectionspagepvlevel
6 files changed, 294 insertions, 419 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java index c19c4826..c7c118bb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java @@ -24,6 +24,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import java.io.UnsupportedEncodingException; +import java.math.BigInteger; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Set; @@ -71,7 +72,17 @@ public class StringUtils { return shortNumberFormat(n, 0); } - private static final char[] c = new char[] { 'k', 'm', 'b', 't' }; + private static final char[] sizeSuffix = new char[]{'k', 'm', 'b', 't'}; + + public static String shortNumberFormat(BigInteger bigInteger) { + BigInteger THOUSAND = BigInteger.valueOf(1000); + int i = -1; + while (bigInteger.compareTo(THOUSAND) > 0 && i < sizeSuffix.length) { + bigInteger = bigInteger.divide(THOUSAND); + i++; + } + return bigInteger.toString() + (i == -1 ? "" : sizeSuffix[i]); + } public static String shortNumberFormat(double n, int iteration) { if (n < 1000) { @@ -84,7 +95,7 @@ public class StringUtils { double d = ((long) n / 100) / 10.0; boolean isRound = (d * 10) % 10 == 0; - return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + c[iteration] : shortNumberFormat(d, iteration + 1); + return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + sizeSuffix[iteration] : shortNumberFormat(d, iteration + 1); } public static String urlEncode(String something) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java index e2e40ed1..45d9370b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; +import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.item.ItemStack; @@ -35,9 +36,11 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.IOException; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; import java.text.NumberFormat; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -88,7 +91,8 @@ public class CollectionsPage extends GuiProfileViewerPage { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_cols); Utils.drawTexturedRect(guiLeft, guiTop, getInstance().sizeX, getInstance().sizeY, GL11.GL_NEAREST); - JsonObject collectionInfo = GuiProfileViewer.getProfile().getCollectionInfo(GuiProfileViewer.getProfileId()); + ProfileCollectionInfo collectionInfo = + GuiProfileViewer.getProfile().getCollectionInfo(GuiProfileViewer.getProfileId()); if (collectionInfo == null) { Utils.drawStringCentered( EnumChatFormatting.RED + "Collection API not enabled!", @@ -198,110 +202,114 @@ public class CollectionsPage extends GuiProfileViewerPage { 4210752 ); - JsonObject minionTiers = collectionInfo.get("minion_tiers").getAsJsonObject(); - JsonObject collectionTiers = collectionInfo.get("collection_tiers").getAsJsonObject(); - JsonObject maxAmounts = collectionInfo.get("max_amounts").getAsJsonObject(); - JsonObject totalAmounts = collectionInfo.get("total_amounts").getAsJsonObject(); - JsonObject personalAmounts = collectionInfo.get("personal_amounts").getAsJsonObject(); - if (collections != null) { for (int i = page * 20, j = 0; i < Math.min((page + 1) * 20, collections.size()); i++, j++) { String collection = collections.get(i); - if (collection != null) { - ItemStack collectionItem = ProfileViewer.getCollectionToCollectionDisplayMap().get(collection); - if (collectionItem != null) { - int xIndex = j % COLLS_XCOUNT; - int yIndex = j / COLLS_XCOUNT; - - float x = 39 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; - float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; - - String tierString; - int tier = (int) Utils.getElementAsFloat(collectionTiers.get(collection), 0); - if (tier > 20 || tier <= 0) { - tierString = String.valueOf(tier); - } else { - tierString = romans[tier-1]; - } - float amount = Utils.getElementAsFloat(totalAmounts.get(collection), 0); - float maxAmount = Utils.getElementAsFloat(maxAmounts.get(collection), 0); - Color color = new Color(128, 128, 128, 255); - int tierStringColour = color.getRGB(); - float completedness = 0; - if (maxAmount > 0) { - completedness = amount / maxAmount; - } - completedness = Math.min(1, completedness); - if (maxAmounts.has(collection) && completedness >= 1) { - tierStringColour = new Color(255, 215, 0).getRGB(); - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect( - guiLeft + x, - guiTop + y, - 20, - 20 * (1 - completedness), - 0, - 20 / 256f, - 0, - 20 * (1 - completedness) / 256f, - GL11.GL_NEAREST - ); - GlStateManager.color(1, 185 / 255f, 0, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect( - guiLeft + x, - guiTop + y + 20 * (1 - completedness), - 20, - 20 * (completedness), - 0, - 20 / 256f, - 20 * (1 - completedness) / 256f, - 20 / 256f, - GL11.GL_NEAREST + if (collection == null) { + continue; + } + ProfileCollectionInfo.CollectionInfo thisCollection = collectionInfo.getCollections().get(collection); + if (thisCollection == null) { + Utils.showOutdatedRepoNotification(); + continue; + } + ItemStack collectionItem = ProfileViewer.getCollectionToCollectionDisplayMap().get(collection); + if (collectionItem == null) { + continue; + } + int xIndex = j % COLLS_XCOUNT; + int yIndex = j / COLLS_XCOUNT; + + float x = 39 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; + float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; + + String tierString; + int tier = thisCollection.getUnlockedTiers().size(); + if (tier > 20 || tier == 0) { + tierString = String.valueOf(tier); + } else { + tierString = romans[tier - 1]; + } + BigInteger amount = thisCollection.getTotalCollectionCount(); + BigInteger maxAmount = BigInteger.valueOf(thisCollection.getCollection().getTiers().get(thisCollection.getCollection().getTiers().size() - 1).getAmountRequired()); + Color color = new Color(128, 128, 128, 255); + int tierStringColour = color.getRGB(); + float completedness = 0; + if (maxAmount.compareTo(BigInteger.ZERO) > 0) { + if (amount.compareTo(maxAmount) > 0) { + completedness = 1; + } else { + completedness = amount.floatValue() / maxAmount.floatValue(); + } + } + if (completedness >= 1) { + tierStringColour = new Color(255, 215, 0).getRGB(); + } + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + Utils.drawTexturedRect( + guiLeft + x, + guiTop + y, + 20, + 20 * (1 - completedness), + 0, + 20 / 256f, + 0, + 20 * (1 - completedness) / 256f, + GL11.GL_NEAREST + ); + GlStateManager.color(1, 185 / 255f, 0, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + Utils.drawTexturedRect( + guiLeft + x, + guiTop + y + 20 * (1 - completedness), + 20, + 20 * (completedness), + 0, + 20 / 256f, + 20 * (1 - completedness) / 256f, + 20 / 256f, + GL11.GL_NEAREST + ); + Utils.drawItemStack(collectionItem, guiLeft + (int) x + 2, guiTop + (int) y + 2); + + if (mouseX > guiLeft + (int) x + 2 && mouseX < guiLeft + (int) x + 18) { + if (mouseY > guiTop + (int) y + 2 && mouseY < guiTop + (int) y + 18) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add( + collectionItem.getDisplayName() + + " " + + (completedness >= 1 ? EnumChatFormatting.GOLD : EnumChatFormatting.GRAY) + + tierString ); - Utils.drawItemStack(collectionItem, guiLeft + (int) x + 2, guiTop + (int) y + 2); - - if (mouseX > guiLeft + (int) x + 2 && mouseX < guiLeft + (int) x + 18) { - if (mouseY > guiTop + (int) y + 2 && mouseY < guiTop + (int) y + 18) { - tooltipToDisplay = new ArrayList<>(); - tooltipToDisplay.add( - collectionItem.getDisplayName() + - " " + - (completedness >= 1 ? EnumChatFormatting.GOLD : EnumChatFormatting.GRAY) + - tierString - ); - tooltipToDisplay.add( - "Collected: " + numberFormat.format(Utils.getElementAsFloat(personalAmounts.get(collection), 0)) - ); - tooltipToDisplay.add("Total Collected: " + numberFormat.format(amount)); - } - } - - GlStateManager.color(1, 1, 1, 1); - if (tier >= 0) { - Utils.drawStringCentered( - tierString, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, - guiTop + y - 4, - true, - tierStringColour - ); - } - - Utils.drawStringCentered( - StringUtils.shortNumberFormat(amount) + "", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, - guiTop + y + 26, - true, - color.getRGB() + tooltipToDisplay.add( + "Collected: " + numberFormat.format(thisCollection.getPersonalCollectionCount()) ); + tooltipToDisplay.add("Total Collected: " + numberFormat.format(amount)); } } + + GlStateManager.color(1, 1, 1, 1); + if (tier >= 0) { + Utils.drawStringCentered( + tierString, + Minecraft.getMinecraft().fontRendererObj, + guiLeft + x + 10, + guiTop + y - 4, + true, + tierStringColour + ); + } + + Utils.drawStringCentered( + StringUtils.shortNumberFormat(amount) + "", + Minecraft.getMinecraft().fontRendererObj, + guiLeft + x + 10, + guiTop + y + 26, + true, + color.getRGB() + ); } } @@ -317,97 +325,99 @@ public class CollectionsPage extends GuiProfileViewerPage { if (minions != null) { for (int i = page * 20, j = 0; i < Math.min((page + 1) * 20, minions.size()); i++, j++) { String minion = minions.get(i); - if (minion != null) { - JsonObject misc = Constants.MISC; - float MAX_MINION_TIER = Utils.getElementAsFloat(Utils.getElement(misc, "minions." + minion + "_GENERATOR"), 11); - - int tier = (int) Utils.getElementAsFloat(minionTiers.get(minion), 0); - JsonObject minionJson; - if (tier == 0) { - minionJson = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(minion + "_GENERATOR_1"); - } else { - minionJson = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(minion + "_GENERATOR_" + tier); - } + if (minion == null) { + continue; + } + JsonObject misc = Constants.MISC; + float MAX_MINION_TIER = Utils.getElementAsFloat(Utils.getElement(misc, "minions." + minion + "_GENERATOR"), 11); - if (minionJson != null) { - int xIndex = j % COLLS_XCOUNT; - int yIndex = j / COLLS_XCOUNT; - - float x = 231 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; - float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; - - String tierString; - - if (tier - 1 >= romans.length || tier - 1 < 0) { - tierString = String.valueOf(tier); - } else { - tierString = romans[tier - 1]; - } - - Color color = new Color(128, 128, 128, 255); - int tierStringColour = color.getRGB(); - float completedness = tier / MAX_MINION_TIER; - - completedness = Math.min(1, completedness); - if (completedness >= 1) { - tierStringColour = new Color(255, 215, 0).getRGB(); - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect( - guiLeft + x, - guiTop + y, - 20, - 20 * (1 - completedness), - 0, - 20 / 256f, - 0, - 20 * (1 - completedness) / 256f, - GL11.GL_NEAREST - ); - GlStateManager.color(1, 185 / 255f, 0, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect( - guiLeft + x, - guiTop + y + 20 * (1 - completedness), - 20, - 20 * (completedness), - 0, - 20 / 256f, - 20 * (1 - completedness) / 256f, - 20 / 256f, - GL11.GL_NEAREST - ); + int tier = collectionInfo.getCraftedGenerators().getOrDefault(minion, 0); + JsonObject minionJson; + if (tier == 0) { + minionJson = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(minion + "_GENERATOR_1"); + } else { + minionJson = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(minion + "_GENERATOR_" + tier); + } - Utils.drawItemStack( - NotEnoughUpdates.INSTANCE.manager.jsonToStack(minionJson), - guiLeft + (int) x + 2, - guiTop + (int) y + 2 - ); + if (minionJson == null) { + continue; + } + int xIndex = j % COLLS_XCOUNT; + int yIndex = j / COLLS_XCOUNT; + + float x = 231 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; + float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; + + String tierString; + + if (tier - 1 >= romans.length || tier - 1 < 0) { + tierString = String.valueOf(tier); + } else { + tierString = romans[tier - 1]; + } + + Color color = new Color(128, 128, 128, 255); + int tierStringColour = color.getRGB(); + float completedness = tier / MAX_MINION_TIER; + + completedness = Math.min(1, completedness); + if (completedness >= 1) { + tierStringColour = new Color(255, 215, 0).getRGB(); + } - if (mouseX > guiLeft + (int) x + 2 && mouseX < guiLeft + (int) x + 18) { - if (mouseY > guiTop + (int) y + 2 && mouseY < guiTop + (int) y + 18) { - tooltipToDisplay = - NotEnoughUpdates.INSTANCE.manager - .jsonToStack(minionJson) - .getTooltip(Minecraft.getMinecraft().thePlayer, false); - } - } - - GlStateManager.color(1, 1, 1, 1); - if (tier >= 0) { - Utils.drawStringCentered( - tierString, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, - guiTop + y - 4, - true, - tierStringColour - ); - } + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + Utils.drawTexturedRect( + guiLeft + x, + guiTop + y, + 20, + 20 * (1 - completedness), + 0, + 20 / 256f, + 0, + 20 * (1 - completedness) / 256f, + GL11.GL_NEAREST + ); + GlStateManager.color(1, 185 / 255f, 0, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + Utils.drawTexturedRect( + guiLeft + x, + guiTop + y + 20 * (1 - completedness), + 20, + 20 * (completedness), + 0, + 20 / 256f, + 20 * (1 - completedness) / 256f, + 20 / 256f, + GL11.GL_NEAREST + ); + + Utils.drawItemStack( + NotEnoughUpdates.INSTANCE.manager.jsonToStack(minionJson), + guiLeft + (int) x + 2, + guiTop + (int) y + 2 + ); + + if (mouseX > guiLeft + (int) x + 2 && mouseX < guiLeft + (int) x + 18) { + if (mouseY > guiTop + (int) y + 2 && mouseY < guiTop + (int) y + 18) { + tooltipToDisplay = + NotEnoughUpdates.INSTANCE.manager + .jsonToStack(minionJson) + .getTooltip(Minecraft.getMinecraft().thePlayer, false); } } + + GlStateManager.color(1, 1, 1, 1); + if (tier >= 0) { + Utils.drawStringCentered( + tierString, + Minecraft.getMinecraft().fontRendererObj, + guiLeft + x + 10, + guiTop + y - 4, + true, + tierStringColour + ); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java index 64ea0f6c..5b5c6cda 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java @@ -293,7 +293,6 @@ public class PlayerStats { private static Stats getSetBonuses( Stats stats, JsonObject inventoryInfo, - JsonObject collectionInfo, Map<String, ProfileViewer.Level> skyblockInfo, JsonObject profile ) { @@ -304,17 +303,11 @@ public class PlayerStats { String fullset = getFullset(armor, -1); if (fullset != null) { + // TODO @nea: repo based stat delivery? (with lisp) switch (fullset) { case "LAPIS_ARMOR_": bonuses.addStat(HEALTH, 60); break; - case "EMERALD_ARMOR_": - { - int bonus = (int) Math.floor(Utils.getElementAsFloat(Utils.getElement(collectionInfo, "EMERALD"), 0) / 3000); - bonuses.addStat(HEALTH, bonus); - bonuses.addStat(DEFENCE, bonus); - } - break; case "FAIRY_": bonuses.addStat(HEALTH, Utils.getElementAsFloat(Utils.getElement(profile, "fairy_souls_collected"), 0)); break; @@ -622,11 +615,10 @@ public class PlayerStats { public static Stats getStats( Map<String, ProfileViewer.Level> skyblockInfo, JsonObject inventoryInfo, - JsonObject collectionInfo, JsonObject petsInfo, JsonObject profile ) { - if (skyblockInfo == null || inventoryInfo == null || collectionInfo == null || profile == null) return null; + if (skyblockInfo == null || inventoryInfo == null || profile == null) return null; JsonArray armor = Utils.getElement(inventoryInfo, "inv_armor").getAsJsonArray(); JsonArray inventory = Utils.getElement(inventoryInfo, "inv_contents").getAsJsonArray(); @@ -651,7 +643,7 @@ public class PlayerStats { stats = stats.add(passiveBonuses).add(armorBonuses).add(talismanBonuses).add(petBonus).add(hotmBonuses); - stats.add(getSetBonuses(stats, inventoryInfo, collectionInfo, skyblockInfo, profile)); + stats.add(getSetBonuses(stats, inventoryInfo, skyblockInfo, profile)); stats.scaleAll(getStatMult(inventoryInfo)); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index d1d2f553..48a4cfd2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -54,15 +54,14 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -659,7 +658,7 @@ public class ProfileViewer { private final HashMap<String, List<JsonObject>> coopProfileMap = new HashMap<>(); private final HashMap<String, Map<String, Level>> skyblockInfoCache = new HashMap<>(); private final HashMap<String, JsonObject> inventoryCacheMap = new HashMap<>(); - private final HashMap<String, JsonObject> collectionInfoMap = new HashMap<>(); + private final HashMap<String, CompletableFuture<ProfileCollectionInfo>> collectionInfoMap = new HashMap<>(); private final List<String> profileNames = new ArrayList<>(); private final HashMap<String, PlayerStats.Stats> stats = new HashMap<>(); private final HashMap<String, PlayerStats.Stats> passiveStats = new HashMap<>(); @@ -1086,6 +1085,10 @@ public class ProfileViewer { double skyblockLevel = getSkyblockLevel(profileName); EnumChatFormatting previousColor = EnumChatFormatting.WHITE; + if (Constants.SBLEVELS == null || !Constants.SBLEVELS.has("sblevel_colours")) { + Utils.showOutdatedRepoNotification(); + return EnumChatFormatting.WHITE; + } JsonObject sblevelColours = Constants.SBLEVELS.getAsJsonObject("sblevel_colours"); try { for (Map.Entry<String, JsonElement> stringJsonElementEntry : sblevelColours.entrySet()) { @@ -1336,69 +1339,62 @@ public class ProfileViewer { } public JsonObject getProfileInformation(String profileName) { + if (profileName == null) profileName = latestProfile; + if (profileMap.containsKey(profileName)) return profileMap.get(profileName); + JsonObject profile = getRawProfileInformation(profileName); + if (profile == null) return null; + if (!profile.has("members")) return null; + JsonObject members = profile.get("members").getAsJsonObject(); + if (!members.has(uuid)) return null; + JsonObject profileInfo = members.get(uuid).getAsJsonObject(); + if (profile.has("banking")) { + profileInfo.add("banking", profile.get("banking").getAsJsonObject()); + } + if (profile.has("game_mode")) { + profileInfo.add("game_mode", profile.get("game_mode")); + } + if (profile.has("community_upgrades")) { + profileInfo.add("community_upgrades", profile.get("community_upgrades")); + } + profileMap.put(profileName, profileInfo); + return profileInfo; + } + + public JsonObject getRawProfileInformation(String profileName) { JsonArray playerInfo = getSkyblockProfiles(() -> {}); if (playerInfo == null) return null; if (profileName == null) profileName = latestProfile; - if (profileMap.containsKey(profileName)) return profileMap.get(profileName); - for (int i = 0; i < skyblockProfiles.size(); i++) { - if (!skyblockProfiles.get(i).isJsonObject()) { + for (JsonElement skyblockProfile : skyblockProfiles) { + if (!skyblockProfile.isJsonObject()) { skyblockProfiles = null; return null; } - JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); - if (profile.get("cute_name").getAsString().equalsIgnoreCase(profileName)) { - if (!profile.has("members")) return null; - JsonObject members = profile.get("members").getAsJsonObject(); - if (!members.has(uuid)) continue; - JsonObject profileInfo = members.get(uuid).getAsJsonObject(); - if (profile.has("banking")) { - profileInfo.add("banking", profile.get("banking").getAsJsonObject()); - } - if (profile.has("game_mode")) { - profileInfo.add("game_mode", profile.get("game_mode")); - } - if (profile.has("community_upgrades")) { - profileInfo.add("community_upgrades", profile.get("community_upgrades")); - } - profileInfo.add("members", members); - profileMap.put(profileName, profileInfo); - return profileInfo; - } + if (skyblockProfile.getAsJsonObject().get("cute_name").getAsString().equalsIgnoreCase(profileName)) + return skyblockProfile.getAsJsonObject(); } - return null; } public List<JsonObject> getCoopProfileInformation(String profileName) { - JsonArray playerInfo = getSkyblockProfiles(() -> {}); - if (playerInfo == null) return null; if (profileName == null) profileName = latestProfile; if (coopProfileMap.containsKey(profileName)) return coopProfileMap.get(profileName); - - for (int i = 0; i < skyblockProfiles.size(); i++) { - if (!skyblockProfiles.get(i).isJsonObject()) { - skyblockProfiles = null; - return null; - } - JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); - if (profile.get("cute_name").getAsString().equalsIgnoreCase(profileName)) { - if (!profile.has("members")) return null; - JsonObject members = profile.get("members").getAsJsonObject(); - if (!members.has(uuid)) return null; - List<JsonObject> coopList = new ArrayList<>(); - for (Map.Entry<String, JsonElement> islandMember : members.entrySet()) { - if (!islandMember.getKey().equals(uuid)) { - JsonObject coopProfileInfo = islandMember.getValue().getAsJsonObject(); - coopList.add(coopProfileInfo); - } - } - coopProfileMap.put(profileName, coopList); - return coopList; + JsonObject profile = getRawProfileInformation(profileName); + if (profile == null) return null; + + if (!profile.has("members")) return null; + JsonObject members = profile.get("members").getAsJsonObject(); + if (!members.has(uuid)) return null; + List<JsonObject> coopList = new ArrayList<>(); + for (Map.Entry<String, JsonElement> islandMember : members.entrySet()) { + if (!islandMember.getKey().equals(uuid)) { + JsonObject coopProfileInfo = islandMember.getValue().getAsJsonObject(); + coopList.add(coopProfileInfo); } } + coopProfileMap.put(profileName, coopList); + return coopList; - return null; } public void resetCache() { @@ -1794,151 +1790,15 @@ public class ProfileViewer { return null; } - public ProfileCollectionInfo getCollectionInfoNew(String profileName, String uuid) - throws ExecutionException, InterruptedException { - if (collectionInfoHashMap.containsKey(profileName)) { - return collectionInfoHashMap.get(profileName).getNow(null); - } - JsonObject profileInfo = getProfileInformation(profileName); - CompletableFuture<ProfileCollectionInfo> collectionData = ProfileCollectionInfo.getCollectionData( - profileInfo, - uuid - ); - if(collectionData.isDone()) { - collectionInfoHashMap.put(profileName, collectionData); - return collectionData.get(); - } - return null; - } - - public JsonObject getCollectionInfo(String profileName) { - JsonObject profileInfo = getProfileInformation(profileName); - if (profileInfo == null) return null; - JsonObject resourceCollectionInfo = getResourceCollectionInformation(); - if (resourceCollectionInfo == null) return null; - if (profileName == null) profileName = latestProfile; - if (collectionInfoMap.containsKey(profileName)) return collectionInfoMap.get(profileName); - - List<JsonObject> coopMembers = getCoopProfileInformation(profileName); - JsonElement unlocked_coll_tiers_element = Utils.getElement(profileInfo, "unlocked_coll_tiers"); - JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); - JsonObject fakeMember = new JsonObject(); - fakeMember.add("crafted_generators", crafted_generators_element); - coopMembers.add(coopMembers.size(), fakeMember); - JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); - - if (unlocked_coll_tiers_element == null || collectionInfoElement == null) { - return null; - } - - JsonObject collectionInfo = new JsonObject(); - JsonObject collectionTiers = new JsonObject(); - JsonObject minionTiers = new JsonObject(); - JsonObject personalAmounts = new JsonObject(); - JsonObject totalAmounts = new JsonObject(); - - if (collectionInfoElement.isJsonObject()) { - personalAmounts = collectionInfoElement.getAsJsonObject(); - } - - for (Map.Entry<String, JsonElement> entry : personalAmounts.entrySet()) { - totalAmounts.addProperty(entry.getKey(), entry.getValue().getAsLong()); - } - - List<JsonObject> coopProfiles = getCoopProfileInformation(profileName); - if (coopProfiles != null) { - for (JsonObject coopProfile : coopProfiles) { - JsonElement coopCollectionInfoElement = Utils.getElement(coopProfile, "collection"); - if (coopCollectionInfoElement != null && coopCollectionInfoElement.isJsonObject()) { - for (Map.Entry<String, JsonElement> entry : coopCollectionInfoElement.getAsJsonObject().entrySet()) { - float existing = Utils.getElementAsFloat(totalAmounts.get(entry.getKey()), 0); - totalAmounts.addProperty(entry.getKey(), existing + entry.getValue().getAsLong()); - } - } - } - } - - if (unlocked_coll_tiers_element.isJsonArray()) { - JsonArray unlocked_coll_tiers = unlocked_coll_tiers_element.getAsJsonArray(); - for (int i = 0; i < unlocked_coll_tiers.size(); i++) { - String unlocked = unlocked_coll_tiers.get(i).getAsString(); - - Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); - - if (matcher.find()) { - String tier_str = matcher.group(1); - int tier = Integer.parseInt(tier_str); - String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); - if (!collectionTiers.has(coll) || collectionTiers.get(coll).getAsInt() < tier) { - collectionTiers.addProperty(coll, tier); - } - } - } - } - for (JsonObject current_member_info : coopMembers) { - if ( - !current_member_info.has("crafted_generators") || !current_member_info.get("crafted_generators").isJsonArray() - ) continue; - JsonArray crafted_generators = Utils.getElement(current_member_info, "crafted_generators").getAsJsonArray(); - for (int j = 0; j < crafted_generators.size(); j++) { - String unlocked = crafted_generators.get(j).getAsString(); - Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); - if (matcher.find()) { - String tierString = matcher.group(1); - int tier = Integer.parseInt(tierString); - String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); - if (!minionTiers.has(coll) || minionTiers.get(coll).getAsInt() < tier) { - minionTiers.addProperty(coll, tier); - } - } - } - } - - JsonObject maxAmount = new JsonObject(); - JsonObject updatedCollectionTiers = new JsonObject(); - for (Map.Entry<String, JsonElement> totalAmountsEntry : totalAmounts.entrySet()) { - String collName = totalAmountsEntry.getKey(); - int collTier = (int) Utils.getElementAsFloat(collectionTiers.get(collName), 0); - - int currentAmount = (int) Utils.getElementAsFloat(totalAmounts.get(collName), 0); - if (currentAmount > 0) { - for (Map.Entry<String, JsonElement> resourceEntry : resourceCollectionInfo.entrySet()) { - JsonElement tiersElement = Utils.getElement(resourceEntry.getValue(), "items." + collName + ".tiers"); - if (tiersElement != null && tiersElement.isJsonArray()) { - JsonArray tiers = tiersElement.getAsJsonArray(); - int maxTierAcquired = -1; - int maxAmountRequired = -1; - for (int i = 0; i < tiers.size(); i++) { - JsonObject tierInfo = tiers.get(i).getAsJsonObject(); - int tier = tierInfo.get("tier").getAsInt(); - int amountRequired = tierInfo.get("amountRequired").getAsInt(); - if (currentAmount >= amountRequired) { - maxTierAcquired = tier; - } - maxAmountRequired = amountRequired; - } - if (maxTierAcquired >= 0) { - updatedCollectionTiers.addProperty(collName, maxTierAcquired); - } - maxAmount.addProperty(collName, maxAmountRequired); - } - } - } - } - - for (Map.Entry<String, JsonElement> collectionTiersEntry : updatedCollectionTiers.entrySet()) { - collectionTiers.add(collectionTiersEntry.getKey(), collectionTiersEntry.getValue()); - } - - collectionInfo.add("minion_tiers", minionTiers); - collectionInfo.add("max_amounts", maxAmount); - collectionInfo.add("personal_amounts", personalAmounts); - collectionInfo.add("total_amounts", totalAmounts); - collectionInfo.add("collection_tiers", collectionTiers); - - collectionInfoMap.put(profileName, collectionInfo); - - return collectionInfo; + public ProfileCollectionInfo getCollectionInfo(String profileName) { + JsonObject rawProfileInformation = getRawProfileInformation(profileName); + if (rawProfileInformation == null) return null; + CompletableFuture<ProfileCollectionInfo> future = + collectionInfoMap.computeIfAbsent( + profileName.toLowerCase(Locale.ROOT), + ignored -> ProfileCollectionInfo.getCollectionData(rawProfileInformation, uuid) + ); + return future.getNow(null); } public PlayerStats.Stats getPassiveStats(String profileName) { @@ -1967,7 +1827,6 @@ public class ProfileViewer { PlayerStats.Stats stats = PlayerStats.getStats( getSkyblockInfo(profileName), getInventoryInfo(profileName), - getCollectionInfo(profileName), getPetsInfo(profileName), profileInfo ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java index 559966f7..33608dff 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java @@ -19,9 +19,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.level.task; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.level.LevelPage; @@ -34,7 +32,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; public class CoreTaskLevel { @@ -100,28 +97,20 @@ public class CoreTaskLevel { int sbXpMinionTier = -1; // keeping at -1 here because cobblestone 1 minion XP isn't included for some reason? JsonObject minionXp = Constants.MISC.get("minionXp").getAsJsonObject(); int collectionsXp = coreTask.get("collections_xp").getAsInt(); - try { - ProfileCollectionInfo collection; - collection = levelPage.getProfile().getCollectionInfoNew( - levelPage.getProfileId(), - levelPage.getProfile().getUuid() - ); - if (collection != null) { - for (Map.Entry<String, ProfileCollectionInfo.CollectionInfo> stringCollectionInfoEntry : collection - .getCollections() - .entrySet()) { - ProfileCollectionInfo.CollectionInfo value = stringCollectionInfoEntry.getValue(); - sbXpCollection = value.getUnlockedTiers().size() * collectionsXp; - } - for (Map.Entry<String, Integer> stringIntegerEntry : collection.getCraftedGenerators().entrySet()) { - String key = stringIntegerEntry.getKey(); - int value = stringIntegerEntry.getValue(); - for (int i = 1; i <= value; i++) { - if (minionXp.has(i + "")) sbXpMinionTier += minionXp.get(i + "").getAsInt(); - } - } + ProfileCollectionInfo collection; + collection = levelPage.getProfile().getCollectionInfo( + levelPage.getProfileId() + ); + if (collection != null) { + for (Map.Entry<String, ProfileCollectionInfo.CollectionInfo> stringCollectionInfoEntry : collection + .getCollections() + .entrySet()) { + ProfileCollectionInfo.CollectionInfo value = stringCollectionInfoEntry.getValue(); + sbXpCollection = value.getUnlockedTiers().size() * collectionsXp; + } + for (Integer tier : collection.getCraftedGenerators().values()) { + if (minionXp.has(tier + "")) sbXpMinionTier += minionXp.get(tier + "").getAsInt(); } - } catch (ExecutionException | InterruptedException e) { } List<String> lore = new ArrayList<>(); @@ -131,7 +120,8 @@ public class CoreTaskLevel { lore.add(levelPage.buildLore("Museum Progression", 0, 0, false )); - lore.add(levelPage.buildLore("Fairy Soul", + lore.add(levelPage.buildLore( + "Fairy Soul", sbXpGainedFairy, coreTask.get("fairy_souls").getAsInt(), false )); lore.add(levelPage.buildLore("Accessory Bag", diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt index 2f2419eb..b2c7fcec 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt @@ -23,8 +23,21 @@ import com.google.gson.JsonArray import com.google.gson.JsonObject import io.github.moulberry.notenoughupdates.NotEnoughUpdates import java.math.BigInteger -import java.util.* import java.util.concurrent.CompletableFuture +import kotlin.collections.List +import kotlin.collections.Map +import kotlin.collections.component1 +import kotlin.collections.component2 +import kotlin.collections.filter +import kotlin.collections.flatMap +import kotlin.collections.groupBy +import kotlin.collections.mapNotNull +import kotlin.collections.mapValues +import kotlin.collections.maxOf +import kotlin.collections.sumOf +import kotlin.collections.toList +import kotlin.collections.toMap +import kotlin.collections.toSet data class ProfileCollectionInfo( val collections: Map<String, CollectionInfo>, |