diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java | 30 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java | 100 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerUtils.java | 156 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java | 5 | ||||
-rw-r--r-- | src/main/kotlin/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.kt (renamed from src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java) | 34 |
5 files changed, 201 insertions, 124 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java index 31dd71eb..907f0f0d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java @@ -19,10 +19,13 @@ package io.github.moulberry.notenoughupdates.miscfeatures; +import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent; import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewerUtils; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -54,13 +57,25 @@ public class PowerStoneStatsDisplay { } @SubscribeEvent + public void onProfileDataLoaded(ProfileDataLoadedEvent event) { + JsonObject profileInfo = event.getProfileInfo(); + + if (profileInfo == null) return; + + JsonObject inventoryInfo = ProfileViewerUtils.readInventoryInfo(profileInfo, "talisman_bag"); + if (inventoryInfo == null) return; + + NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (configProfileSpecific == null) return; + int powerAmount = ProfileViewerUtils.getMagicalPower(inventoryInfo, profileInfo); + configProfileSpecific.magicalPower = powerAmount; + } + + @SubscribeEvent public void onTick(TickEvent event) { + if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.powerStoneStats) return; if (!dirty) return; - - if (!Utils.getOpenChestName().equals("SkyBlock Menu")) { - dirty = false; - return; - } + if (!Utils.getOpenChestName().equals("Your Bags")) return; EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; Container openContainer = p.openContainer; @@ -70,14 +85,15 @@ public class PowerStoneStatsDisplay { String displayName = stack.getDisplayName(); if (!"§aAccessory Bag".equals(displayName)) continue; + dirty = false; for (String line : ItemUtils.getLore(stack)) { if (line.startsWith("§7Magical Power: ")) { String rawNumber = line.split("§6")[1].replace(",", ""); NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if (configProfileSpecific == null) return; - configProfileSpecific.magicalPower = Integer.parseInt(rawNumber); - dirty = false; + int magicalPower = Integer.parseInt(rawNumber); + configProfileSpecific.magicalPower = magicalPower; } } } 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 610e4090..17a14d1f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -28,7 +28,6 @@ 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.JsonUtils; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo; import net.minecraft.init.Blocks; @@ -36,7 +35,6 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; @@ -44,25 +42,20 @@ import net.minecraft.util.EnumChatFormatting; import javax.annotation.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.util.AbstractMap; 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.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Objects; -import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.regex.Pattern; -import java.util.stream.Collectors; public class ProfileViewer { @@ -703,98 +696,7 @@ public class ProfileViewer { return -1; } - Map<String, Integer> accessories = JsonUtils.getJsonArrayAsStream(inventoryInfo - .get("talisman_bag") - .getAsJsonArray()).map(o -> { - try { - return JsonToNBT.getTagFromJson(o - .getAsJsonObject() - .get("nbttag") - .getAsString()); - } catch (Exception ignored) { - return null; - } - }).filter(Objects::nonNull).map(tag -> { - NBTTagList loreTagList = tag.getCompoundTag("display").getTagList("Lore", 8); - String lastElement = loreTagList.getStringTagAt(loreTagList.tagCount() - 1); - if (lastElement.contains(EnumChatFormatting.OBFUSCATED.toString())) { - lastElement = lastElement.substring(lastElement.indexOf(' ')).trim().substring(4); - } - JsonArray lastElementJsonArray = new JsonArray(); - lastElementJsonArray.add(new JsonPrimitive(lastElement)); - return new AbstractMap.SimpleEntry<>( - tag.getCompoundTag("ExtraAttributes").getString("id"), - Utils.getRarityFromLore(lastElementJsonArray) - ); - }).sorted(Comparator.comparingInt(e -> -e.getValue())).collect(Collectors.toMap( - Map.Entry::getKey, - Map.Entry::getValue, - (v1, v2) -> v1, - LinkedHashMap::new - )); - - Set<String> ignoredTalismans = new HashSet<>(); - int powerAmount = 0; - for (Map.Entry<String, Integer> entry : accessories.entrySet()) { - if (ignoredTalismans.contains(entry.getKey())) { - continue; - } - - JsonArray children = Utils - .getElementOrDefault(Constants.PARENTS, entry.getKey(), new JsonArray()) - .getAsJsonArray(); - for (JsonElement child : children) { - ignoredTalismans.add(child.getAsString()); - } - - if (entry.getKey().equals("HEGEMONY_ARTIFACT")) { - switch (entry.getValue()) { - case 4: - powerAmount += 16; - break; - case 5: - powerAmount += 22; - break; - } - } - if (entry.getKey().equals("ABICASE")) { - if (profileInfo != null && profileInfo.has("nether_island_player_data") && - profileInfo.get("nether_island_player_data").getAsJsonObject().has("abiphone") && profileInfo - .get( - "nether_island_player_data") - .getAsJsonObject() - .get("abiphone") - .getAsJsonObject() - .has("active_contacts")) { // BatChest - int contact = - profileInfo.get("nether_island_player_data").getAsJsonObject().get("abiphone").getAsJsonObject().get( - "active_contacts").getAsJsonArray().size(); - powerAmount += Math.floor(contact / 2); - } - } - switch (entry.getValue()) { - case 0: - case 6: - powerAmount += 3; - break; - case 1: - case 7: - powerAmount += 5; - break; - case 2: - powerAmount += 8; - break; - case 3: - powerAmount += 12; - break; - case 4: - powerAmount += 16; - break; - case 5: - powerAmount += 22; - break; - } - } + int powerAmount = ProfileViewerUtils.getMagicalPower(inventoryInfo, profileInfo); magicalPower.put(profileId, powerAmount); return powerAmount; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerUtils.java new file mode 100644 index 00000000..66164688 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerUtils.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +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.util.Constants; +import io.github.moulberry.notenoughupdates.util.JsonUtils; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.AbstractMap; +import java.util.Base64; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +public class ProfileViewerUtils { + + public static JsonObject readInventoryInfo(JsonObject profileInfo, String bagName) { + JsonObject inventoryInfo = new JsonObject(); + JsonElement element = Utils.getElement(profileInfo, bagName + ".data"); + + String bytes = Utils.getElementAsString(element, "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); + NBTTagCompound inv_contents_nbt; + try { + inv_contents_nbt = CompressedStreamTools.readCompressed( + new ByteArrayInputStream(Base64.getDecoder().decode(bytes)) + ); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + NBTTagList items = inv_contents_nbt.getTagList("i", 10); + JsonArray contents = new JsonArray(); + NEUManager manager = NotEnoughUpdates.INSTANCE.manager; + for (int j = 0; j < items.tagCount(); j++) { + JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); + contents.add(item); + } + + inventoryInfo.add(bagName, contents); + return inventoryInfo; + } + + public static int getMagicalPower(JsonObject inventoryInfo, JsonObject profileInfo) { + JsonArray talismanBag = inventoryInfo.get("talisman_bag").getAsJsonArray(); + Map<String, Integer> accessories = JsonUtils.getJsonArrayAsStream(talismanBag).map(o -> { + try { + return JsonToNBT.getTagFromJson(o.getAsJsonObject().get("nbttag").getAsString()); + } catch (Exception ignored) { + return null; + } + }).filter(Objects::nonNull).map(tag -> { + NBTTagList loreTagList = tag.getCompoundTag("display").getTagList("Lore", 8); + String lastElement = loreTagList.getStringTagAt(loreTagList.tagCount() - 1); + if (lastElement.contains(EnumChatFormatting.OBFUSCATED.toString())) { + lastElement = lastElement.substring(lastElement.indexOf(' ')).trim().substring(4); + } + JsonArray lastElementJsonArray = new JsonArray(); + lastElementJsonArray.add(new JsonPrimitive(lastElement)); + return new AbstractMap.SimpleEntry<>(tag.getCompoundTag("ExtraAttributes").getString("id"), + Utils.getRarityFromLore(lastElementJsonArray) + ); + }).sorted(Comparator.comparingInt(e -> -e.getValue())).collect(Collectors.toMap( + Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1, LinkedHashMap::new + )); + + Set<String> ignoredTalismans = new HashSet<>(); + int powerAmount = 0; + for (Map.Entry<String, Integer> entry : accessories.entrySet()) { + if (ignoredTalismans.contains(entry.getKey())) continue; + + JsonArray children = Utils + .getElementOrDefault(Constants.PARENTS, entry.getKey(), new JsonArray()) + .getAsJsonArray(); + for (JsonElement child : children) { + ignoredTalismans.add(child.getAsString()); + } + + if (entry.getKey().equals("HEGEMONY_ARTIFACT")) { + switch (entry.getValue()) { + case 4: + powerAmount += 16; + break; + case 5: + powerAmount += 22; + break; + } + } + if (entry.getKey().equals("ABICASE")) { + if (profileInfo != null && profileInfo.has("nether_island_player_data")) { + JsonObject data = profileInfo.get("nether_island_player_data").getAsJsonObject(); + if (data.has("abiphone") && data.get("abiphone").getAsJsonObject().has("active_contacts")) { // BatChest + int contact = data.get("abiphone").getAsJsonObject().get("active_contacts").getAsJsonArray().size(); + powerAmount += Math.floor(contact / 2); + } + } + } + switch (entry.getValue()) { + case 0: + case 6: + powerAmount += 3; + break; + case 1: + case 7: + powerAmount += 5; + break; + case 2: + powerAmount += 8; + break; + case 3: + powerAmount += 12; + break; + case 4: + powerAmount += 16; + break; + case 5: + powerAmount += 22; + break; + } + } + return powerAmount; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index c86ac84f..0c590bab 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -89,11 +89,12 @@ public class ApiUtil { public void updateProfileData(String playerUuid) { if (!updateTasks.getOrDefault(playerUuid, CompletableFuture.completedFuture(null)).isDone()) return; + String uuid = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", ""); updateTasks.put(playerUuid, newHypixelApiRequest("skyblock/profiles") - .queryArgument("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")) + .queryArgument("uuid", uuid) .requestJson() .handle((jsonObject, throwable) -> { - new ProfileDataLoadedEvent(jsonObject).post(); + new ProfileDataLoadedEvent(uuid, jsonObject).post(); return null; })); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.kt index 956acfe0..00a535c6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.kt @@ -16,25 +16,27 @@ * You should have received a copy of the GNU Lesser General Public License * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. */ +package io.github.moulberry.notenoughupdates.events -package io.github.moulberry.notenoughupdates.events; - -import com.google.gson.JsonObject; - -import javax.annotation.Nullable; +import com.google.gson.JsonObject //TODO extend the usage of this event (accessory bag and storage data) -public class ProfileDataLoadedEvent extends NEUEvent { - - @Nullable - private final JsonObject data; +class ProfileDataLoadedEvent(val uuid: String, val data: JsonObject?) : NEUEvent() { + val profileInfo: JsonObject? by lazy { readProfileInfo() } - public ProfileDataLoadedEvent(@Nullable JsonObject entireApiResponse) { - this.data = entireApiResponse; - } + private fun readProfileInfo(): JsonObject? { + if (data == null) return null - @Nullable - public JsonObject getData() { - return data; - } + val skyblockProfiles = data["profiles"].asJsonArray + for (profileEle in skyblockProfiles) { + val profile = profileEle.asJsonObject + if (!profile.has("members")) continue + val members = profile["members"].asJsonObject + if (!members.has(uuid)) continue + if (profile.has("selected") && profile["selected"].asBoolean) { + return members[uuid].asJsonObject + } + } + return null + } } |