diff options
| author | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-26 12:12:25 +1000 |
|---|---|---|
| committer | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-26 12:12:25 +1000 |
| commit | f0293a74282cece3aa8a2a328559889d6e187209 (patch) | |
| tree | e4bb3d101b8b7e70a58f521a41a44071bb6cc0fa /src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java | |
| parent | 16b89f752b83aa91f1697238d785eb97a4f01f61 (diff) | |
| download | notenoughupdates-f0293a74282cece3aa8a2a328559889d6e187209.tar.gz notenoughupdates-f0293a74282cece3aa8a2a328559889d6e187209.tar.bz2 notenoughupdates-f0293a74282cece3aa8a2a328559889d6e187209.zip | |
1.11.7
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 | 472 |
1 files changed, 408 insertions, 64 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 5706dee9..f79b4767 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -48,11 +48,202 @@ public class ProfileViewer { 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(null, null); 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")); } + 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")); + 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")); + 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")); + + /** 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+"Birch", 1)); + collectionToCollectionDisplayMap.put("LOG:2", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), + EnumChatFormatting.DARK_GREEN+"Spruce", 2)); + collectionToCollectionDisplayMap.put("LOG_2:1", Utils.createItemStack(Item.getItemFromBlock(Blocks.log2), + EnumChatFormatting.DARK_GREEN+"Jungle", 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+"Dark Oak", 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); } @@ -65,6 +256,8 @@ public class ProfileViewer { 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<>(); @@ -102,50 +295,49 @@ public class ProfileViewer { } public JsonArray getPlayerInformation(Runnable runnable) { - if(playerInformation != null) return playerInformation; - if(updatingPlayerInfoState.get()) return null; + if (playerInformation != null) return playerInformation; + if (updatingPlayerInfoState.get()) return null; updatingPlayerInfoState.set(true); HashMap<String, String> args = new HashMap<>(); - args.put("uuid", ""+uuid); + args.put("uuid", "" + uuid); manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/profiles", - args, jsonObject -> { - if(jsonObject == null) return; - - updatingPlayerInfoState.set(false); - if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { - playerInformation = jsonObject.get("profiles").getAsJsonArray(); - if(playerInformation == null) return; - String backup = null; - long backupLastSave = 0; - for(int i=0; i<playerInformation.size(); i++) { - JsonObject profile = playerInformation.get(i).getAsJsonObject(); - String cute_name = profile.get("cute_name").getAsString(); - - if(backup == null) backup = cute_name; - - if(!profile.has("members")) continue; - JsonObject members = profile.get("members").getAsJsonObject(); - - if(members.has(uuid)) { - JsonObject member = members.get(uuid).getAsJsonObject(); - if(member.has("last_save")) { - long last_save = member.get("last_save").getAsLong(); - if(last_save > backupLastSave) { - backupLastSave = last_save; - backup = cute_name; + args, jsonObject -> { + if (jsonObject == null) return; + + updatingPlayerInfoState.set(false); + if (jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + playerInformation = jsonObject.get("profiles").getAsJsonArray(); + if (playerInformation == null) return; + String backup = null; + long backupLastSave = 0; + for (int i = 0; i < playerInformation.size(); i++) { + JsonObject profile = playerInformation.get(i).getAsJsonObject(); + String cute_name = profile.get("cute_name").getAsString(); + + if (backup == null) backup = cute_name; + + if (!profile.has("members")) continue; + JsonObject members = profile.get("members").getAsJsonObject(); + + if (members.has(uuid)) { + JsonObject member = members.get(uuid).getAsJsonObject(); + if (member.has("last_save")) { + long last_save = member.get("last_save").getAsLong(); + if (last_save > backupLastSave) { + backupLastSave = last_save; + backup = cute_name; + } } } } + if (runnable != null) runnable.run(); + latestProfile = backup; } - System.out.println("accepting runnable"); - if(runnable != null) runnable.run(); - latestProfile = backup; + }, () -> { + updatingPlayerInfoState.set(false); } - }, () -> { - updatingPlayerInfoState.set(false); - } ); return null; @@ -171,12 +363,41 @@ public class ProfileViewer { if(profile.has("banking")) { profileInfo.add("banking", profile.get("banking").getAsJsonObject()); } - System.out.println("got profile"); profileMap.put(profileId, profileInfo); return profileInfo; } } - System.out.println("couldnt get profile"); + + 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; } @@ -185,7 +406,11 @@ public class ProfileViewer { playerInformation = null; basicInfo = null; playerStatus = null; + stats = null; + passiveStats = null; profileMap.clear(); + coopProfileMap.clear(); + petsInfoMap.clear(); skillInfoMap.clear(); inventoryInfoMap.clear(); collectionInfoMap.clear(); @@ -250,7 +475,6 @@ public class ProfileViewer { + experience_skill_runecrafting; if(totalSkillXP <= 0) { - System.out.println("couldnt get skill xp"); return null; } @@ -340,8 +564,6 @@ public class ProfileViewer { if(profileId == null) profileId = latestProfile; if(inventoryInfoMap.containsKey(profileId)) return inventoryInfoMap.get(profileId); - //inv_armor, fishing_bag, quiver, ender_chest_contents, wardrobe_contents, potion_bag, inv_contents, talisman_bag, candy_inventory_contents - String inv_armor_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "inv_armor.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); String fishing_bag_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "fishing_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); String quiver_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "quiver.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); @@ -378,47 +600,148 @@ public class ProfileViewer { return inventoryInfo; } + public JsonObject getPetsInfo(String profileId) { + JsonObject profileInfo = getProfileInformation(profileId); + if(profileInfo == null) return null; + if(petsInfoMap.containsKey(profileId)) return petsInfoMap.get(profileId); + + JsonObject petsInfo = new JsonObject(); + JsonElement petsElement = profileInfo.get("pets"); + if(petsElement != null && petsElement.isJsonArray()) { + JsonObject activePet = null; + JsonArray pets = petsElement.getAsJsonArray(); + for(int i=0; i<pets.size(); i++) { + JsonObject pet = pets.get(i).getAsJsonObject(); + if(pet.has("active") && pet.get("active").getAsJsonPrimitive().getAsBoolean()) { + activePet = pet; + break; + } + } + petsInfo.add("active_pet", activePet); + petsInfo.add("pets", pets); + petsInfoMap.put(profileId, petsInfo); + return petsInfo; + } + return null; + } + private final Pattern COLL_TIER_PATTERN = Pattern.compile("_(-?[0-9]+)"); public JsonObject getCollectionInfo(String profileId) { JsonObject profileInfo = getProfileInformation(profileId); if(profileInfo == null) return null; + JsonObject resourceCollectionInfo = getResourceCollectionInformation(); + if(resourceCollectionInfo == null) return null; if(profileId == null) profileId = latestProfile; if(collectionInfoMap.containsKey(profileId)) return collectionInfoMap.get(profileId); - JsonElement unlocked_coll_tiers_element = Utils.getElement(profileInfo, "unlocked_coll_tiers"); - if(unlocked_coll_tiers_element == null) { - JsonObject collectionInfo = new JsonObject(); - collectionInfo.add("collection_tiers", new JsonObject()); - return collectionInfo; + JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); + JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); + + JsonObject collectionInfo = new JsonObject(); + JsonObject collectionTiers = new JsonObject(); + JsonObject minionTiers = new JsonObject(); + JsonObject personalAmounts = new JsonObject(); + JsonObject totalAmounts = new JsonObject(); + + if(collectionInfoElement != null && collectionInfoElement.isJsonObject()) { + personalAmounts = collectionInfoElement.getAsJsonObject(); } - JsonArray unlocked_coll_tiers = unlocked_coll_tiers_element.getAsJsonArray(); - JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collections"); - if(collectionInfoElement == null) { - JsonObject collectionInfo = new JsonObject(); - collectionInfo.add("collection_tiers", new JsonObject()); - return collectionInfo; + for(Map.Entry<String, JsonElement> entry : personalAmounts.entrySet()) { + totalAmounts.addProperty(entry.getKey(), entry.getValue().getAsInt()); } - JsonObject collectionInfo = collectionInfoElement.getAsJsonObject(); - JsonObject collectionTiers = new JsonObject(); - for(int i=0; i<unlocked_coll_tiers.size(); i++) { - String unlocked = unlocked_coll_tiers.get(i).getAsString(); + List<JsonObject> coopProfiles = getCoopProfileInformation(profileId); + if(coopProfiles != null) { + for(JsonObject coopProfile : coopProfiles) { + JsonElement coopCollectionInfoElement = Utils.getElement(coopProfile, "collection"); + if(coopCollectionInfoElement != null && coopCollectionInfoElement.isJsonObject()) { + for(Map.Entry<String, JsonElement> entry : coopCollectionInfoElement.getAsJsonObject().entrySet()) { + float existing = Utils.getElementAsFloat(totalAmounts.get(entry.getKey()), 0); + totalAmounts.addProperty(entry.getKey(), existing+entry.getValue().getAsInt()); + } + } + } + } + + if(unlocked_coll_tiers_element != null && unlocked_coll_tiers_element.isJsonArray()) { + JsonArray unlocked_coll_tiers = unlocked_coll_tiers_element.getAsJsonArray(); + for(int i=0; i<unlocked_coll_tiers.size(); i++) { + String unlocked = unlocked_coll_tiers.get(i).getAsString(); - Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); + Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); - if(matcher.find()) { - String tier_str = matcher.group(1); - int tier = Integer.parseInt(tier_str); - String coll = unlocked.substring(0, unlocked.length()-(matcher.group().length())); - if(!collectionTiers.has(coll) || collectionTiers.get(coll).getAsInt() < tier) { - collectionTiers.addProperty(coll, tier); + if(matcher.find()) { + String tier_str = matcher.group(1); + int tier = Integer.parseInt(tier_str); + String coll = unlocked.substring(0, unlocked.length()-(matcher.group().length())); + if(!collectionTiers.has(coll) || collectionTiers.get(coll).getAsInt() < tier) { + collectionTiers.addProperty(coll, tier); + } } } } - collectionInfo.add("collection_tiers", collectionInfo); + if(crafted_generators_element != null && crafted_generators_element.isJsonArray()) { + JsonArray crafted_generators = crafted_generators_element.getAsJsonArray(); + for(int i=0; i<crafted_generators.size(); i++) { + String unlocked = crafted_generators.get(i).getAsString(); + + Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); + + if(matcher.find()) { + String tier_str = matcher.group(1); + int tier = Integer.parseInt(tier_str); + String coll = unlocked.substring(0, unlocked.length()-(matcher.group().length())); + if(!minionTiers.has(coll) || minionTiers.get(coll).getAsInt() < tier) { + minionTiers.addProperty(coll, tier); + } + } + } + } + + JsonObject maxAmount = new JsonObject(); + JsonObject updatedCollectionTiers = new JsonObject(); + for(Map.Entry<String, JsonElement> totalAmountsEntry : totalAmounts.entrySet()) { + String collName = totalAmountsEntry.getKey(); + int collTier = (int)Utils.getElementAsFloat(collectionTiers.get(collName), 0); + + int currentAmount = (int)Utils.getElementAsFloat(totalAmounts.get(collName), 0); + if(currentAmount > 0) { + for(Map.Entry<String, JsonElement> resourceEntry : resourceCollectionInfo.entrySet()) { + JsonElement tiersElement = Utils.getElement(resourceEntry.getValue(), "items."+collName+".tiers"); + if(tiersElement != null && tiersElement.isJsonArray()) { + JsonArray tiers = tiersElement.getAsJsonArray(); + int maxTierAcquired = -1; + int maxAmountRequired = -1; + for(int i=0; i<tiers.size(); i++) { + JsonObject tierInfo = tiers.get(i).getAsJsonObject(); + int tier = tierInfo.get("tier").getAsInt(); + int amountRequired = tierInfo.get("amountRequired").getAsInt(); + if(currentAmount >= amountRequired) { + maxTierAcquired = tier; + } + maxAmountRequired = amountRequired; + } + if(maxTierAcquired >= 0 && maxTierAcquired > collTier) { + updatedCollectionTiers.addProperty(collName, maxTierAcquired); + } + maxAmount.addProperty(collName, maxAmountRequired); + } + } + } + } + + for(Map.Entry<String, JsonElement> collectionTiersEntry : updatedCollectionTiers.entrySet()) { + collectionTiers.add(collectionTiersEntry.getKey(), collectionTiersEntry.getValue()); + } + + collectionInfo.add("minion_tiers", minionTiers); + collectionInfo.add("max_amounts", maxAmount); + collectionInfo.add("personal_amounts", personalAmounts); + collectionInfo.add("total_amounts", totalAmounts); + collectionInfo.add("collection_tiers", collectionTiers); return collectionInfo; } @@ -492,10 +815,8 @@ public class ProfileViewer { public Profile getProfile(String uuid, Consumer<Profile> callback) { Profile profile = uuidToProfileMap.computeIfAbsent(uuid, k -> new Profile(uuid)); if(profile.playerInformation != null) { - System.out.println("getting profile with callback1"); callback.accept(profile); } else { - System.out.println("getting profile with callback3"); profile.getPlayerInformation(() -> callback.accept(profile)); } return profile; @@ -507,4 +828,27 @@ public class ProfileViewer { return profile; } + private static JsonObject resourceCollection = null; + private static AtomicBoolean updatingResourceCollection = new AtomicBoolean(false); + public static JsonObject getResourceCollectionInformation() { + if(resourceCollection != null) return resourceCollection; + if(updatingResourceCollection.get()) return null; + + updatingResourceCollection.set(true); + + HashMap<String, String> args = new HashMap<>(); + NotEnoughUpdates.INSTANCE.manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.manager.config.apiKey.value, "resources/skyblock/collections", + args, jsonObject -> { + updatingResourceCollection.set(false); + if(jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + resourceCollection = jsonObject.get("collections").getAsJsonObject(); + } + }, () -> { + updatingResourceCollection.set(false); + } + ); + + return null; + } + } |
