diff options
author | jani270 <69345714+jani270@users.noreply.github.com> | 2024-01-15 18:40:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 18:40:24 +0100 |
commit | 457d980d9b23055b97cdcc026bfc49912e69e52c (patch) | |
tree | 7d2635a07d09bbd6493cecc19d5ed70a4fcef70d /src | |
parent | 2fc8c7bf35fcaf6c2ccc495f7b0eabd0ff74b1f0 (diff) | |
download | NotEnoughUpdates-457d980d9b23055b97cdcc026bfc49912e69e52c.tar.gz NotEnoughUpdates-457d980d9b23055b97cdcc026bfc49912e69e52c.tar.bz2 NotEnoughUpdates-457d980d9b23055b97cdcc026bfc49912e69e52c.zip |
Fixed another crash on the rift page (#998)
Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com>
Co-authored-by: Linnea Gräf <nea@nea.moe>
Diffstat (limited to 'src')
3 files changed, 118 insertions, 50 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java index fc9ec444..8530bcb1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java @@ -19,20 +19,25 @@ package io.github.moulberry.notenoughupdates.profileviewer; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.profileviewer.bestiary.BestiaryData; +import io.github.moulberry.notenoughupdates.profileviewer.rift.RiftJson; import io.github.moulberry.notenoughupdates.profileviewer.weight.senither.SenitherWeight; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.UrsaClient; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo; +import io.github.moulberry.notenoughupdates.util.kotlin.KotlinTypeAdapterFactory; import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.init.Items; @@ -42,6 +47,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.io.ByteArrayInputStream; @@ -330,7 +336,9 @@ public class SkyblockProfiles { .get(UrsaClient.profiles(Utils.parseDashlessUUID(uuid))) .handle((profilesJson, throwable) -> { try { - if (Utils.parseDashlessUUID(uuid).toString().equals(Minecraft.getMinecraft().thePlayer.getUniqueID().toString())) { + if (Utils.parseDashlessUUID(uuid).toString().equals(Minecraft.getMinecraft().thePlayer + .getUniqueID() + .toString())) { new ProfileDataLoadedEvent(uuid, profilesJson).post(); } } catch (Exception ignored) { @@ -489,6 +497,10 @@ public class SkyblockProfiles { } } + private static final Gson gson = new GsonBuilder() + .registerTypeAdapterFactory(KotlinTypeAdapterFactory.INSTANCE) + .create(); + public class SkyblockProfile { private final JsonObject outerProfileJson; @@ -505,6 +517,8 @@ public class SkyblockProfiles { private Long networth = null; private SoopyNetworth soopyNetworth = null; private MuseumData museumData = null; + @Getter + private @Nullable RiftJson riftJson; private final AtomicBoolean updatingMuseumData = new AtomicBoolean(false); public class MuseumData { @@ -642,18 +656,23 @@ public class SkyblockProfiles { public long getValue() { return museumValue; } + public Map<String, JsonArray> getWeaponItems() { return weaponItems; } + public Map<String, JsonArray> getArmorItems() { return armorItems; } + public Map<String, JsonArray> getRaritiesItems() { return raritiesItems; } + public List<JsonArray> getSpecialItems() { return specialItems; } + public Map<String, Pair<Long, Boolean>> getSavedItems() { return savedItems; } @@ -667,29 +686,36 @@ public class SkyblockProfiles { updatingMuseumData.set(true); String profileId = getOuterProfileJson().get("profile_id").getAsString(); profileViewer.getManager().ursaClient.get(UrsaClient.museumForProfile(profileId)) - .handle((museumJson, throwable) -> { - if (museumJson != null && museumJson.has("success") - && museumJson.get("success").getAsBoolean() && museumJson.has("members")) { - museumData = new MuseumData(museumJson); - return null; - } - return null; - }); + .handle((museumJson, throwable) -> { + if (museumJson != null && museumJson.has("success") + && museumJson.get("success").getAsBoolean() && + museumJson.has("members")) { + museumData = new MuseumData(museumJson); + return null; + } + return null; + }); } public SkyblockProfile(JsonObject outerProfileJson) { this.outerProfileJson = outerProfileJson; this.gamemode = Utils.getElementAsString(outerProfileJson.get("game_mode"), null); + + try { + riftJson = gson.fromJson(getProfileJson().get("rift"), RiftJson.class); + } catch (Exception exception) { + NotEnoughUpdates.LOGGER.error("Could not read rift data", exception); + } } - public JsonObject getOuterProfileJson() { + public @NotNull JsonObject getOuterProfileJson() { return outerProfileJson; } /** * @return Profile json with UUID of {@link SkyblockProfiles#uuid} */ - public JsonObject getProfileJson() { + public @NotNull JsonObject getProfileJson() { return Utils.getElement(outerProfileJson, "members." + SkyblockProfiles.this.uuid).getAsJsonObject(); } @@ -758,7 +784,8 @@ public class SkyblockProfiles { if (invName.endsWith("bag") || invName.equals("quiver")) { path = "inventory.bag_contents." + invName + ".data"; } else if (invName.equals("candy_inventory_contents")) { - path = "shared_inventory.candy_inventory_contents"; //the mappings said that this is the new path but i cant verify that because the data doesnt exist. + path = + "shared_inventory.candy_inventory_contents"; //the mappings said that this is the new path but i cant verify that because the data doesnt exist. } String contentBytes = Utils.getElementAsString( @@ -860,7 +887,8 @@ public class SkyblockProfiles { } public boolean skillsApiEnabled() { - return Utils.getElementAsLong(Utils.getElement(getProfileJson(), "player_data.experience.SKILL_COMBAT"), -1 ) != -1; + return Utils.getElementAsLong(Utils.getElement(getProfileJson(), "player_data.experience.SKILL_COMBAT"), -1) != + -1; } /** @@ -1206,7 +1234,10 @@ public class SkyblockProfiles { if (internalName.startsWith("BEASTMASTER_CREST")) { hasBeastmasterCrest = true; try { - PetInfoOverlay.Rarity talismanRarity = PetInfoOverlay.Rarity.valueOf(internalName.replace("BEASTMASTER_CREST_", "")); + PetInfoOverlay.Rarity talismanRarity = PetInfoOverlay.Rarity.valueOf(internalName.replace( + "BEASTMASTER_CREST_", + "" + )); if (talismanRarity.beastcreatMultiplyer > currentBeastRarity.beastcreatMultiplyer) currentBeastRarity = talismanRarity; } catch (Exception ignored) { @@ -1217,16 +1248,16 @@ public class SkyblockProfiles { JsonObject stats = getProfileJson().get("player_stats").getAsJsonObject(); int mk = Utils.getElementAsInt(Utils.getElement(stats, "mythos.kills"), 0); - float petXpBoost = mk > 10000 ? 1f : mk > 7500 ? 0.9f : mk > 5000 ? 0.8f : mk > 2500 ? 0.7f : - mk > 1000 - ? 0.6f - : mk > 500 - ? 0.5f - : mk > 250 - ? 0.4f - : mk > 100 - ? 0.3f - : mk > 25 ? 0.2f : 0.1f; + float petXpBoost = mk > 10000 ? 1f : mk > 7500 ? 0.9f : mk > 5000 ? 0.8f : mk > 2500 ? 0.7f : + mk > 1000 + ? 0.6f + : mk > 500 + ? 0.5f + : mk > 250 + ? 0.4f + : mk > 100 + ? 0.3f + : mk > 25 ? 0.2f : 0.1f; PetInfoOverlay.getConfig().beastMultiplier = (petXpBoost == 0 ? 0.1f : petXpBoost) * currentBeastRarity.beastcreatMultiplyer; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftJson.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftJson.java new file mode 100644 index 00000000..684dd68b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftJson.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2024 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.rift; + +import com.google.gson.annotations.Expose; + +import java.util.List; + +public class RiftJson { + + @Expose + public RiftDeadCats dead_cats; + + public static class RiftDeadCats { + @Expose + public List<String> found_cats; + @Expose + public Pet montezuma; + + public static class Pet { + @Expose + public String type; + @Expose + public String tier; + @Expose + public Long exp; + @Expose + public int candyUsed; + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java index 93878bf0..7259260e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.rift; +import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -88,7 +89,9 @@ public class RiftPage extends GuiProfileViewerPage { return; } JsonObject profileInfo = selectedProfile.getProfileJson(); - if (!profileInfo.has("rift")) { + // TODO change everything to RiftJson walker moment + RiftJson rift = selectedProfile.getRiftJson(); + if (!profileInfo.has("rift") || rift == null) { drawErrorMessage(); return; } @@ -119,42 +122,28 @@ public class RiftPage extends GuiProfileViewerPage { Minecraft.getMinecraft().getTextureManager().bindTexture(GuiProfileViewer.pv_elements); Utils.drawTexturedRect(guiLeft + 35, guiTop + 156, 20, 20, 0, 20 / 256f, 0, 20 / 256f, GL11.GL_NEAREST); - JsonObject deadCats = Utils.getElementOrDefault( - selectedProfile.getProfileJson(), - "rift.dead_cats", - new JsonObject() - ).getAsJsonObject(); - - if (deadCats != null && !deadCats.entrySet().isEmpty() && deadCats.has("found_cats")) { - JsonArray foundCats = Utils.getElementOrDefault( - selectedProfile.getProfileJson(), - "rift.dead_cats.found_cats", - new JsonArray() - ).getAsJsonArray(); + RiftJson.RiftDeadCats deadCats = rift.dead_cats; + if (deadCats != null && deadCats.found_cats != null) { + List<String> foundCats = deadCats.found_cats; int size = foundCats.size(); int riftTime = size * 15; int manaRegen = size * 2; - JsonObject montezuma = Utils.getElementOrDefault( - selectedProfile.getProfileJson(), - "rift.dead_cats.montezuma", - new JsonObject() - ).getAsJsonObject(); + RiftJson.RiftDeadCats.Pet montezuma = deadCats.montezuma; if (montezuma != null) { - String montezumaType = montezuma.get("type").getAsString(); PetInfoOverlay.Pet pet = new PetInfoOverlay.Pet(); - pet.petLevel = new PetLeveling.PetLevel(100, 100, 0, 0, 0, montezuma.get("exp").getAsInt()); - pet.rarity = PetInfoOverlay.Rarity.valueOf(montezuma.get("tier").getAsString().toUpperCase()); - pet.petType = montezumaType; - pet.candyUsed = montezuma.get("candyUsed").getAsInt(); - ItemStack petItemstackFromPetInfo = ItemUtils.createPetItemstackFromPetInfo(pet); - Utils.drawItemStack(petItemstackFromPetInfo, guiLeft + 37, guiTop + 158, true); + pet.petLevel = new PetLeveling.PetLevel(100, 100, 0, 0, 0, montezuma.exp); + pet.rarity = PetInfoOverlay.Rarity.valueOf(montezuma.tier); + pet.petType = montezuma.type; + pet.candyUsed = montezuma.candyUsed; + ItemStack petItemStackFromPetInfo = ItemUtils.createPetItemstackFromPetInfo(pet); + Utils.drawItemStack(petItemStackFromPetInfo, guiLeft + 37, guiTop + 158, true); if ((mouseX > guiLeft + 37 && mouseX < guiLeft + 37 + 20) && (mouseY > guiTop + 158 && mouseY < guiTop + 158 + 20)) { - List<String> tooltip = petItemstackFromPetInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false); + List<String> tooltip = petItemStackFromPetInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false); tooltip.set(3, "§7Found: §9" + size + "/9 Soul Pieces"); tooltip.set(5, "§7Rift Time: §a+" + riftTime + "s"); if (pet.rarity == PetInfoOverlay.Rarity.EPIC) tooltip.set(6, "§7Mana Regen: §a+" + manaRegen + "%"); |