diff options
| author | Moulberry <jjenour@student.unimelb.edu.au> | 2021-07-26 01:36:28 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-26 01:36:28 +0800 |
| commit | c9975b9c20161c929e2c29640eab767f97df4105 (patch) | |
| tree | a8e4a0c84dc559be1925b230dc719423dd2a5ff1 /src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java | |
| parent | 0f48092ef19488a43114478095f1d4a2040d369c (diff) | |
| parent | a7dde6d4582ad1b2474b0f59c1c74dd70b654a98 (diff) | |
| download | notenoughupdates-c9975b9c20161c929e2c29640eab767f97df4105.tar.gz notenoughupdates-c9975b9c20161c929e2c29640eab767f97df4105.tar.bz2 notenoughupdates-c9975b9c20161c929e2c29640eab767f97df4105.zip | |
Merge pull request #213 from IRONM00N/pr
Misc. Improvements now without formatting or conflicts
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.java | 2460 |
1 files changed, 1231 insertions, 1229 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 b4fce512..23c91dd0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -1,1229 +1,1231 @@ -package io.github.moulberry.notenoughupdates.profileviewer;
-
-import com.google.common.base.Splitter;
-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.util.Constants;
-import io.github.moulberry.notenoughupdates.util.Utils;
-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.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.function.Consumer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class ProfileViewer {
-
- private final NEUManager manager;
-
- public ProfileViewer(NEUManager manager) {
- this.manager = manager;
- }
-
-
- private static HashMap<String, String> petRarityToNumMap = new HashMap<>();
- static {
- petRarityToNumMap.put("COMMON", "0");
- petRarityToNumMap.put("UNCOMMON", "1");
- petRarityToNumMap.put("RARE", "2");
- petRarityToNumMap.put("EPIC", "3");
- petRarityToNumMap.put("LEGENDARY", "4");
- }
-
- private static final LinkedHashMap<String, ItemStack> skillToSkillDisplayMap = new LinkedHashMap<>();
- static {
- skillToSkillDisplayMap.put("skill_taming", Utils.createItemStack(Items.spawn_egg, EnumChatFormatting.LIGHT_PURPLE+"Taming"));
- skillToSkillDisplayMap.put("skill_mining", Utils.createItemStack(Items.stone_pickaxe, EnumChatFormatting.GRAY+"Mining"));
- skillToSkillDisplayMap.put("skill_foraging", Utils.createItemStack(Item.getItemFromBlock(Blocks.sapling), EnumChatFormatting.DARK_GREEN+"Foraging"));
- skillToSkillDisplayMap.put("skill_enchanting", Utils.createItemStack(Item.getItemFromBlock(Blocks.enchanting_table), EnumChatFormatting.GREEN+"Enchanting"));
- skillToSkillDisplayMap.put("skill_carpentry", Utils.createItemStack(Item.getItemFromBlock(Blocks.crafting_table), EnumChatFormatting.DARK_RED+"Carpentry"));
- skillToSkillDisplayMap.put("skill_farming", Utils.createItemStack(Items.golden_hoe, EnumChatFormatting.YELLOW+"Farming"));
- skillToSkillDisplayMap.put("skill_combat", Utils.createItemStack(Items.stone_sword, EnumChatFormatting.RED+"Combat"));
- skillToSkillDisplayMap.put("skill_fishing", Utils.createItemStack(Items.fishing_rod, EnumChatFormatting.AQUA+"Fishing"));
- skillToSkillDisplayMap.put("skill_alchemy", Utils.createItemStack(Items.brewing_stand, EnumChatFormatting.BLUE+"Alchemy"));
- skillToSkillDisplayMap.put("skill_runecrafting", Utils.createItemStack(Items.magma_cream, EnumChatFormatting.DARK_PURPLE+"Runecrafting"));
- //skillToSkillDisplayMap.put("skill_catacombs", Utils.createItemStack(Item.getItemFromBlock(Blocks.deadbush), EnumChatFormatting.GOLD+"Catacombs"));
- skillToSkillDisplayMap.put("slayer_zombie", Utils.createItemStack(Items.rotten_flesh, EnumChatFormatting.GOLD+"Rev Slayer"));
- skillToSkillDisplayMap.put("slayer_spider", Utils.createItemStack(Items.spider_eye, EnumChatFormatting.GOLD+"Tara Slayer"));
- skillToSkillDisplayMap.put("slayer_wolf", Utils.createItemStack(Items.bone, EnumChatFormatting.GOLD+"Sven Slayer"));
- skillToSkillDisplayMap.put("slayer_enderman", Utils.createItemStack(Items.ender_pearl, EnumChatFormatting.GOLD+"Ender Slayer"));
- }
-
- private static final ItemStack CAT_FARMING = Utils.createItemStack(Items.golden_hoe, EnumChatFormatting.YELLOW+"Farming");
- private static final ItemStack CAT_MINING = Utils.createItemStack(Items.stone_pickaxe, EnumChatFormatting.GRAY+"Mining");
- private static final ItemStack CAT_COMBAT = Utils.createItemStack(Items.stone_sword, EnumChatFormatting.RED+"Combat");
- private static final ItemStack CAT_FORAGING = Utils.createItemStack(Item.getItemFromBlock(Blocks.sapling), EnumChatFormatting.DARK_GREEN+"Foraging");
- private static final ItemStack CAT_FISHING = Utils.createItemStack(Items.fishing_rod, EnumChatFormatting.AQUA+"Fishing");
-
- private static final LinkedHashMap<ItemStack, List<String>> collectionCatToCollectionMap = new LinkedHashMap<>();
- static {
- collectionCatToCollectionMap.put(CAT_FARMING,
- Utils.createList("WHEAT", "CARROT_ITEM", "POTATO_ITEM", "PUMPKIN", "MELON", "SEEDS", "MUSHROOM_COLLECTION",
- "INK_SACK:3", "CACTUS", "SUGAR_CANE", "FEATHER", "LEATHER", "PORK", "RAW_CHICKEN", "MUTTON",
- "RABBIT", "NETHER_STALK"));
- collectionCatToCollectionMap.put(CAT_MINING,
- Utils.createList("COBBLESTONE", "COAL", "IRON_INGOT", "GOLD_INGOT", "DIAMOND", "INK_SACK:4",
- "EMERALD", "REDSTONE", "QUARTZ", "OBSIDIAN", "GLOWSTONE_DUST", "GRAVEL", "ICE", "NETHERRACK",
- "SAND", "ENDER_STONE", "MITHRIL_ORE", "HARD_STONE", "GEMSTONE_COLLECTION"));
- collectionCatToCollectionMap.put(CAT_COMBAT,
- Utils.createList("ROTTEN_FLESH", "BONE", "STRING", "SPIDER_EYE", "SULPHUR", "ENDER_PEARL",
- "GHAST_TEAR", "SLIME_BALL", "BLAZE_ROD", "MAGMA_CREAM"));
- collectionCatToCollectionMap.put(CAT_FORAGING,
- Utils.createList("LOG", "LOG:1", "LOG:2", "LOG_2:1", "LOG_2", "LOG:3"));
- collectionCatToCollectionMap.put(CAT_FISHING,
- Utils.createList("RAW_FISH", "RAW_FISH:1", "RAW_FISH:2", "RAW_FISH:3", "PRISMARINE_SHARD",
- "PRISMARINE_CRYSTALS", "CLAY_BALL", "WATER_LILY", "INK_SACK", "SPONGE"));
- }
-
- private static final LinkedHashMap<ItemStack, List<String>> collectionCatToMinionMap = new LinkedHashMap<>();
- static {
- collectionCatToMinionMap.put(CAT_FARMING,
- Utils.createList("WHEAT", "CARROT", "POTATO", "PUMPKIN", "MELON", null, "MUSHROOM",
- "COCOA", "CACTUS", "SUGAR_CANE", "CHICKEN", "COW", "PIG", null, "SHEEP",
- "RABBIT", "NETHER_WARTS"));
- collectionCatToMinionMap.put(CAT_MINING,
- Utils.createList("COBBLESTONE", "COAL", "IRON", "GOLD", "DIAMOND", "LAPIS",
- "EMERALD", "REDSTONE", "QUARTZ", "OBSIDIAN", "GLOWSTONE", "GRAVEL", "ICE", null,
- "SAND", "ENDER_STONE", "MITHRIL", "HARD_STONE", null));
- collectionCatToMinionMap.put(CAT_COMBAT,
- Utils.createList("ZOMBIE", "SKELETON", "SPIDER", "CAVESPIDER", "CREEPER", "ENDERMAN",
- "GHAST", "SLIME", "BLAZE", "MAGMA_CUBE"));
- collectionCatToMinionMap.put(CAT_FORAGING,
- Utils.createList("OAK", "SPRUCE", "BIRCH", "DARK_OAK", "ACACIA", "JUNGLE"));
- collectionCatToMinionMap.put(CAT_FISHING,
- Utils.createList("FISHING", null, null, null, null,
- null, "CLAY", null, null, null));
- }
-
- private static final LinkedHashMap<String, ItemStack> collectionToCollectionDisplayMap = new LinkedHashMap<>();
- static {
- /** FARMING COLLECTIONS **/
- collectionToCollectionDisplayMap.put("WHEAT", Utils.createItemStack(Items.wheat,
- EnumChatFormatting.YELLOW+"Wheat"));
- collectionToCollectionDisplayMap.put("CARROT_ITEM", Utils.createItemStack(Items.carrot,
- EnumChatFormatting.YELLOW+"Carrot"));
- collectionToCollectionDisplayMap.put("POTATO_ITEM", Utils.createItemStack(Items.potato,
- EnumChatFormatting.YELLOW+"Potato"));
- collectionToCollectionDisplayMap.put("PUMPKIN", Utils.createItemStack(Item.getItemFromBlock(Blocks.pumpkin),
- EnumChatFormatting.YELLOW+"Pumpkin"));
- collectionToCollectionDisplayMap.put("MELON", Utils.createItemStack(Items.melon,
- EnumChatFormatting.YELLOW+"Melon"));
- collectionToCollectionDisplayMap.put("SEEDS", Utils.createItemStack(Items.wheat_seeds,
- EnumChatFormatting.YELLOW+"Seeds"));
- collectionToCollectionDisplayMap.put("MUSHROOM_COLLECTION",
- Utils.createItemStack(Item.getItemFromBlock(Blocks.red_mushroom)
- , EnumChatFormatting.YELLOW+"Mushroom"));
- collectionToCollectionDisplayMap.put("INK_SACK:3", Utils.createItemStack(Items.dye,
- EnumChatFormatting.YELLOW+"Cocoa Beans", 3));
- collectionToCollectionDisplayMap.put("CACTUS", Utils.createItemStack(Item.getItemFromBlock(Blocks.cactus),
- EnumChatFormatting.YELLOW+"Cactus"));
- collectionToCollectionDisplayMap.put("SUGAR_CANE", Utils.createItemStack(Items.reeds,
- EnumChatFormatting.YELLOW+"Sugar Cane"));
- collectionToCollectionDisplayMap.put("FEATHER", Utils.createItemStack(Items.feather,
- EnumChatFormatting.YELLOW+"Feather"));
- collectionToCollectionDisplayMap.put("LEATHER", Utils.createItemStack(Items.leather,
- EnumChatFormatting.YELLOW+"Leather"));
- collectionToCollectionDisplayMap.put("PORK", Utils.createItemStack(Items.porkchop,
- EnumChatFormatting.YELLOW+"Porkchop"));
- collectionToCollectionDisplayMap.put("RAW_CHICKEN", Utils.createItemStack(Items.chicken,
- EnumChatFormatting.YELLOW+"Chicken"));
- collectionToCollectionDisplayMap.put("MUTTON", Utils.createItemStack(Items.mutton,
- EnumChatFormatting.YELLOW+"Mutton"));
- collectionToCollectionDisplayMap.put("RABBIT", Utils.createItemStack(Items.rabbit,
- EnumChatFormatting.YELLOW+"Rabbit"));
- collectionToCollectionDisplayMap.put("NETHER_STALK", Utils.createItemStack(Items.nether_wart,
- EnumChatFormatting.YELLOW+"Nether Wart"));
-
- /** MINING COLLECTIONS **/
- collectionToCollectionDisplayMap.put("COBBLESTONE", Utils.createItemStack(Item.getItemFromBlock(Blocks.cobblestone),
- EnumChatFormatting.GRAY+"Cobblestone"));
- collectionToCollectionDisplayMap.put("COAL", Utils.createItemStack(Items.coal,
- EnumChatFormatting.GRAY+"Coal"));
- collectionToCollectionDisplayMap.put("IRON_INGOT", Utils.createItemStack(Items.iron_ingot,
- EnumChatFormatting.GRAY+"Iron Ingot"));
- collectionToCollectionDisplayMap.put("GOLD_INGOT", Utils.createItemStack(Items.gold_ingot,
- EnumChatFormatting.GRAY+"Gold Ingot"));
- collectionToCollectionDisplayMap.put("DIAMOND", Utils.createItemStack(Items.diamond,
- EnumChatFormatting.GRAY+"Diamond"));
- collectionToCollectionDisplayMap.put("INK_SACK:4", Utils.createItemStack(Items.dye,
- EnumChatFormatting.GRAY+"Lapis Lazuli", 4));
- collectionToCollectionDisplayMap.put("EMERALD", Utils.createItemStack(Items.emerald,
- EnumChatFormatting.GRAY+"Emerald"));
- collectionToCollectionDisplayMap.put("REDSTONE", Utils.createItemStack(Items.redstone,
- EnumChatFormatting.GRAY+"Redstone"));
- collectionToCollectionDisplayMap.put("QUARTZ", Utils.createItemStack(Items.quartz,
- EnumChatFormatting.GRAY+"Nether Quartz"));
- collectionToCollectionDisplayMap.put("OBSIDIAN", Utils.createItemStack(Item.getItemFromBlock(Blocks.obsidian),
- EnumChatFormatting.GRAY+"Obsidian"));
- collectionToCollectionDisplayMap.put("GLOWSTONE_DUST", Utils.createItemStack(Items.glowstone_dust,
- EnumChatFormatting.GRAY+"Glowstone"));
- collectionToCollectionDisplayMap.put("GRAVEL", Utils.createItemStack(Item.getItemFromBlock(Blocks.gravel),
- EnumChatFormatting.GRAY+"Gravel"));
- collectionToCollectionDisplayMap.put("ICE", Utils.createItemStack(Item.getItemFromBlock(Blocks.ice),
- EnumChatFormatting.GRAY+"Ice"));
- collectionToCollectionDisplayMap.put("NETHERRACK", Utils.createItemStack(Item.getItemFromBlock(Blocks.netherrack),
- EnumChatFormatting.GRAY+"Netherrack"));
- collectionToCollectionDisplayMap.put("SAND", Utils.createItemStack(Item.getItemFromBlock(Blocks.sand),
- EnumChatFormatting.GRAY+"Sand"));
- collectionToCollectionDisplayMap.put("ENDER_STONE", Utils.createItemStack(Item.getItemFromBlock(Blocks.end_stone),
- EnumChatFormatting.GRAY+"End Stone"));
- collectionToCollectionDisplayMap.put("MITHRIL_ORE", Utils.createItemStack(Items.prismarine_crystals,
- EnumChatFormatting.GRAY+"Mithril"));
- collectionToCollectionDisplayMap.put("HARD_STONE", Utils.createItemStack(Item.getItemFromBlock(Blocks.stone),
- EnumChatFormatting.GRAY+"Hard Stone"));
- ItemStack gemstone = Utils.createItemStack(Item.getItemFromBlock(Blocks.stained_glass),
- EnumChatFormatting.GRAY+"Gem Stones");
- gemstone.setItemDamage(14);
- collectionToCollectionDisplayMap.put("GEMSTONE_COLLECTION", gemstone);
-
-
- /** COMBAT COLLECTIONS **/
- collectionToCollectionDisplayMap.put("ROTTEN_FLESH", Utils.createItemStack(Items.rotten_flesh,
- EnumChatFormatting.RED+"Rotten Flesh"));
- collectionToCollectionDisplayMap.put("BONE", Utils.createItemStack(Items.bone,
- EnumChatFormatting.RED+"Bone"));
- collectionToCollectionDisplayMap.put("STRING", Utils.createItemStack(Items.string,
- EnumChatFormatting.RED+"String"));
- collectionToCollectionDisplayMap.put("SPIDER_EYE", Utils.createItemStack(Items.spider_eye,
- EnumChatFormatting.RED+"Spider Eye"));
- collectionToCollectionDisplayMap.put("SULPHUR", Utils.createItemStack(Items.gunpowder,
- EnumChatFormatting.RED+"Gunpowder"));
- collectionToCollectionDisplayMap.put("ENDER_PEARL", Utils.createItemStack(Items.ender_pearl,
- EnumChatFormatting.RED+"Ender Pearl"));
- collectionToCollectionDisplayMap.put("GHAST_TEAR", Utils.createItemStack(Items.ghast_tear,
- EnumChatFormatting.RED+"Ghast Tear"));
- collectionToCollectionDisplayMap.put("SLIME_BALL", Utils.createItemStack(Items.slime_ball,
- EnumChatFormatting.RED+"Slimeball"));
- collectionToCollectionDisplayMap.put("BLAZE_ROD", Utils.createItemStack(Items.blaze_rod,
- EnumChatFormatting.RED+"Blaze Rod"));
- collectionToCollectionDisplayMap.put("MAGMA_CREAM", Utils.createItemStack(Items.magma_cream,
- EnumChatFormatting.RED+"Magma Cream"));
-
- /** FORAGING COLLECTIONS **/
- collectionToCollectionDisplayMap.put("LOG", Utils.createItemStack(Item.getItemFromBlock(Blocks.log),
- EnumChatFormatting.DARK_GREEN+"Oak"));
- collectionToCollectionDisplayMap.put("LOG:1", Utils.createItemStack(Item.getItemFromBlock(Blocks.log),
- EnumChatFormatting.DARK_GREEN+"Spruce", 1));
- collectionToCollectionDisplayMap.put("LOG:2", Utils.createItemStack(Item.getItemFromBlock(Blocks.log),
- EnumChatFormatting.DARK_GREEN+"Birch", 2));
- collectionToCollectionDisplayMap.put("LOG_2:1", Utils.createItemStack(Item.getItemFromBlock(Blocks.log2),
- EnumChatFormatting.DARK_GREEN+"Dark Oak", 1));
- collectionToCollectionDisplayMap.put("LOG_2", Utils.createItemStack(Item.getItemFromBlock(Blocks.log2),
- EnumChatFormatting.DARK_GREEN+"Acacia"));
- collectionToCollectionDisplayMap.put("LOG:3", Utils.createItemStack(Item.getItemFromBlock(Blocks.log),
- EnumChatFormatting.DARK_GREEN+"Jungle", 3));
-
- /** FISHING COLLECTIONS **/
- collectionToCollectionDisplayMap.put("RAW_FISH", Utils.createItemStack(Items.fish,
- EnumChatFormatting.AQUA+"Fish"));
- collectionToCollectionDisplayMap.put("RAW_FISH:1", Utils.createItemStack(Items.fish,
- EnumChatFormatting.AQUA+"Salmon", 1));
- collectionToCollectionDisplayMap.put("RAW_FISH:2", Utils.createItemStack(Items.fish,
- EnumChatFormatting.AQUA+"Clownfish", 2));
- collectionToCollectionDisplayMap.put("RAW_FISH:3", Utils.createItemStack(Items.fish,
- EnumChatFormatting.AQUA+"Pufferfish", 3));
- collectionToCollectionDisplayMap.put("PRISMARINE_SHARD", Utils.createItemStack(Items.prismarine_shard,
- EnumChatFormatting.AQUA+"Prismarine Shard"));
- collectionToCollectionDisplayMap.put("PRISMARINE_CRYSTALS", Utils.createItemStack(Items.prismarine_crystals,
- EnumChatFormatting.AQUA+"Prismarine Crystals"));
- collectionToCollectionDisplayMap.put("CLAY_BALL", Utils.createItemStack(Items.clay_ball,
- EnumChatFormatting.AQUA+"Clay"));
- collectionToCollectionDisplayMap.put("WATER_LILY", Utils.createItemStack(Item.getItemFromBlock(Blocks.waterlily),
- EnumChatFormatting.AQUA+"Lilypad"));
- collectionToCollectionDisplayMap.put("INK_SACK", Utils.createItemStack(Items.dye,
- EnumChatFormatting.AQUA+"Ink Sack"));
- collectionToCollectionDisplayMap.put("SPONGE", Utils.createItemStack(Item.getItemFromBlock(Blocks.sponge),
- EnumChatFormatting.AQUA+"Sponge"));
- }
-
- 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 class Level {
- public float level = 0;
- public float maxXpForLevel = 0;
- public boolean maxed = false;
- }
-
- public static Level getLevel(JsonArray levelingArray, float xp, int levelCap, boolean cumulative) {
- Level levelObj = new Level();
- for(int level=0; level<levelingArray.size(); level++) {
- float levelXp = levelingArray.get(level).getAsFloat();
- if(levelXp > xp) {
- if(cumulative) {
- float previous = 0;
- if(level > 0) previous = levelingArray.get(level-1).getAsFloat();
- 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 = levelingArray.size();
- if(levelObj.level > levelCap) {
- levelObj.level = levelCap;
- }
- levelObj.maxed = true;
- return levelObj;
- }
-
- public class Profile {
- private final String uuid;
- private String latestProfile = null;
-
- private JsonArray playerInformation = null;
- private JsonObject basicInfo = null;
-
- 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, JsonObject> skillInfoMap = new HashMap<>();
- private final HashMap<String, JsonObject> inventoryInfoMap = new HashMap<>();
- private final HashMap<String, JsonObject> collectionInfoMap = new HashMap<>();
- private List<String> profileIds = new ArrayList<>();
- private JsonObject playerStatus = null;
- private HashMap<String, PlayerStats.Stats> stats = new HashMap<>();
- private HashMap<String, PlayerStats.Stats> passiveStats = new HashMap<>();
- private HashMap<String, Long> networth = new HashMap<>();
-
- public Profile(String uuid) {
- this.uuid = uuid;
- }
-
- private AtomicBoolean updatingPlayerInfoState = new AtomicBoolean(false);
- private long lastPlayerInfoState = 0;
- private AtomicBoolean updatingPlayerStatusState = new AtomicBoolean(false);
-
- public JsonObject getPlayerStatus() {
- if(playerStatus != null) return playerStatus;
- if(updatingPlayerStatusState.get()) return null;
-
- updatingPlayerStatusState.set(true);
-
- HashMap<String, String> args = new HashMap<>();
- args.put("uuid", ""+uuid);
- manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "status",
- args, jsonObject -> {
- if(jsonObject == null) return;
-
- updatingPlayerStatusState.set(false);
- if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) {
- playerStatus = jsonObject.get("session").getAsJsonObject();
- }
- }, () -> updatingPlayerStatusState.set(false)
- );
-
- return null;
- }
-
- public long getNetWorth(String profileId) {
- if(profileId == null) profileId = latestProfile;
- if(networth.get(profileId) != null) return networth.get(profileId);
- if(getProfileInformation(profileId) == null) return -1;
- if(getInventoryInfo(profileId) == null) return -1;
-
- JsonObject inventoryInfo = getInventoryInfo(profileId);
- JsonObject profileInfo = getProfileInformation(profileId);
-
- 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);
-
- int auctionPrice;
- if(bzInfo != null && bzInfo.has("curr_sell")) {
- auctionPrice = (int)bzInfo.get("curr_sell").getAsFloat();
- } else {
- auctionPrice = (int)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);
-
- int auctionPrice2;
- if(bzInfo2 != null && bzInfo2.has("curr_sell")) {
- auctionPrice2 = (int)bzInfo2.get("curr_sell").getAsFloat();
- } else {
- auctionPrice2 = (int)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;
-
- //System.out.println(profileId);
- for(Map.Entry<String, Long> entry : mostExpensiveInternal.entrySet()) {
- //System.out.println(entry.getKey() + ":" + entry.getValue());
- }
-
- networth = (int)(networth*1.3f);
-
- JsonObject petsInfo = getPetsInfo(profileId);
- 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(profileId, networth);
- return networth;
- }
-
- public String getLatestProfile() {
- return latestProfile;
- }
-
- public JsonArray getPlayerInformation(Runnable runnable) {
- if (playerInformation != null) return playerInformation;
-
- long currentTime = System.currentTimeMillis();
-
- if (currentTime - lastPlayerInfoState < 15*1000 && updatingPlayerInfoState.get()) return null;
-
- lastPlayerInfoState = currentTime;
- updatingPlayerInfoState.set(true);
-
- HashMap<String, String> args = new HashMap<>();
- args.put("uuid", "" + uuid);
- manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "skyblock/profiles",
- args, jsonObject -> {
- updatingPlayerInfoState.set(false);
-
- if (jsonObject == null) return;
- if (jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) {
- playerInformation = jsonObject.get("profiles").getAsJsonArray();
- if (playerInformation == null) return;
- String backup = null;
- long backupLastSave = 0;
-
- profileIds.clear();
-
- for (int i = 0; i < playerInformation.size(); i++) {
- JsonObject profile = playerInformation.get(i).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")) {
- JsonObject coop_invitation = member.get("coop_invitation").getAsJsonObject();
- if(!coop_invitation.get("confirmed").getAsBoolean()) {
- continue;
- }
- }
-
- String cute_name = profile.get("cute_name").getAsString();
- if (backup == null) backup = cute_name;
- profileIds.add(cute_name);
- if (member.has("last_save")) {
- long last_save = member.get("last_save").getAsLong();
- if (last_save > backupLastSave) {
- backupLastSave = last_save;
- backup = cute_name;
- }
- }
-
- }
- }
- latestProfile = backup;
- if (runnable != null) runnable.run();
- }
- }, () -> {
- updatingPlayerInfoState.set(false);
- }
- );
-
- return null;
- }
-
- public List<String> getProfileIds() {
- return profileIds;
- }
-
- public JsonObject getProfileInformation(String profileId) {
- JsonArray playerInfo = getPlayerInformation(() -> {});
- if(playerInfo == null) return null;
- if(profileId == null) profileId = latestProfile;
- if(profileMap.containsKey(profileId)) return profileMap.get(profileId);
-
- for(int i=0; i<playerInformation.size(); i++) {
- if(!playerInformation.get(i).isJsonObject()) {
- playerInformation = null;
- return null;
- }
- JsonObject profile = playerInformation.get(i).getAsJsonObject();
- if(profile.get("cute_name").getAsString().equalsIgnoreCase(profileId)) {
- if(!profile.has("members")) return null;
- JsonObject members = profile.get("members").getAsJsonObject();
- if(!members.has(uuid)) continue;
- JsonObject profileInfo = members.get(uuid).getAsJsonObject();
- if(profile.has("banking")) {
- profileInfo.add("banking", profile.get("banking").getAsJsonObject());
- }
- profileMap.put(profileId, profileInfo);
- return profileInfo;
- }
- }
-
- return null;
- }
-
- public List<JsonObject> getCoopProfileInformation(String profileId) {
- JsonArray playerInfo = getPlayerInformation(() -> {});
- if(playerInfo == null) return null;
- if(profileId == null) profileId = latestProfile;
- if(coopProfileMap.containsKey(profileId)) return coopProfileMap.get(profileId);
-
- for(int i=0; i<playerInformation.size(); i++) {
- if(!playerInformation.get(i).isJsonObject()) {
- playerInformation = null;
- return null;
- }
- JsonObject profile = playerInformation.get(i).getAsJsonObject();
- if(profile.get("cute_name").getAsString().equalsIgnoreCase(profileId)) {
- if(!profile.has("members")) return null;
- JsonObject members = profile.get("members").getAsJsonObject();
- if(!members.has(uuid)) return null;
- List<JsonObject> coopList = new ArrayList<>();
- for(Map.Entry<String, JsonElement> islandMember : members.entrySet()) {
- if(!islandMember.getKey().equals(uuid)) {
- JsonObject coopProfileInfo = islandMember.getValue().getAsJsonObject();
- coopList.add(coopProfileInfo);
- }
- }
- coopProfileMap.put(profileId, coopList);
- return coopList;
- }
- }
-
- return null;
- }
-
- public void resetCache() {
- playerInformation = null;
- basicInfo = null;
- playerStatus = null;
- stats.clear();
- passiveStats.clear();
- profileIds.clear();
- profileMap.clear();
- coopProfileMap.clear();
- petsInfoMap.clear();
- skillInfoMap.clear();
- inventoryInfoMap.clear();
- collectionInfoMap.clear();
- networth.clear();
- }
-
- public int getCap(JsonObject leveling, String skillName) {
- JsonElement capsElement = Utils.getElement(leveling, "leveling_caps");
- if(capsElement == null || !capsElement.isJsonObject()) {
- return 50;
- }
- JsonObject caps = capsElement.getAsJsonObject();
- if(caps.has(skillName)) {
- return caps.get(skillName).getAsInt();
- }
- return 50;
- }
-
- public JsonObject getSkillInfo(String profileId) {
- JsonObject profileInfo = getProfileInformation(profileId);
- if(profileInfo == null) return null;
- if(profileId == null) profileId = latestProfile;
- if(skillInfoMap.containsKey(profileId)) return skillInfoMap.get(profileId);
- JsonObject leveling = Constants.LEVELING;
- if(leveling == null) return null;
-
- float experience_skill_taming = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_taming"), 0);
- float experience_skill_mining = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_mining"), 0);
- float experience_skill_foraging = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_foraging"), 0);
- float experience_skill_enchanting = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_enchanting"), 0);
- float experience_skill_carpentry = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_carpentry"), 0);
- float experience_skill_farming = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_farming"), 0);
- float experience_skill_combat = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_combat"), 0);
- float experience_skill_fishing = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_fishing"), 0);
- float experience_skill_alchemy = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_alchemy"), 0);
- float experience_skill_runecrafting = Utils.getElementAsFloat(Utils.getElement(profileInfo, "experience_skill_runecrafting"), 0);
-
- float experience_skill_catacombs = Utils.getElementAsFloat(Utils.getElement(profileInfo, "dungeons.dungeon_types.catacombs.experience"), 0);
-
- float experience_slayer_zombie = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.zombie.xp"), 0);
- float experience_slayer_spider = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.spider.xp"), 0);
- float experience_slayer_wolf = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.wolf.xp"), 0);
- float experience_slayer_enderman = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.enderman.xp"), 0);
-
-
- float totalSkillXP = experience_skill_taming + experience_skill_mining + experience_skill_foraging
- + experience_skill_enchanting + experience_skill_carpentry + experience_skill_farming
- + experience_skill_combat + experience_skill_fishing + experience_skill_alchemy
|
