From 8115922b37e375285c2a72dbdbb5d83fd942e27c Mon Sep 17 00:00:00 2001 From: kr45732 <52721908+kr45732@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:00:04 -0400 Subject: PV Overhaul (#708) Co-authored-by: Lulonaut --- .../moulberry/notenoughupdates/NEUManager.java | 68 +- .../notenoughupdates/core/util/StringUtils.java | 56 +- .../notenoughupdates/cosmetics/GuiCosmetics.java | 11 +- .../listener/ItemTooltipListener.java | 14 +- .../listener/ItemTooltipRngListener.java | 10 +- .../notenoughupdates/listener/RenderListener.java | 2 +- .../miscfeatures/CustomItemEffects.java | 4 +- .../miscfeatures/PetInfoOverlay.java | 29 +- .../miscfeatures/PowerStoneStatsDisplay.java | 17 +- .../notenoughupdates/miscgui/TradeWindow.java | 35 +- .../notenoughupdates/miscgui/hex/GuiCustomHex.java | 19 +- .../overlays/CrystalHollowOverlay.java | 8 +- .../notenoughupdates/profileviewer/BasicPage.java | 159 +-- .../notenoughupdates/profileviewer/BingoPage.java | 14 +- .../profileviewer/CollectionsPage.java | 42 +- .../profileviewer/CrimsonIslePage.java | 45 +- .../profileviewer/DungeonPage.java | 184 +-- .../notenoughupdates/profileviewer/ExtraPage.java | 81 +- .../profileviewer/GuiProfileViewer.java | 269 ++--- .../profileviewer/GuiProfileViewerPage.java | 8 + .../profileviewer/InventoriesPage.java | 72 +- .../notenoughupdates/profileviewer/MiningPage.java | 461 +++---- .../notenoughupdates/profileviewer/Panorama.java | 4 - .../notenoughupdates/profileviewer/PetsPage.java | 24 +- .../profileviewer/PlayerStats.java | 54 +- .../profileviewer/ProfileViewer.java | 1275 +------------------- .../profileviewer/ProfileViewerUtils.java | 65 +- .../profileviewer/SkyblockProfiles.java | 974 +++++++++++++++ .../profileviewer/bestiary/BestiaryPage.java | 24 +- .../profileviewer/level/LevelPage.java | 91 +- .../profileviewer/level/task/CoreTaskLevel.java | 27 +- .../profileviewer/level/task/DungeonTaskLevel.java | 37 +- .../profileviewer/level/task/EssenceTaskLevel.java | 9 +- .../profileviewer/level/task/EventTaskLevel.java | 9 +- .../profileviewer/level/task/GuiTaskLevel.java | 30 + .../profileviewer/level/task/MiscTaskLevel.java | 20 +- .../level/task/SkillRelatedTaskLevel.java | 40 +- .../profileviewer/level/task/SlayingTaskLevel.java | 40 +- .../profileviewer/level/task/StoryTaskLevel.java | 9 +- .../profileviewer/trophy/TrophyFishPage.java | 27 +- .../weight/lily/LilySkillsWeight.java | 5 +- .../weight/senither/SenitherSkillsWeight.java | 3 +- .../profileviewer/weight/weight/Weight.java | 4 +- .../notenoughupdates/recipes/EssenceUpgrades.java | 2 +- .../notenoughupdates/recipes/MobLootRecipe.java | 3 +- .../moulberry/notenoughupdates/util/ItemUtils.java | 3 +- .../notenoughupdates/util/ProfileApiSyncer.java | 10 +- .../notenoughupdates/util/XPInformation.java | 5 +- 48 files changed, 1898 insertions(+), 2504 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/GuiTaskLevel.java (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index a5bea05d..6b68fccf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -39,7 +39,6 @@ import io.github.moulberry.notenoughupdates.util.ApiUtil; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery; import io.github.moulberry.notenoughupdates.util.ItemUtils; -import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; @@ -49,7 +48,6 @@ import net.minecraft.inventory.ContainerChest; import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTException; import net.minecraft.nbt.NBTTagCompound; @@ -63,7 +61,6 @@ import javax.net.ssl.HttpsURLConnection; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -143,7 +140,6 @@ public class NEUManager { public File configLocation; public File repoLocation; - public File configFile; public KatSitterOverlay katSitterOverlay; @@ -162,24 +158,6 @@ public class NEUManager { repoLocation.mkdir(); } - public String getCurrentProfile() { - return SBInfo.getInstance().currentProfile; - } - - public T getJsonFromFile(File file, Class clazz) { - try ( - BufferedReader reader = new BufferedReader(new InputStreamReader( - new FileInputStream(file), - StandardCharsets.UTF_8 - )) - ) { - T obj = gson.fromJson(reader, clazz); - return obj; - } catch (Exception e) { - return null; - } - } - /** * Parses a file in to a JsonObject. */ @@ -738,17 +716,6 @@ public class NEUManager { return inputWithoutLastChar + incrementedLastChar; } - public JsonObject getJsonFromItemBytes(String item_bytes) { - try { - NBTTagCompound tag = - CompressedStreamTools.readCompressed(new ByteArrayInputStream(Base64.getDecoder().decode(item_bytes))); - //System.out.println(tag.toString()); - return getJsonFromNBT(tag); - } catch (IOException e) { - return null; - } - } - public static String getUUIDFromNBT(NBTTagCompound tag) { String uuid = null; if (tag != null && tag.hasKey("ExtraAttributes", 10)) { @@ -778,16 +745,6 @@ public class NEUManager { return null; } - /** - * Replaced with {@link #createItemResolutionQuery()} - */ - @Deprecated - public String getInternalnameFromNBT(NBTTagCompound tag) { - return createItemResolutionQuery() - .withItemNBT(tag) - .resolveInternalName(); - } - public String[] getLoreFromNBT(NBTTagCompound tag) { return ItemUtils.getLore(tag).toArray(new String[0]); } @@ -806,7 +763,9 @@ public class NEUManager { if (id == 141) id = 391; //for some reason hypixel thinks carrots have id 141 - String internalname = getInternalnameFromNBT(tag); + String internalname = createItemResolutionQuery() + .withItemNBT(tag) + .resolveInternalName(); if (internalname == null) return null; NBTTagCompound display = tag.getCompoundTag("display"); @@ -818,8 +777,6 @@ public class NEUManager { itemid = itemMc.getRegistryName(); } String displayName = display.getString("Name"); - String[] info = new String[0]; - String clickcommand = ""; JsonObject item = new JsonObject(); item.addProperty("internalname", internalname); @@ -1231,25 +1188,6 @@ public class NEUManager { return json; } - public boolean writeItemJson( - String internalname, String itemid, String displayName, String[] lore, String crafttext, - String infoType, String[] info, String clickcommand, int damage, NBTTagCompound nbttag - ) { - return writeItemJson( - new JsonObject(), - internalname, - itemid, - displayName, - lore, - crafttext, - infoType, - info, - clickcommand, - damage, - nbttag - ); - } - public boolean writeItemJson( JsonObject base, String internalname, String itemid, String displayName, String[] lore, String crafttext, String infoType, String[] info, String clickcommand, int damage, NBTTagCompound nbttag 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 ec50633f..e59a6a14 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 @@ -19,18 +19,14 @@ package io.github.moulberry.notenoughupdates.core.util; -import com.google.common.collect.Sets; -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; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Locale; public class StringUtils { - public static final Set PROTOCOLS = Sets.newHashSet("http", "https"); + private final static DecimalFormat TENTHS_DECIMAL_FORMAT = new DecimalFormat("#.#"); + public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US); public static String cleanColour(String in) { return in.replaceAll("(?i)\\u00A7.", ""); @@ -40,24 +36,6 @@ public class StringUtils { return in.replaceAll("(?i)\\u00A7[0-9a-f]", "\u00A7r"); } - public static String trimToWidth(String str, int len) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - String trim = fr.trimStringToWidth(str, len); - - if (str.length() != trim.length() && !trim.endsWith(" ")) { - char next = str.charAt(trim.length()); - if (next != ' ') { - String[] split = trim.split(" "); - String last = split[split.length - 1]; - if (last.length() < 8) { - trim = trim.substring(0, trim.length() - last.length()); - } - } - } - - return trim; - } - public static String substringBetween(String str, String open, String close) { return org.apache.commons.lang3.StringUtils.substringBetween(str, open, close); } @@ -99,22 +77,6 @@ public class StringUtils { return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + sizeSuffix[iteration] : shortNumberFormat(d, iteration + 1); } - public static String urlEncode(String something) { - try { - return URLEncoder.encode(something, StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); // UTF 8 should always be present - } - } - - /** - * taken and modified from https://stackoverflow.com/a/23326014/5507634 - */ - public static String replaceLast(String string, String toReplace, String replacement) { - int start = string.lastIndexOf(toReplace); - return string.substring(0, start) + replacement + string.substring(start + toReplace.length()); - } - public static String removeLastWord(String string, String splitString) { try { String[] split = string.split(splitString); @@ -143,4 +105,12 @@ public class StringUtils { } return true; } + + public static String formatToTenths(Number num) { + return TENTHS_DECIMAL_FORMAT.format(num); + } + + public static String formatNumber(Number num) { + return NUMBER_FORMAT.format(num); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java index cacae83b..3dbd52a5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java @@ -49,11 +49,12 @@ import java.util.HashMap; import java.util.List; import java.util.Random; +import static io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer.pv_bg; +import static io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer.pv_dropdown; +import static io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer.pv_elements; + public class GuiCosmetics extends GuiScreen { - public static final ResourceLocation pv_bg = new ResourceLocation("notenoughupdates:pv_bg.png"); - public static final ResourceLocation pv_dropdown = new ResourceLocation("notenoughupdates:pv_dropdown.png"); public static final ResourceLocation cosmetics_fg = new ResourceLocation("notenoughupdates:cosmetics_fg.png"); - public static final ResourceLocation pv_elements = new ResourceLocation("notenoughupdates:pv_elements.png"); private final GuiElementTextField unlockTextField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT); @@ -301,7 +302,6 @@ public class GuiCosmetics extends GuiScreen { } } - int index = 0; int displayingCapes = 0; for (CapeManager.CapeData cape : CapeManager.INSTANCE.getCapes()) { boolean equipable = CapeManager.INSTANCE.getAvailableCapes() == null || @@ -315,7 +315,6 @@ public class GuiCosmetics extends GuiScreen { float totalAvail = sizeX - 20; float xOffset = scroll * (totalNeeded - totalAvail); - index = 0; int displayIndex = 0; for (CapeManager.CapeData cape : CapeManager.INSTANCE.getCapes()) { boolean equipable = CapeManager.INSTANCE.getAvailableCapes() == null || @@ -447,7 +446,6 @@ public class GuiCosmetics extends GuiScreen { Minecraft.getMinecraft().displayWidth * (sizeX - 6) / width, Minecraft.getMinecraft().displayHeight ); - int index = 0; int displayingCapes = 0; for (CapeManager.CapeData capeData : CapeManager.INSTANCE.getCapes()) { boolean equipable = CapeManager.INSTANCE.getAvailableCapes() == null || @@ -461,7 +459,6 @@ public class GuiCosmetics extends GuiScreen { float totalAvail = sizeX - 20; float xOffset = scroll * (totalNeeded - totalAvail); - index = 0; int displayIndex = 0; for (CapeManager.CapeData capeData : CapeManager.INSTANCE.getCapes()) { boolean equipable = CapeManager.INSTANCE.getAvailableCapes() == null || diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java index 1e3dd7e0..01a173d3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java @@ -30,7 +30,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.MiscUtils; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.PetLeveling; import io.github.moulberry.notenoughupdates.util.Utils; @@ -57,7 +56,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -164,7 +162,6 @@ public class ItemTooltipListener { for (int k = 0; k < event.toolTip.size(); k++) { String line = event.toolTip.get(k); - boolean thisLineHasEnchants = false; if (line.endsWith(EnumChatFormatting.DARK_GRAY + "Reforge Stone") && NotEnoughUpdates.INSTANCE.config.tooltipTweaks.showReforgeStats) { @@ -299,7 +296,7 @@ public class ItemTooltipListener { if (reforgeCost >= 0) { String text = EnumChatFormatting.BLUE + "Apply Cost: " + EnumChatFormatting.GOLD + - NumberFormat.getNumberInstance().format(reforgeCost) + " coins"; + StringUtils.formatNumber(reforgeCost) + " coins"; newTooltip.add(""); newTooltip.add(text); } @@ -495,12 +492,11 @@ public class ItemTooltipListener { } } - NumberFormat format = NumberFormat.getInstance(Locale.US); String valueStringBIN1; String valueStringBIN2; if (totalValue >= 0) { valueStringBIN1 = EnumChatFormatting.YELLOW + "Value (BIN): "; - valueStringBIN2 = EnumChatFormatting.GOLD + format.format(totalValue) + " coins"; + valueStringBIN2 = EnumChatFormatting.GOLD + StringUtils.formatNumber(totalValue) + " coins"; } else { valueStringBIN1 = EnumChatFormatting.YELLOW + "Can't find BIN: "; valueStringBIN2 = missingItem; @@ -513,9 +509,9 @@ public class ItemTooltipListener { String plStringBIN; if (profitLossBIN >= 0) { - plStringBIN = prefix + "+" + format.format(profitLossBIN) + " coins"; + plStringBIN = prefix + "+" + StringUtils.formatNumber(profitLossBIN) + " coins"; } else { - plStringBIN = prefix + "-" + format.format(-profitLossBIN) + " coins"; + plStringBIN = prefix + "-" + StringUtils.formatNumber(-profitLossBIN) + " coins"; } String neu = EnumChatFormatting.YELLOW + "[NEU] "; @@ -526,7 +522,7 @@ public class ItemTooltipListener { } for (Map.Entry entry : itemValues.entrySet()) { - newTooltip.add(neu + entry.getKey() + prefix + "+" + format.format(entry.getValue().intValue())); + newTooltip.add(neu + entry.getKey() + prefix + "+" + StringUtils.formatNumber(entry.getValue().intValue())); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java index 06d294a3..10882b9b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java @@ -169,17 +169,17 @@ public class ItemTooltipRngListener { if (matcher.matches()) { String odds = matcher.group(1); int baseChance = calculateChance(matcher.group(2)); - String baseFormat = GuiProfileViewer.numberFormat.format(baseChance); + String baseFormat = StringUtils.formatNumber(baseChance); String fractionFormat = "§7(1/" + baseFormat + ")"; result = odds + " " + fractionFormat; } else if (matcherSelected.matches()) { String odds = matcherSelected.group(1); int baseChance = calculateChance(matcherSelected.group(2)); - String baseFormat = GuiProfileViewer.numberFormat.format(baseChance); + String baseFormat = StringUtils.formatNumber(baseChance); int increasedChance = calculateChance(matcherSelected.group(3)); - String increased = GuiProfileViewer.numberFormat.format(increasedChance); + String increased = StringUtils.formatNumber(increasedChance); String fractionFormat = "§7(§8§m1/" + baseFormat + "§r §71/" + increased + ")"; result = odds + " " + fractionFormat; @@ -304,8 +304,8 @@ public class ItemTooltipRngListener { int runsNeeded = (int) Math.floor((double) needed / (double) gainPerRun); int runsHaving = having / gainPerRun; - String runsNeededFormat = GuiProfileViewer.numberFormat.format(runsNeeded); - String runsHavingFormat = GuiProfileViewer.numberFormat.format(runsHaving); + String runsNeededFormat = StringUtils.formatNumber(runsNeeded); + String runsHavingFormat = StringUtils.formatNumber(runsHaving); String progressString = null; if (nextLineProgress) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 9b88a094..a31e54c4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -940,7 +940,7 @@ public class RenderListener { if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) { String username = tag.getCompoundTag("SkullOwner").getString("Name"); Utils.playPressSound(); - NotEnoughUpdates.profileViewer.getProfileByName(username, profile -> { + NotEnoughUpdates.profileViewer.loadPlayerByName(username, profile -> { if (profile == null) { Utils.addChatMessage("${RED}Invalid player name/API key. Maybe the API is down? Try /api new."); } else { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java index 55dedadf..72431697 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java @@ -715,7 +715,9 @@ public class CustomItemEffects { NBTTagCompound buildersItem = items.getCompoundTagAt(j); if (buildersItem.getKeySet().size() > 0) { String internalname = - NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(buildersItem.getCompoundTag("tag")); + NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery() + .withItemNBT(buildersItem.getCompoundTag("tag")) + .resolveInternalName(); if (internalname != null && internalname.equals("INFINIDIRT_WAND")) { return true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 693bb3e3..fadf8b1b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonNull; import com.google.gson.JsonObject; @@ -36,6 +37,7 @@ import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.overlays.TextOverlayStyle; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; +import io.github.moulberry.notenoughupdates.profileviewer.SkyblockProfiles; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.PetLeveling; import io.github.moulberry.notenoughupdates.util.ProfileApiSyncer; @@ -66,15 +68,11 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -283,15 +281,15 @@ public class PetInfoOverlay extends TextOverlay { } } - private static void getAndSetPet(ProfileViewer.Profile profile) { - Map skyblockInfo = profile.getSkyblockInfo(profile.getLatestProfile()); - JsonObject invInfo = profile.getInventoryInfo(profile.getLatestProfile()); - JsonObject profileInfo = profile.getProfileInformation(profile.getLatestProfile()); + private static void getAndSetPet(SkyblockProfiles profile) { + Map skyblockInfo = profile.getLatestProfile().getLevelingInfo(); + Map invInfo = profile.getLatestProfile().getInventoryInfo(); + JsonObject profileInfo = profile.getLatestProfile().getProfileJson(); if (invInfo != null && profileInfo != null) { JsonObject stats = profileInfo.get("stats").getAsJsonObject(); boolean hasBeastmasterCrest = false; Rarity currentBeastRarity = Rarity.COMMON; - for (JsonElement talisman : invInfo.get("talisman_bag").getAsJsonArray()) { + for (JsonElement talisman : invInfo.get("talisman_bag")) { if (talisman.isJsonNull()) continue; String internalName = talisman.getAsJsonObject().get("internalname").getAsString(); if (internalName.startsWith("BEASTMASTER_CREST")) { @@ -323,7 +321,9 @@ public class PetInfoOverlay extends TextOverlay { } } } - if (skyblockInfo != null) config.tamingLevel = (int) skyblockInfo.get("taming").level; + if (skyblockInfo != null && profile.getLatestProfile().skillsApiEnabled()) { + config.tamingLevel = (int) skyblockInfo.get("taming").level; + } //JsonObject petObject = profile.getPetsInfo(profile.getLatestProfile()); /*JsonObject petsJson = Constants.PETS; @@ -515,10 +515,9 @@ public class PetInfoOverlay extends TextOverlay { } public float getLevelPercent(Pet pet) { - DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); if (pet == null) return 0; try { - return Float.parseFloat(df.format(Math.min(pet.petLevel.getPercentageToNextLevel() * 100f, 100f))); + return Float.parseFloat(StringUtils.formatToTenths(Math.min(pet.petLevel.getPercentageToNextLevel() * 100f, 100f))); } catch (Exception ignored) { return 0; } @@ -1085,13 +1084,13 @@ public class PetInfoOverlay extends TextOverlay { public String roundFloat(float f) { if (f % 1 < 0.05f) { - return NumberFormat.getNumberInstance().format((int) f); + return StringUtils.formatNumber((int) f); } else { String s = Utils.floatToString(f, 1); if (s.contains(".")) { - return NumberFormat.getNumberInstance().format((int) f) + '.' + s.split("\\.")[1]; + return StringUtils.formatNumber((int) f) + '.' + s.split("\\.")[1]; } else if (s.contains(",")) { - return NumberFormat.getNumberInstance().format((int) f) + ',' + s.split(",")[1]; + return StringUtils.formatNumber((int) f) + ',' + s.split(",")[1]; } else { return s; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java index 907f0f0d..fd9b2938 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; @@ -38,15 +39,12 @@ import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -import java.text.NumberFormat; import java.util.LinkedList; import java.util.List; -import java.util.Locale; @NEUAutoSubscribe public class PowerStoneStatsDisplay { private static PowerStoneStatsDisplay instance = null; - private final NumberFormat format = NumberFormat.getInstance(Locale.US); private boolean dirty = true; public static PowerStoneStatsDisplay getInstance() { @@ -59,16 +57,14 @@ public class PowerStoneStatsDisplay { @SubscribeEvent public void onProfileDataLoaded(ProfileDataLoadedEvent event) { JsonObject profileInfo = event.getProfileInfo(); - if (profileInfo == null) return; - JsonObject inventoryInfo = ProfileViewerUtils.readInventoryInfo(profileInfo, "talisman_bag"); + JsonArray inventoryInfo = ProfileViewerUtils.readInventoryInfo(profileInfo, "talisman_bag"); if (inventoryInfo == null) return; NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if (configProfileSpecific == null) return; - int powerAmount = ProfileViewerUtils.getMagicalPower(inventoryInfo, profileInfo); - configProfileSpecific.magicalPower = powerAmount; + configProfileSpecific.magicalPower = ProfileViewerUtils.getMagicalPower(inventoryInfo, profileInfo); } @SubscribeEvent @@ -92,8 +88,7 @@ public class PowerStoneStatsDisplay { String rawNumber = line.split("§6")[1].replace(",", ""); NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if (configProfileSpecific == null) return; - int magicalPower = Integer.parseInt(rawNumber); - configProfileSpecific.magicalPower = magicalPower; + configProfileSpecific.magicalPower = Integer.parseInt(rawNumber); } } } @@ -153,7 +148,7 @@ public class PowerStoneStatsDisplay { return; } - event.toolTip.set(index, "§7At §6" + format.format((double) magicalPower) + " Magical Power§7:"); + event.toolTip.set(index, "§7At §6" + StringUtils.formatNumber((double) magicalPower) + " Magical Power§7:"); foundMagicalPower = true; continue; } @@ -177,7 +172,7 @@ public class PowerStoneStatsDisplay { } double realStat = (currentStat / scaledCurrentPower) * scaledMagicalPower; - String format = this.format.format((double) Math.round(realStat)); + String format = StringUtils.formatNumber((double) Math.round(realStat)); format += rawStat.substring(rawStat.length() - 1); event.toolTip.set(index, line.replace(rawStat, format)); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java index 6d565bb3..4d88ef07 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java @@ -23,6 +23,7 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.Utils; @@ -46,12 +47,10 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.ByteArrayInputStream; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -75,10 +74,6 @@ public class TradeWindow { private static String[] theirTradeOld = new String[16]; private static Long[] theirTradeChangesMillis = new Long[16]; - private static ItemStack lastBackpack; - private static int lastBackpackX; - private static int lastBackpackY; - public static boolean hypixelTradeWindowActive(String containerName) { return containerName != null && containerName.trim().startsWith("You "); } @@ -129,9 +124,8 @@ public class TradeWindow { JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalName); if (info != null && !NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(internalName) && info.has("price") && info.has("count")) { - long auctionPricePer = (long) (info.get("price").getAsDouble() / info.get("count").getAsDouble()); - pricePer = auctionPricePer; + pricePer = (long) (info.get("price").getAsDouble() / info.get("count").getAsDouble()); } } if (pricePer == -1) { @@ -293,7 +287,9 @@ public class TradeWindow { for (int k = 0; k < items.tagCount(); k++) { if (items.getCompoundTagAt(k).getKeySet().size() > 0) { NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag"); - String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(nbt); + String internalname2 = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery() + .withItemNBT(nbt) + .resolveInternalName(); if (internalname2 != null) { long pricePer2 = getPrice(internalname2); if (pricePer2 > 0) { @@ -412,7 +408,7 @@ public class TradeWindow { if (stack == null) continue; NBTTagCompound tag = stack.getTagCompound(); - String uuid = null; + String uuid; if (tag != null && tag.hasKey("ExtraAttributes", 10)) { NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); @@ -533,7 +529,7 @@ public class TradeWindow { if (stack == null) continue; NBTTagCompound tag = stack.getTagCompound(); - String uuid = null; + String uuid; if (tag != null && tag.hasKey("ExtraAttributes", 10)) { NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); @@ -820,8 +816,6 @@ public class TradeWindow { theirPrice += processTopItems(stack, theirTopItems, theirTopItemsStack, theirTopItemsCount); } - NumberFormat format = NumberFormat.getInstance(Locale.US); - GlStateManager.disableLighting(); GlStateManager.color(1, 1, 1, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(location); @@ -831,7 +825,7 @@ public class TradeWindow { drawStringShadow(EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + "Total Value", guiLeft - 40 - 3, guiTop + 11, 72 ); - drawStringShadow(EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + format.format(ourPrice), + drawStringShadow(EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + StringUtils.formatNumber(ourPrice), guiLeft - 40 - 3, guiTop + 21, 72 ); @@ -861,7 +855,7 @@ public class TradeWindow { GlStateManager.disableBlend(); GlStateManager.color(1, 1, 1, 1); drawStringShadow( - EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + format.format(entry.getKey()), + EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + StringUtils.formatNumber(entry.getKey()), guiLeft - 29 - 3, guiTop + 57 + 18 * ourTopIndex, 52 @@ -875,7 +869,7 @@ public class TradeWindow { 72 ); drawStringShadow( - EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + format.format(entry.getKey()), + EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + StringUtils.formatNumber(entry.getKey()), guiLeft - 40 - 3, guiTop + 56 + 20 * ourTopIndex, 72 @@ -894,7 +888,7 @@ public class TradeWindow { drawStringShadow(EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + "Total Value", guiLeft + xSize + 3 + 40, guiTop + 11, 72 ); - drawStringShadow(EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + format.format(theirPrice), + drawStringShadow(EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + StringUtils.formatNumber(theirPrice), guiLeft + xSize + 3 + 40, guiTop + 21, 72 ); @@ -924,7 +918,7 @@ public class TradeWindow { GlStateManager.disableBlend(); GlStateManager.color(1, 1, 1, 1); drawStringShadow( - EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + format.format(entry.getKey()), + EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + StringUtils.formatNumber(entry.getKey()), guiLeft + xSize + 3 + 51, guiTop + 57 + 18 * theirTopIndex, 52 @@ -935,7 +929,7 @@ public class TradeWindow { guiLeft + xSize + 3 + 40, guiTop + 46 + 20 * theirTopIndex, 72 ); drawStringShadow( - EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + format.format(entry.getKey()), + EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + StringUtils.formatNumber(entry.getKey()), guiLeft + xSize + 3 + 40, guiTop + 56 + 20 * theirTopIndex, 72 @@ -1099,15 +1093,12 @@ public class TradeWindow { if (mouseY >= guiTop + ySize - 19 && mouseY <= guiTop + ySize - 19 + 17) { NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade = !NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade; - return; } else if (mouseY >= guiTop + ySize - 38 && mouseY <= guiTop + ySize - 38 + 17) { NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePrices = !NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePrices; - return; } else if (mouseY >= guiTop + ySize - 57 && mouseY <= guiTop + ySize - 57 + 17) { NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePriceStyle = !NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePriceStyle; - return; } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java index deef7bdc..fb936a4d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java @@ -25,6 +25,7 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.GlScissorStack; import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingFloat; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; @@ -63,13 +64,11 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.util.glu.Project; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Objects; import java.util.Random; import java.util.regex.Matcher; @@ -82,14 +81,10 @@ public class GuiCustomHex extends Gui { "textures/entity/enchanting_table_book.png"); private static final ModelBook MODEL_BOOK = new ModelBook(); - private static final int EXPERIENCE_ORB_COUNT = 30; - private static final Pattern XP_COST_PATTERN = Pattern.compile("\\u00a73(\\d+) Exp Levels"); private static final Pattern ENCHANT_LEVEL_PATTERN = Pattern.compile("(.*)_(.*)"); private static final Pattern ENCHANT_NAME_PATTERN = Pattern.compile("([^IVX]*) ([IVX]*)"); - public static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); - public class Enchantment { public int slotIndex; public String enchantName; @@ -112,8 +107,10 @@ public class GuiCustomHex extends Gui { this.level = level; boolean isUlt = false; for (String lore : displayLore) { - if (lore.contains("§l")) isUlt = true; - break; + if (lore.contains("§l")) { + isUlt = true; + break; + } } JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo( (isUlt ? "ULTIMATE_" : "") + enchId.toUpperCase() + ";" + level); @@ -502,7 +499,7 @@ public class GuiCustomHex extends Gui { int index = 0; for (String lore : enchantment.displayLore) { if (lore.contains("N/A") && enchantment.price > 0) { - String price = numberFormat.format(enchantment.price); + String price = StringUtils.formatNumber(enchantment.price); enchantment.displayLore.set(index, "\u00a76" + price + ".0 Coins"); } if (lore.contains("Loading...")) { @@ -1532,7 +1529,7 @@ public class GuiCustomHex extends Gui { fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); - String priceStr = "" + numberFormat.format(enchanterCurrentEnch.price) + " Coins"; + String priceStr = StringUtils.formatNumber(enchanterCurrentEnch.price) + " Coins"; if (enchanterCurrentEnch.price < 0) priceStr = ""; int priceWidth = fr.getStringWidth(priceStr); int priceTop = guiTop + 16; @@ -2076,7 +2073,7 @@ public class GuiCustomHex extends Gui { } } - String priceStr = "" + numberFormat.format(enchanterCurrentItem.getPrice()) + " Coins"; + String priceStr = StringUtils.formatNumber(enchanterCurrentItem.getPrice()) + " Coins"; if (enchanterCurrentItem.price < 0) priceStr = ""; int priceWidth = fr.getStringWidth(priceStr); int priceTop = guiTop + 10; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CrystalHollowOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CrystalHollowOverlay.java index 852a2742..1bc08744 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CrystalHollowOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CrystalHollowOverlay.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.overlays; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -34,7 +35,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import org.lwjgl.util.vector.Vector2f; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -213,11 +213,10 @@ public class CrystalHollowOverlay extends TextOverlay { if (crystalCheck()) { int count = getCountCrystal(hidden.crystals); float percent = (float) count / hidden.crystals.size() * 100; - DecimalFormat df = new DecimalFormat("#.#"); overlayStrings.add( EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.mining.crystalHollowPartColor] + "Crystals: " + getColor(percent) + - df.format(percent) + "%"); + StringUtils.formatToTenths(percent) + "%"); } break; case 3: @@ -334,11 +333,10 @@ public class CrystalHollowOverlay extends TextOverlay { ) { int count = getCount(parts, inventoryData, storageData); float percent = (float) count / parts.size() * 100; - DecimalFormat df = new DecimalFormat("#.#"); overlayStrings.add( EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.mining.crystalHollowPartColor] + text + ": " + getColor(percent) + - df.format(percent) + "%"); + StringUtils.formatToTenths(percent) + "%"); } private EnumChatFormatting getColor(float percent) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java index 266722e5..d6740c0c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java @@ -28,6 +28,7 @@ import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.profileviewer.level.LevelPage; import io.github.moulberry.notenoughupdates.profileviewer.weight.lily.LilyWeight; import io.github.moulberry.notenoughupdates.profileviewer.weight.senither.SenitherWeight; +import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.PronounDB; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -67,7 +68,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; -import static io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer.DECIMAL_FORMAT; import static io.github.moulberry.notenoughupdates.util.Utils.roundToNearestInt; public class BasicPage extends GuiProfileViewerPage { @@ -130,13 +130,12 @@ public class BasicPage extends GuiProfileViewerPage { @Override public void drawPage(int mouseX, int mouseY, float partialTicks) { FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - ProfileViewer.Profile profile = GuiProfileViewer.getProfile(); - String profileId = GuiProfileViewer.getProfileId(); + SkyblockProfiles profile = GuiProfileViewer.getProfile(); int guiLeft = GuiProfileViewer.getGuiLeft(); int guiTop = GuiProfileViewer.getGuiTop(); if (onSecondPage) { - levelPage.drawPage(mouseX, mouseY); + levelPage.drawPage(mouseX, mouseY, partialTicks); return; } @@ -202,8 +201,11 @@ public class BasicPage extends GuiProfileViewerPage { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_basic); Utils.drawTexturedRect(guiLeft, guiTop, getInstance().sizeX, getInstance().sizeY, GL11.GL_NEAREST); - JsonObject profileInfo = profile.getProfileInformation(profileId); - if (profileInfo == null) return; + String profileName = GuiProfileViewer.getProfileName(); + SkyblockProfiles.SkyblockProfile selectedProfile = getSelectedProfile(); + if (selectedProfile == null) { + return; + } if (entityPlayer != null && profile.getHypixelProfile() != null) { String playerName = null; @@ -251,11 +253,10 @@ public class BasicPage extends GuiProfileViewerPage { playerName = EnumChatFormatting.GRAY + name; if (rankName != null) { - String icon = getIcon(getGameModeType(profileInfo)); + String icon = selectedProfile.getGamemode() == null ? "" : getIcon(selectedProfile.getGamemode()); playerName = "\u00A7" + rankColor + "[" + rankName + rankPlusColor + rankPlus + "\u00A7" + rankColor + "] " + name + (icon.equals("") ? "" : " " + icon); - ; } } } @@ -279,50 +280,45 @@ public class BasicPage extends GuiProfileViewerPage { } } - long networth; + String stateStr = EnumChatFormatting.RED + "An error occurred"; + long networth = -2; ArrayList nwCategoryHover = new ArrayList<>(); if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { - ProfileViewer.Profile.SoopyNetworthData nwData = profile.getSoopyNetworth(profileId, () -> {}); - if (nwData == null) { - networth = -2l; - } else { - networth = nwData.getTotal(); - - for (String category : nwData.getCategories()) { - if (nwData.getCategory(category) == 0) continue; - - nwCategoryHover.add(EnumChatFormatting.GREEN + - WordUtils.capitalizeFully(category.replace("_", " ")) + + SkyblockProfiles.SoopyNetworth nwData = selectedProfile.getSoopyNetworth(() -> {}); + networth = nwData.getNetworth(); + + if (networth == -1) { + stateStr = EnumChatFormatting.YELLOW + "Loading..."; + } else if (networth != -2) { // -2 indicates error + for (Map.Entry entry : nwData.getCategoryToTotal().entrySet()) { + nwCategoryHover.add( + EnumChatFormatting.GREEN + + WordUtils.capitalizeFully(entry.getKey().replace("_", " ")) + ": " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(nwData.getCategory(category))); + StringUtils.formatNumber(entry.getValue()) + ); } - nwCategoryHover.add(""); } - } else { - networth = profile.getNetWorth(profileId); } - //Networth is under 0 - //If = -1 -> an error occurred - //If = -2 -> still loading networth - String stateStr = EnumChatFormatting.RED + "An error occurred"; + // Calculate using NEU networth if not using soopy networth or soopy networth errored if (networth == -2) { - stateStr = EnumChatFormatting.YELLOW + "Loading..."; - } else if (networth == -1) { - networth = profile.getNetWorth(profileId); + networth = selectedProfile.getNetworth(); } - int fontWidth = fr.getStringWidth("Net Worth: " + GuiProfileViewer.numberFormat.format(networth)); - int offset = (fontWidth >= 117 ? 63 + (fontWidth - 117) : 63); + if (networth > 0) { + int fontWidth = fr.getStringWidth("Net Worth: " + StringUtils.formatNumber(networth)); + int offset = (fontWidth >= 117 ? 63 + (fontWidth - 117) : 63); + if (fontWidth >= 117) { fr.drawString(EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(networth), guiLeft + 8, guiTop + 38 - fr.FONT_HEIGHT / 2f, 0, true); + StringUtils.formatNumber(networth), guiLeft + 8, guiTop + 38 - fr.FONT_HEIGHT / 2f, 0, true); } else { Utils.drawStringCentered( EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(networth), + StringUtils.formatNumber(networth), guiLeft + 68, guiTop + 38, true, 0 ); } @@ -336,7 +332,7 @@ public class BasicPage extends GuiProfileViewerPage { .get("avg_buy") .getAsDouble() ); - String networthIRLMoney = GuiProfileViewer.numberFormat.format(Math.round( + String networthIRLMoney = StringUtils.formatNumber(Math.round( ((networthInCookies * 325) / 675) * 4.99)); @@ -355,10 +351,10 @@ public class BasicPage extends GuiProfileViewerPage { if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth && profile.getSoopyNetworthLeaderboardPosition() >= 0 - && profile.isProfileMaxSoopyWeight(profile, profileId)) { + && profile.isProfileMaxSoopyWeight(profileName)) { getInstance().tooltipToDisplay.add(""); String lbPosStr = - EnumChatFormatting.DARK_GREEN + "#" + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format( + EnumChatFormatting.DARK_GREEN + "#" + EnumChatFormatting.GOLD + StringUtils.formatNumber( profile.getSoopyNetworthLeaderboardPosition()); getInstance().tooltipToDisplay.add( lbPosStr + EnumChatFormatting.GREEN + " on soopy's networth leaderboard!"); @@ -472,15 +468,15 @@ public class BasicPage extends GuiProfileViewerPage { entityPlayer.getDataWatcher().updateObject(10, b); } - Map skyblockInfo = profile.getSkyblockInfo(profileId); - JsonObject inventoryInfo = profile.getInventoryInfo(profileId); + Map skyblockInfo = getSelectedProfile().getLevelingInfo(); + Map inventoryInfo = getSelectedProfile().getInventoryInfo(); if (entityPlayer != null) { if (backgroundClickedX != -1 && Mouse.isButtonDown(1)) { Arrays.fill(entityPlayer.inventory.armorInventory, null); } else { - if (inventoryInfo != null && inventoryInfo.has("inv_armor")) { - JsonArray items = inventoryInfo.get("inv_armor").getAsJsonArray(); + if (inventoryInfo != null && inventoryInfo.containsKey("inv_armor")) { + JsonArray items = inventoryInfo.get("inv_armor"); if (items != null && items.size() == 4) { for (int i = 0; i < entityPlayer.inventory.armorInventory.length; i++) { JsonElement itemElement = items.get(i); @@ -531,7 +527,7 @@ public class BasicPage extends GuiProfileViewerPage { } GlStateManager.color(1, 1, 1, 1); - JsonObject petsInfo = profile.getPetsInfo(profileId); + JsonObject petsInfo = profile.getProfile(profileName).getPetsInfo(); if (petsInfo != null) { JsonElement activePetElement = petsInfo.get("active_pet"); if (activePetElement != null && activePetElement.isJsonObject()) { @@ -582,8 +578,8 @@ public class BasicPage extends GuiProfileViewerPage { int sbLevelX = guiLeft + 162; int sbLevelY = guiTop + 90; - double skyblockLevel = profile.getSkyblockLevel(profileId); - EnumChatFormatting skyblockLevelColour = profile.getSkyblockLevelColour(profileId); + double skyblockLevel = profile.getProfile(profileName).getSkyblockLevel(); + EnumChatFormatting skyblockLevelColour = profile.getProfile(profileName).getSkyblockLevelColour(); GlStateManager.pushMatrix(); GlStateManager.translate(sbLevelX, sbLevelY, 0); @@ -607,7 +603,7 @@ public class BasicPage extends GuiProfileViewerPage { } } - if (skyblockInfo != null) { + if (skyblockInfo != null && selectedProfile.skillsApiEnabled()) { int position = 0; for (Map.Entry entry : ProfileViewer.getSkillToSkillDisplayMap().entrySet()) { if (entry.getValue() == null || entry.getKey() == null) { @@ -653,15 +649,15 @@ public class BasicPage extends GuiProfileViewerPage { "/" + StringUtils.shortNumberFormat(maxXp)); } - String totalXpS = GuiProfileViewer.numberFormat.format((long) level.totalXp); + String totalXpS = StringUtils.formatNumber((long) level.totalXp); tooltipToDisplay.add(EnumChatFormatting.GRAY + "Total XP: " + EnumChatFormatting.DARK_PURPLE + totalXpS + EnumChatFormatting.DARK_GRAY + " (" + - DECIMAL_FORMAT.format(guiProfileViewer.getPercentage(entry.getKey().toLowerCase(), level)) + + StringUtils.formatToTenths(guiProfileViewer.getPercentage(entry.getKey().toLowerCase(), level)) + "% to " + level.maxLevel + ")"); if (entry.getKey().equals("farming")) { // double drops + pelts - int doubleDrops = Utils.getElementAsInt(Utils.getElement(profileInfo, "jacob2.perks.double_drops"), 0); - int peltCount = Utils.getElementAsInt(Utils.getElement(profileInfo, "trapper_quest.pelt_count"), 0); + int doubleDrops = Utils.getElementAsInt(Utils.getElement(selectedProfile.getProfileJson(), "jacob2.perks.double_drops"), 0); + int peltCount = Utils.getElementAsInt(Utils.getElement(selectedProfile.getProfileJson(), "trapper_quest.pelt_count"), 0); if (doubleDrops == 15) { tooltipToDisplay.add("§7Double Drops: §6" + (doubleDrops * 2) + "%"); @@ -670,7 +666,7 @@ public class BasicPage extends GuiProfileViewerPage { tooltipToDisplay.add("§7Pelts: §e" + peltCount); // medals - JsonObject medals_inv = Utils.getElement(profileInfo, "jacob2.medals_inv").getAsJsonObject(); + JsonObject medals_inv = Utils.getElement(selectedProfile.getProfileJson(), "jacob2.medals_inv").getAsJsonObject(); tooltipToDisplay.add(" "); for (String medalName : medalNames) { String textWithoutFormattingCodes = @@ -687,12 +683,18 @@ public class BasicPage extends GuiProfileViewerPage { } String slayerNameLower = entry.getKey().toLowerCase(); - if (ExtraPage.slayers.containsKey(slayerNameLower)) { - int maxLevel = ExtraPage.slayers.get(slayerNameLower); + if (Weight.SLAYER_NAMES.contains(slayerNameLower)) { + JsonObject slayerToTier = Constants.LEVELING.getAsJsonObject("slayer_to_highest_tier"); + if (slayerToTier == null) { + Utils.showOutdatedRepoNotification(); + return; + } + + int maxLevel = slayerToTier.get(slayerNameLower).getAsInt(); for (int i = 0; i < 5; i++) { if (i >= maxLevel) break; float tier = Utils.getElementAsFloat( - Utils.getElement(profileInfo, "slayer_bosses." + slayerNameLower + ".boss_kills_tier_" + i), + Utils.getElement(selectedProfile.getProfileJson(), "slayer_bosses." + slayerNameLower + ".boss_kills_tier_" + i), 0 ); tooltipToDisplay.add(EnumChatFormatting.GRAY + "T" + (i + 1) + " Kills: " + @@ -718,7 +720,9 @@ public class BasicPage extends GuiProfileViewerPage { } drawSideButtons(); - if (NotEnoughUpdates.INSTANCE.config.profileViewer.displayWeight) renderWeight(mouseX, mouseY, skyblockInfo, profileInfo); + if (NotEnoughUpdates.INSTANCE.config.profileViewer.displayWeight) { + renderWeight(mouseX, mouseY, selectedProfile); + } } private String getIcon(String gameModeType) { @@ -761,15 +765,19 @@ public class BasicPage extends GuiProfileViewerPage { private void renderWeight( int mouseX, int mouseY, - Map skyblockInfo, - JsonObject profileInfo + SkyblockProfiles.SkyblockProfile selectedProfile ) { + if (!selectedProfile.skillsApiEnabled()) { + return; + } + + Map skyblockInfo = selectedProfile.getLevelingInfo(); if (skyblockInfo == null) { return; } - ProfileViewer.Profile profile = GuiProfileViewer.getProfile(); - String profileId = GuiProfileViewer.getProfileId(); + SkyblockProfiles profile = GuiProfileViewer.getProfile(); + String profileName = GuiProfileViewer.getProfileName(); if (Constants.WEIGHT == null || Utils.getElement(Constants.WEIGHT, "lily.skills.overall") == null || !Utils.getElement(Constants.WEIGHT, "lily.skills.overall").isJsonPrimitive()) { @@ -782,7 +790,7 @@ public class BasicPage extends GuiProfileViewerPage { int guiTop = GuiProfileViewer.getGuiTop(); SenitherWeight senitherWeight = new SenitherWeight(skyblockInfo); - LilyWeight lilyWeight = new LilyWeight(skyblockInfo, profileInfo); + LilyWeight lilyWeight = new LilyWeight(skyblockInfo, selectedProfile.getProfileJson()); long weight = -2L; if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { @@ -793,13 +801,13 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GREEN + "Senither Weight: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())), + StringUtils.formatNumber(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())), guiLeft + 63, guiTop + 18, true, 0 ); int textWidth = fr.getStringWidth( "Senither Weight: " + - GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())) + StringUtils.formatNumber(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())) ); if (mouseX > guiLeft + 63 - textWidth / 2 && mouseX < guiLeft + 63 + textWidth / 2) { if (mouseY > guiTop + 12 && mouseY < guiTop + 12 + fr.FONT_HEIGHT) { @@ -809,7 +817,7 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GREEN + "Skills: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight + StringUtils.formatNumber(roundToNearestInt(senitherWeight .getSkillsWeight() .getWeightStruct() .getRaw())) @@ -819,7 +827,7 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GREEN + "Slayer: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight + StringUtils.formatNumber(roundToNearestInt(senitherWeight .getSlayerWeight() .getWeightStruct() .getRaw())) @@ -829,16 +837,16 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GREEN + "Dungeons: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format( + StringUtils.formatNumber( roundToNearestInt(senitherWeight.getDungeonsWeight().getWeightStruct().getRaw()) ) ); if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth - && profile.isProfileMaxSoopyWeight(profile, profileId)) { + && profile.isProfileMaxSoopyWeight(profileName)) { String lbPosStr = - EnumChatFormatting.DARK_GREEN + "#" + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format( + EnumChatFormatting.DARK_GREEN + "#" + EnumChatFormatting.GOLD + StringUtils.formatNumber( profile.getSoopyWeightLeaderboardPosition()); getInstance().tooltipToDisplay.add(""); String stateStr = EnumChatFormatting.RED + "An error occurred"; @@ -856,12 +864,12 @@ public class BasicPage extends GuiProfileViewerPage { Utils.drawStringCentered( EnumChatFormatting.GREEN + "Lily Weight: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())), + StringUtils.formatNumber(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())), guiLeft + 63, guiTop + 28, true, 0 ); int fontWidth = fr.getStringWidth( - "Lily Weight: " + GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())) + "Lily Weight: " + StringUtils.formatNumber(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())) ); if (mouseX > guiLeft + 63 - fontWidth / 2 && mouseX < guiLeft + 63 + fontWidth / 2) { if (mouseY > guiTop + 22 && mouseY < guiTop + 22 + fr.FONT_HEIGHT) { @@ -871,7 +879,7 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GREEN + "Skills: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight + StringUtils.formatNumber(roundToNearestInt(lilyWeight .getSkillsWeight() .getWeightStruct() .getRaw())) @@ -881,7 +889,7 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GREEN + "Slayer: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight + StringUtils.formatNumber(roundToNearestInt(lilyWeight .getSlayerWeight() .getWeightStruct() .getRaw())) @@ -891,7 +899,7 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GREEN + "Dungeons: " + EnumChatFormatting.GOLD + - GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight + StringUtils.formatNumber(roundToNearestInt(lilyWeight .getDungeonsWeight() .getWeightStruct() .getRaw())) @@ -974,13 +982,6 @@ public class BasicPage extends GuiProfileViewerPage { return 0; } - public String getGameModeType(JsonObject profileInfo) { - if (profileInfo != null && profileInfo.has("game_mode")) { - return profileInfo.get("game_mode").getAsString(); - } - return ""; - } - public void drawSideButtons() { GlStateManager.enableDepth(); GlStateManager.translate(0, 0, 5); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java index cc5fc92f..fa14ad52 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java @@ -52,8 +52,7 @@ public class BingoPage extends GuiProfileViewerPage { @Override public void drawPage(int mouseX, int mouseY, float partialTicks) { - processBingoResources(); - JsonObject bingoInfo = GuiProfileViewer.getProfile().getBingoInformation(); + loadBingoResources(); ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledResolution.getScaledWidth(); @@ -61,12 +60,19 @@ public class BingoPage extends GuiProfileViewerPage { int guiLeft = GuiProfileViewer.getGuiLeft(); int guiTop = GuiProfileViewer.getGuiTop(); - //check if the player has created a bingo profile for the current event + + JsonObject bingoInfo = GuiProfileViewer.getProfile().getBingoInformation(); + // Check if the player has created a bingo profile for the current event if (bingoInfo == null) { showMissingDataMessage(guiLeft, guiTop); return; } + // Bingo goals data not loaded yet + if (bingoGoals == null) { + return; + } + JsonArray events = bingoInfo.get("events").getAsJsonArray(); JsonObject lastEvent = events.get(events.size() - 1).getAsJsonObject(); int lastParticipatedId = lastEvent.get("key").getAsInt(); @@ -304,7 +310,7 @@ public class BingoPage extends GuiProfileViewerPage { return list; } - private void processBingoResources() { + private void loadBingoResources() { long currentTime = System.currentTimeMillis(); //renew every 2 minutes 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 03be7cf1..da90843a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java @@ -37,16 +37,15 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.IOException; import java.math.BigInteger; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Locale; + +import static io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer.pv_elements; public class CollectionsPage extends GuiProfileViewer