aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
diff options
context:
space:
mode:
authorkr45732 <52721908+kr45732@users.noreply.github.com>2023-06-08 10:00:04 -0400
committerGitHub <noreply@github.com>2023-06-08 16:00:04 +0200
commit8115922b37e375285c2a72dbdbb5d83fd942e27c (patch)
treee0d6cb5228493e8bb032465cbb2dfd95b4946e43 /src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
parenta6fb7bfb97d313b665085a52a660150f1da26065 (diff)
downloadnotenoughupdates-8115922b37e375285c2a72dbdbb5d83fd942e27c.tar.gz
notenoughupdates-8115922b37e375285c2a72dbdbb5d83fd942e27c.tar.bz2
notenoughupdates-8115922b37e375285c2a72dbdbb5d83fd942e27c.zip
PV Overhaul (#708)
Co-authored-by: Lulonaut <lulonaut@tutanota.de>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java1275
1 files changed, 48 insertions, 1227 deletions
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 ea852da3..8c552146 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
@@ -19,57 +19,27 @@
package io.github.moulberry.notenoughupdates.profileviewer;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.JsonPrimitive;
import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
-import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData;
-import io.github.moulberry.notenoughupdates.profileviewer.weight.senither.SenitherWeight;
-import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.Utils;
-import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo;
+import lombok.Getter;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.CompressedStreamTools;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumChatFormatting;
-import javax.annotation.Nullable;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.time.Duration;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Base64;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
-import java.util.regex.Pattern;
public class ProfileViewer {
- private static final HashMap<String, String> petRarityToNumMap = new HashMap<String, String>() {
- {
- put("COMMON", "0");
- put("UNCOMMON", "1");
- put("RARE", "2");
- put("EPIC", "3");
- put("LEGENDARY", "4");
- put("MYTHIC", "5");
- }
- };
+ @Getter
private static final LinkedHashMap<String, ItemStack> skillToSkillDisplayMap =
new LinkedHashMap<String, ItemStack>() {
{
@@ -121,6 +91,7 @@ public class ProfileViewer {
Items.fishing_rod,
EnumChatFormatting.AQUA + "Fishing"
);
+ @Getter
private static final LinkedHashMap<ItemStack, List<String>> collectionCatToCollectionMap =
new LinkedHashMap<ItemStack, List<String>>() {
{
@@ -213,6 +184,7 @@ public class ProfileViewer {
);
}
};
+ @Getter
private static final LinkedHashMap<ItemStack, List<String>> collectionCatToMinionMap =
new LinkedHashMap<ItemStack, List<String>>() {
{
@@ -289,6 +261,7 @@ public class ProfileViewer {
put(CAT_FISHING, Utils.createList("FISHING", null, null, null, null, null, "CLAY", null, null, null));
}
};
+ @Getter
private static final LinkedHashMap<String, ItemStack> collectionToCollectionDisplayMap =
new LinkedHashMap<String, ItemStack>() {
{
@@ -448,74 +421,20 @@ public class ProfileViewer {
);
}
};
-
- public static final List<String> SLAYERS = Arrays.asList("zombie", "spider", "wolf", "enderman", "blaze");
-
private static final AtomicBoolean updatingResourceCollection = new AtomicBoolean(false);
private static JsonObject resourceCollection = null;
- private final NEUManager manager;
+ @Getter
private final HashMap<String, JsonObject> uuidToHypixelProfile = new HashMap<>();
- private final HashMap<String, Profile> uuidToProfileMap = new HashMap<>();
-
+ @Getter
+ private final NEUManager manager;
+ private final HashMap<String, SkyblockProfiles> uuidToSkyblockProfiles = new HashMap<>();
private final HashMap<String, String> nameToUuid = new HashMap<>();
public ProfileViewer(NEUManager manager) {
this.manager = manager;
}
- public static LinkedHashMap<ItemStack, List<String>> getCollectionCatToMinionMap() {
- return collectionCatToMinionMap;
- }
-
- public static LinkedHashMap<String, ItemStack> getCollectionToCollectionDisplayMap() {
- return collectionToCollectionDisplayMap;
- }
-
- public static LinkedHashMap<ItemStack, List<String>> getCollectionCatToCollectionMap() {
- return collectionCatToCollectionMap;
- }
-
- public static Map<String, ItemStack> getSkillToSkillDisplayMap() {
- return Collections.unmodifiableMap(skillToSkillDisplayMap);
- }
-
- public static Level getLevel(JsonArray levelingArray, float xp, int levelCap, boolean cumulative) {
- Level levelObj = new Level();
- levelObj.totalXp = xp;
- levelObj.maxLevel = levelCap;
-
- for (int level = 0; level < levelingArray.size(); level++) {
- float levelXp = levelingArray.get(level).getAsFloat();
-
- if (levelXp > xp) {
- if (cumulative) {
- float previous = level > 0 ? levelingArray.get(level - 1).getAsFloat() : 0;
- levelObj.maxXpForLevel = (levelXp - previous);
- levelObj.level = 1 + level + (xp - levelXp) / levelObj.maxXpForLevel;
- } else {
- levelObj.maxXpForLevel = levelXp;
- levelObj.level = level + xp / levelXp;
- }
-
- if (levelObj.level > levelCap) {
- levelObj.level = levelCap;
- levelObj.maxed = true;
- }
-
- return levelObj;
- } else {
- if (!cumulative) {
- xp -= levelXp;
- }
- }
- }
-
- levelObj.level = Math.min(levelingArray.size(), levelCap);
- levelObj.maxed = true;
- return levelObj;
- }
-
- public static JsonObject getResourceCollectionInformation() {
+ public static JsonObject getOrLoadCollectionsResource() {
if (resourceCollection != null) return resourceCollection;
if (updatingResourceCollection.get()) return null;
@@ -533,53 +452,26 @@ public class ProfileViewer {
return null;
}
- public void getHypixelProfile(String name, Consumer<JsonObject> callback) {
- String nameF = name.toLowerCase();
- manager.apiUtils
- .newHypixelApiRequest("player")
- .queryArgument("name", nameF)
- .maxCacheAge(Duration.ofSeconds(30))
- .requestJson()
- .thenAccept(jsonObject -> {
- if (
- jsonObject != null &&
- jsonObject.has("success") &&
- jsonObject.get("success").getAsBoolean() &&
- jsonObject.get("player").isJsonObject()
- ) {
- nameToUuid.put(nameF, jsonObject.get("player").getAsJsonObject().get("uuid").getAsString());
- uuidToHypixelProfile.put(
- jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(),
- jsonObject.get("player").getAsJsonObject()
- );
- if (callback != null) callback.accept(jsonObject);
- } else {
- if (callback != null) callback.accept(null);
- }
- }
- );
- }
-
public void putNameUuid(String name, String uuid) {
nameToUuid.put(name, uuid);
}
public void getPlayerUUID(String name, Consumer<String> uuidCallback) {
- String nameF = name.toLowerCase();
- if (nameToUuid.containsKey(nameF)) {
- uuidCallback.accept(nameToUuid.get(nameF));
+ String nameLower = name.toLowerCase();
+ if (nameToUuid.containsKey(nameLower)) {
+ uuidCallback.accept(nameToUuid.get(nameLower));
return;
}
manager.apiUtils
.request()
- .url("https://api.mojang.com/users/profiles/minecraft/" + nameF)
+ .url("https://api.mojang.com/users/profiles/minecraft/" + nameLower)
.requestJson()
.thenAccept(jsonObject -> {
if (jsonObject.has("id") && jsonObject.get("id").isJsonPrimitive() &&
- ((JsonPrimitive) jsonObject.get("id")).isString()) {
+ jsonObject.get("id").getAsJsonPrimitive().isString()) {
String uuid = jsonObject.get("id").getAsString();
- nameToUuid.put(nameF, uuid);
+ nameToUuid.put(nameLower, uuid);
uuidCallback.accept(uuid);
return;
}
@@ -587,54 +479,60 @@ public class ProfileViewer {
});
}
- public void getProfileByName(String name, Consumer<Profile> callback) {
- String nameF = name.toLowerCase();
+ public void loadPlayerByName(String name, Consumer<SkyblockProfiles> callback) {
+ String nameLower = name.toLowerCase();
- if (nameToUuid.containsKey(nameF) && nameToUuid.get(nameF) == null) {
+ if (nameToUuid.containsKey(nameLower) && nameToUuid.get(nameLower) == null) {
callback.accept(null);
return;
}
getPlayerUUID(
- nameF,
+ nameLower,
uuid -> {
+ nameToUuid.put(nameLower, uuid);
if (uuid == null) {
- getHypixelProfile(
- nameF,
- jsonObject -> {
- if (jsonObject != null) {
- callback.accept(getProfileReset(nameToUuid.get(nameF), ignored -> {}));
- } else {
- callback.accept(null);
- nameToUuid.put(nameF, null);
- }
- }
- );
+ callback.accept(null);
} else {
if (!uuidToHypixelProfile.containsKey(uuid)) {
- getHypixelProfile(nameF, jsonObject -> {});
+ manager.apiUtils
+ .newHypixelApiRequest("player")
+ .queryArgument("uuid", uuid)
+ .maxCacheAge(Duration.ofSeconds(30))
+ .requestJson()
+ .thenAccept(playerJson -> {
+ if (
+ playerJson != null &&
+ playerJson.has("success") &&
+ playerJson.get("success").getAsBoolean() &&
+ playerJson.get("player").isJsonObject()
+ ) {
+ uuidToHypixelProfile.put(uuid, playerJson.get("player").getAsJsonObject());
+ }
+ }
+ );
}
- callback.accept(getProfileReset(uuid, ignored -> {}));
+
+ callback.accept(getOrLoadSkyblockProfiles(uuid, ignored -> {}));
}
}
);
}
- public Profile getProfile(String uuid, Consumer<Profile> callback) {
- Profile profile = uuidToProfileMap.computeIfAbsent(uuid, k -> new Profile(uuid));
- if (profile.skyblockProfiles != null) {
+ public SkyblockProfiles getOrLoadSkyblockProfiles(String uuid, Consumer<SkyblockProfiles> callback) {
+ if (uuidToSkyblockProfiles.containsKey(uuid)) {
+ uuidToSkyblockProfiles.get(uuid).resetCache();
+ }
+
+ SkyblockProfiles profile = uuidToSkyblockProfiles.computeIfAbsent(uuid, key -> new SkyblockProfiles(this, uuid));
+ if (profile.getNameToProfile() != null) {
callback.accept(profile);
} else {
- profile.getSkyblockProfiles(() -> callback.accept(profile));
+ profile.getOrLoadSkyblockProfiles(() -> callback.accept(profile));
}
return profile;
}
- public Profile getProfileReset(String uuid, Consumer<Profile> callback) {
- if (uuidToProfileMap.containsKey(uuid)) uuidToProfileMap.get(uuid).resetCache();
- return getProfile(uuid, callback);
- }
-
public static class Level {
public float level = 0;
@@ -643,1081 +541,4 @@ public class ProfileViewer {
public int maxLevel;
public float totalXp;
}
-
- public class Profile {
-
- private final String uuid;
- private final HashMap<String, JsonObject> profileMap = new HashMap<>();
- private final HashMap<String, JsonObject> petsInfoMap = new HashMap<>();
- 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, CompletableFuture<ProfileCollectionInfo>> collectionInfoMap = new HashMap<>();
- private final HashMap<String, Double> skyBlockExperience = new HashMap<>();
- private final HashMap<String, EnumChatFormatting> skyBlockExperienceColour = 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<>();
- private final HashMap<String, Long> networth = new HashMap<>();
- private final HashMap<String, Integer> magicalPower = new HashMap<>();
- private final HashMap<String, SoopyNetworthData> soopyNetworth = new HashMap<>();
- private final AtomicBoolean updatingSkyblockProfilesState = new AtomicBoolean(false);
- private final AtomicBoolean updatingGuildInfoState = new AtomicBoolean(false);
- private final AtomicBoolean updatingPlayerStatusState = new AtomicBoolean(false);
- private final AtomicBoolean updatingSoopyNetworth = new AtomicBoolean(false);
- private final AtomicBoolean updatingBingoInfo = new AtomicBoolean(false);
- private final Pattern COLL_TIER_PATTERN = Pattern.compile("_(-?\\d+)");
- private long soopyNetworthLeaderboardPosition = -1; //-1 = default, -2 = loading, -3 = error
- private long soopyWeightLeaderboardPosition = -1; //-1 = default, -2 = loading, -3 = error
- private String latestProfile = null;
- private JsonArray skyblockProfiles = null;
- private JsonObject guildInformation = null;
- private JsonObject playerStatus = null;
- private JsonObject bingoInformation = null;
- private long lastPlayerInfoState = 0;
- private long lastStatusInfoState = 0;
- private long lastGuildInfoState = 0;
- private long lastBingoInfoState = 0;
-
- public Profile(String uuid) {
- this.uuid = uuid;
- }
-
- /**
- * Calculates the amount of Magical Power the player has using the list of accessories
- *
- * @return the amount of Magical Power or -1
- * @see io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer.Profile#getInventoryInfo(String)
- */
- public int getMagicalPower(String profileId) {
- JsonObject inventoryInfo = getInventoryInfo(profileId);
- JsonObject profileInfo = getProfileInformation(profileId);
- if (magicalPower.containsKey(profileId)) return magicalPower.get(profileId);
- if (inventoryInfo == null || !inventoryInfo.has("talisman_bag") ||
- !inventoryInfo.get("talisman_bag").isJsonArray()) {
- return -1;
- }
-
- int powerAmount = ProfileViewerUtils.getMagicalPower(inventoryInfo, profileInfo);
- magicalPower.put(profileId, powerAmount);
- return powerAmount;
- }
-
- public JsonObject getPlayerStatus() {
- if (playerStatus != null) return playerStatus;
- if (updatingPlayerStatusState.get()) return null;
-
- long currentTime = System.currentTimeMillis();
- if (currentTime - lastStatusInfoState < 15 * 1000) return null;
- lastStatusInfoState = currentTime;
- updatingPlayerStatusState.set(true);
-
- HashMap<String, String> args = new HashMap<>();
- args.put("uuid", "" + uuid);
- manager.apiUtils
- .newHypixelApiRequest("status")
- .queryArgument("uuid", "" + uuid)
- .requestJson()
- .handle((jsonObject, ex) -> {
- updatingPlayerStatusState.set(false);
-
- if (jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) {
- playerStatus = jsonObject.get("session").getAsJsonObject();
- }
- return null;
- });
- return null;
- }
-
- public JsonObject getBingoInformation() {
- long currentTime = System.currentTimeMillis();
- if (bingoInformation != null && currentTime - lastBingoInfoState < 15 * 1000) return bingoInformation;
- if (updatingBingoInfo.get() && bingoInformation != null) return bingoInformation;
- if (updatingBingoInfo.get() && bingoInformation == null) return null;
-
- lastBingoInfoState = currentTime;
- updatingBingoInfo.set(true);
-
- NotEnoughUpdates.INSTANCE.manager.apiUtils
- .newHypixelApiRequest("skyblock/bingo")
- .queryArgument("uuid", "" + uuid)
- .requestJson()
- .handle(((jsonObject, throwable) -> {
- updatingBingoInfo.set(false);
-
- if (jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) {
- bingoInformation = jsonObject;
- } else {
- bingoInformation = null;
- }
- return null;
- }));
- return bingoInformation != null ? bingoInformation : null;
- }
-
- public class SoopyNetworthData {
- private HashMap<String, Long> categoryWorth;
- private Long totalWorth;
- private String[] keys;
-
- SoopyNetworthData(JsonObject nwData) {
- categoryWorth = new HashMap<>();
-
- if (nwData == null || nwData.isJsonNull()) {
- totalWorth = -1l;
- keys = new String[0];
- return;
- }
- if (nwData.get("total").isJsonNull()) {
- totalWorth = -1l;
- keys = new String[0];
- return;
- }
-
- totalWorth = nwData.get("total").getAsLong();
- for (Map.Entry<String, JsonElement> entry : nwData.get("categories").getAsJsonObject().entrySet()) {
- if (entry.getValue().isJsonNull()) {
- continue;
- }
- categoryWorth.put(entry.getKey(), entry.getValue().getAsLong());
- }
-
- //Sort keys based on category value
- keys = categoryWorth
- .keySet()
- .stream()
- .sorted(Comparator.comparingLong(k -> getCategory((String) k)).reversed())
- .toArray(String[]::new);
- }
-
- private SoopyNetworthData setLoading() {
- totalWorth = -2l;
- return this;
- }
-
- public long getTotal() {
- return totalWorth;
- }
-
- public long getCategory(String name) {
- if (categoryWorth.containsKey(name)) return categoryWorth.get(name);
- return 0;
- }
-
- public String[] getCategories() {
- return keys;
- }
- }
-
- /**
- * -1 = default, -2 = loading, -3 = error
- * >= 0 = actual position
- */
- public long getSoopyNetworthLeaderboardPosition() {
- if ("d0e05de76067454dbeaec6d19d886191".equals(uuid)) return 1;
- return soopyNetworthLeaderboardPosition;
- }
-
- public long getSoopyWeightLeaderboardPosition() {
- if ("d0e05de76067454dbeaec6d19d886191".equals(uuid)) return 1;
- return soopyWeightLeaderboardPosition;
- }
-
- public boolean isProfileMaxSoopyWeight(ProfileViewer.Profile profile, String profileName) {
- String highestProfileName = "";
- double largestProfileWeight = 0;
-
- for (int yIndex = 0; yIndex < profileNames.size(); yIndex++) {
- String otherProfileId = profileNames.get(yIndex);
- Map<String, ProfileViewer.Level> skyblockInfo = profile.getSkyblockInfo(otherProfileId);
- if (skyblockInfo == null) continue;
- SenitherWeight senitherWeight = new SenitherWeight(skyblockInfo);
- double weightValue = senitherWeight.getTotalWeight().getRaw();
-
- if (weightValue > largestProfileWeight) {
- largestProfileWeight = weightValue;
- highestProfileName = otherProfileId;
- }
- }
-
- return highestProfileName.equals(profileName);
- }
-
- /**
- * Returns SoopyNetworthData with total = -1 if error
- * Returns null if still loading
- */
- public SoopyNetworthData getSoopyNetworth(String profileName, Runnable callback) {
- if (profileName == null) profileName = latestProfile;
- if (soopyNetworth.get(profileName) != null) {
- callback.run();
- return soopyNetworth.get(profileName);
- }
-
- JsonArray playerInfo = getSkyblockProfiles(() -> {});
- if (playerInfo == null)
- return null; //Not sure how to support the callback in these cases
- if (updatingSoopyNetworth.get())
- return new SoopyNetworthData(null).setLoading(); //It shouldent really matter tho as these should never occur in /peek
- updatingSoopyNetworth.set(true);
-
- soopyNetworthLeaderboardPosition = -2; //loading
- manager.apiUtils
- .request()
- .url("https://soopy.dev/api/v2/leaderboard/networth/user/" + this.uuid)
- .requestJson()
- .handle((jsonObject, throwable) -> {
- if (throwable != null) throwable.printStackTrace();
- if (throwable != null || !jsonObject.has("success") || !jsonObject.get("success").getAsBoolean()
- || !jsonObject.has("data")
- || !jsonObject.get("data").getAsJsonObject().has("data")
- || !jsonObject.get("data").getAsJsonObject().get("data").getAsJsonObject().has("position")) {
- //Something went wrong
- //Set profile lb position to -3 to indicate that
- soopyNetworthLeaderboardPosition = -3; //error
- return null;
- }
- soopyNetworthLeaderboardPosition = jsonObject.get("data").getAsJsonObject().get("data").getAsJsonObject().get(
- "position").getAsLong();
- return null;
- });
-
- soopyWeightLeaderboardPosition = -2; //loading
- manager.apiUtils
- .request()
- .url("https://soopy.dev/api/v2/leaderboard/weight/user/" + this.uuid)
- .requestJson()
- .handle((jsonObject, throwable) -> {
- if (throwable != null) throwable.printStackTrace();
- if (throwable != null || !jsonObject.has("success") || !jsonObject.get("success").getAsBoolean()
- || !jsonObject.has("data")
- || !jsonObject.get("data").getAsJsonObject().has("data")
- || !jsonObject.get("data").getAsJsonObject().get("data").getAsJsonObject().has("position")) {
- //Something went wrong
- //Set profile lb position to -3 to indicate that
- soopyWeightLeaderboardPosition = -3; //error
- return null;
- }
- soopyWeightLeaderboardPosition = jsonObject.get("data").getAsJsonObject().get("data").getAsJsonObject().get(
- "position").getAsLong();
- return null;
- });
-
- manager.apiUtils
- .request()
- .url("https://soopy.dev/api/v2/player_networth/" + this.uuid)
- .method("POST")
- .postData("application/json", skyblockProfiles.toString())
- .requestJson()
- .handle((jsonObject, throwable) -> {
- if (throwable != null) throwable.printStackTrace();
- if (throwable != null || !jsonObject.has("success") || !jsonObject.get("success").getAsBoolean()) {
- //Something went wrong
- //Set profile networths to null to indicate that
- for (int i = 0; i < skyblockProfiles.size(); i++) {
- if (!skyblockProfiles.get(i).isJsonObject()) {
- return null;
- }
- JsonObject profile = skyblockProfiles.get(i).getAsJsonObject();
-
- String cuteName = profile.get("cute_name").getAsString();
-
- soopyNetworth.put(cuteName, new SoopyNetworthData(null));
- }
- updatingSoopyNetworth.set(false);
- callback.run();
- return null;
- }
-
- //Success, update networth data
- for (int i = 0; i < skyblockProfiles.size(); i++) {
- if (!skyblockProfiles.get(i).isJsonObject()) {
- return null;
- }
- JsonObject profile = skyblockProfiles.get(i).getAsJsonObject();
-
- String cuteName = profile.get("cute_name").getAsString();
- String profileId = profile.get("profile_id").getAsString().replace("-", "");
-
- SoopyNetworthData networth;
- if (jsonObject.getAsJsonObject("data").get(profileId) == null) {
- networth = new SoopyNetworthData(null);
- } else {
- networth = new SoopyNetworthData(jsonObject.getAsJsonObject("data").get(profileId).getAsJsonObject());
- }
-
- soopyNetworth.put(cuteName, networth);
- }
-
- updatingSoopyNetworth.set(false);
- callback.run();
- return null;
- });
- return null;
- }
-
- public EnumChatFormatting getSkyblockLevelColour(String profileName) {
- if (Constants.SBLEVELS == null) return EnumChatFormatting.WHITE;
- if (skyBlockExperienceColour.containsKey(profileName)) {
- return skyBlockExperienceColour.get(profileName);
- }
-
- double skyblockLevel = getSkyblockLevel(profileName);
- EnumChatFormatting levelColour = 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()) {
- int nextLevelBracket = Integer.parseInt(stringJsonElementEntry.getKey());
- EnumChatFormatting valueByName = EnumChatFormatting.getValueByName(stringJsonElementEntry
- .getValue()
- .getAsString());
- if (skyblockLevel >= nextLevelBracket) {
- levelColour = valueByName;
- }
- }
- } catch (RuntimeException ignored) {
- // catch both numberformat and getValueByName being wrong
- }
- skyBlockExperienceColour.put(profileName, levelColour);
- return levelColour;
- }
-
- public double getSkyblockLevel(String profileName) {
- if (skyBlockExperience.containsKey(profileName)) {
- return skyBlockExperience.get(profileName);
- }
- final JsonObject profileInfo = getProfileInformation(profileName);
- int element = Utils.getElementAsInt(Utils.getElement(profileInfo, "leveling.experience"), 0);
- double level = (element / 100F);
- skyBlockExperience.put(profileName, level);
- return level;
- }
-
- public long getNetWorth(String profileName) {
- if (profileName == null) profileName = latestProfile;
- if (networth.get(profileName) != null) return networth.get(profileName);
- if (getProfileInformation(profileName) == null) return -1;
- if (getInventoryInfo(profileName) == null) return -1;
-
- JsonObject inventoryInfo = getInventoryInfo(profileName);
- JsonObject profileInfo = getProfileInformation(profileName);
-
- HashMap<String, Long> mostExpensiveInternal = new HashMap<>();
-
- long networth = 0;
- for (Map.Entry<String, JsonElement> entry : inventoryInfo.entrySet()) {
- if (entry.getValue().isJsonArray()) {
- for (JsonElement element : entry.getValue().getAsJsonArray()) {
- if (element != null && element.isJsonObject()) {
- JsonObject item = element.getAsJsonObject();
- String internalname = item.get("internalname").getAsString();
-
- if (manager.auctionManager.isVanillaItem(internalname)) continue;
-
- JsonObject bzInfo = manager.auctionManager.getBazaarInfo(internalname);
-
- long auctionPrice;
- if (bzInfo != null && bzInfo.has("curr_sell")) {
- auctionPrice = (int) bzInfo.get("curr_sell").getAsFloat();
- } else {
- auctionPrice = (long) manager.auctionManager.getItemAvgBin(internalname);
- if (auctionPrice <= 0) {
- auctionPrice = manager.auctionManager.getLowestBin(internalname);
- }
- }
-
- try {
- if (item.has("item_contents")) {
- JsonArray bytesArr = item.get("item_contents").getAsJsonArray();
- byte[] bytes = new byte[bytesArr.size()];
- for (int bytesArrI = 0; bytesArrI < bytesArr.size(); bytesArrI++) {
- bytes[bytesArrI] = bytesArr.get(bytesArrI).getAsByte();
- }
- NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes));
- NBTTagList items = contents_nbt.getTagList("i", 10);
- for (int j = 0; j < items.tagCount(); j++) {
- if (items.getCompoundTagAt(j).getKeySet().size() > 0) {
- NBTTagCompound nbt = items.getCompoundTagAt(j).getCompoundTag("tag");
- String internalname2 = manager.getInternalnameFromNBT(nbt);
- if (internalname2 != null) {
- if (manager.auctionManager.isVanillaItem(internalname2)) continue;
-
- JsonObject bzInfo2 = manager.auctionManager.getBazaarInfo(internalname2);
-
- long auctionPrice2;
- if (bzInfo2 != null && bzInfo2.has("curr_sell")) {
- auctionPrice2 = (int) bzInfo2.get("curr_sell").getAsFloat();
- } else {
- auctionPrice2 = (long) manager.auctionManager.getItemAvgBin(internalname2);
- if (auctionPrice2 <= 0) {
- auctionPrice2 = manager.auctionManager.getLowestBin(internalname2);
- }
- }
-
- int count2 = items.getCompoundTagAt(j).getByte("Count");
-
- mostExpensiveInternal.put(
- internalname2,
- auctionPrice2 * count2 + mostExpensiveInternal.getOrDefault(internalname2, 0L)
- );
- networth += auctionPrice2 * count2;
- }
- }
- }
- }
- } catch (IOException ignored) {
- }
-
- int count = 1;
- if (element.getAsJsonObject().has("count")) {
- count = element.getAsJsonObject().get("count").getAsInt();
- }
- mostExpensiveInternal.put(
- internalname,
- auctionPrice * count + mostExpensiveInternal.getOrDefault(internalname, 0L)
- );
- networth += auctionPrice * count;
- }
- }
- }
- }
- if (networth == 0) return -1;
-
- networth = (int) (networth * 1.3f);
-
- JsonObject petsInfo = getPetsInfo(profileName);
- if (petsInfo != null && petsInfo.has("pets")) {
- if (petsInfo.get("pets").isJsonArray()) {
- JsonArray pets = petsInfo.get("pets").getAsJsonArray();
- for (JsonElement element : pets) {
- if (element.isJsonObject()) {
- JsonObject pet = element.getAsJsonObject();
-
- String petname = pet.get("type").getAsString();
- String tier = pet.get("tier").getAsString();
- String tierNum = petRarityToNumMap.get(tier);
- if (tierNum != null) {
- String internalname2 = petname + ";" + tierNum;
- JsonObject info2 = manager.auctionManager.getItemAuctionInfo(internalname2);
- if (info2 == null || !info2.has("price") || !info2.has("count")) continue;
- int auctionPrice2 = (int) (info2.get("price").getAsFloat() / info2.get("count").getAsFloat());
-
- networth += auctionPrice2;
- }
- }
- }
- }
- }
-
- float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), 0);
- float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0);
-
- networth += bankBalance + purseBalance;
-
- this.networth.put(profileName, networth);
- return networth;
- }
-
- public String getLatestProfile() {
- return latestProfile;
- }
-
- public JsonArray getSkyblockProfiles(Runnable runnable) {
- if (skyblockProfiles != null) return skyblockProfiles;
-
- long currentTime = System.currentTimeMillis();
-
- if (currentTime - lastPlayerInfoState < 15 * 1000 && updatingSkyblockProfilesState.get()) return null;
- lastPlayerInfoState = currentTime;
- updatingSkyblockProfilesState.set(true);
-
- manager.apiUtils
- .newHypixelApiRequest("skyblock/profiles")
- .queryArgument("uuid", "" + uuid)
- .requestJson()
- .handle((jsonObject, throwable) -> {
- updatingSkyblockProfilesState.set(false);
-
- if (jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) {
- if (!jsonObject.has("profiles")) return null;
- skyblockProfiles = jsonObject.get("profiles").getAsJsonArray();
-
- String lastCuteName = null;
-
- profileNames.clear();
-
- for (JsonElement profileEle : skyblockProfiles) {
- JsonObject profile = profileEle.getAsJsonObject();
-
- if (!profile.has("members")) continue;
- JsonObject members = profile.get("members").getAsJsonObject();
-
- if (members.has(uuid)) {
- JsonObject member = members.get(uuid).getAsJsonObject();
-
- if (member.has("coop_invitation")) {
- if (!member.get("coop_invitation").getAsJsonObject().get("confirmed").getAsBoolean()) {
- continue;
- }
- }
-
- String cuteName = profile.get("cute_name").getAsString();
- profileNames.add(cuteName);
- if (profile.has("selected") && profile.get("selected").getAsBoolean()) {
- lastCuteName = cuteName;
- }
- }
- }
- latestProfile = lastCuteName;
-
- if (runnable != null) runnable.run();
- }
- return null;
- });
- return null;
- }
-
- public JsonObject getGuildInformation(Runnable runnable) {
- if (guildInformation != null) return guildInformation;
-
- long currentTime = System.currentTimeMillis();
-
- if (currentTime - lastGuildInfoState < 15 * 1000 && updatingGuildInfoState.get()) return null;
- lastGuildInfoState = currentTime;
- updatingGuildInfoState.set(true);
-
- manager.apiUtils
- .newHypixelApiRequest("guild")
- .queryArgument("player", "" + uuid)
- .requestJson()
- .handle((jsonObject, ex) -> {
- updatingGuildInfoState.set(false);
-
- if (jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) {
- if (!jsonObject.has("guild")) return null;
-
- guildInformation = jsonObject.get("guild").getAsJsonObject();
-
- if (runnable != null) runnable.run();
- }
- return null;
- });
- return null;
- }
-
- public List<String> getProfileNames() {
- return profileNames;
- }
-
- 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;
-
- for (JsonElement skyblockProfile : skyblockProfiles) {
- if (!skyblockProfile.isJsonObject()) {
- skyblockProfiles = null;
- return null;
- }
- if (skyblockProfile.getAsJsonObject().get("cute_name").getAsString().equalsIgnoreCase(profileName))
- return skyblockProfile.getAsJsonObject();
- }
- return null;
- }
-
- public List<JsonObject> getCoopProfileInformation(String profileName) {
- if (profileName == null) profileName = latestProfile;
- if (coopProfileMap.containsKey(profileName)) return coopProfileMap.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;
- List<JsonObject> coopList = new ArrayList<>();
- for (Map.Entry<String, JsonElement> islandMember : members.entrySet()) {
- if (!islandMember.getKey().equals(uuid)) {