diff options
author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2023-02-24 20:30:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 21:30:08 +0100 |
commit | f8522cf86cfee87186366e0176ce808dba3688d4 (patch) | |
tree | c80eacd6cf0ae1302be77f9153f34399dd03e42a | |
parent | df945f9d58d4f40f9adc4727c4f8d548b21fa4b0 (diff) | |
download | NotEnoughUpdates-f8522cf86cfee87186366e0176ce808dba3688d4.tar.gz NotEnoughUpdates-f8522cf86cfee87186366e0176ce808dba3688d4.tar.bz2 NotEnoughUpdates-f8522cf86cfee87186366e0176ce808dba3688d4.zip |
Fix crashes in levels page (#626)
google null pointer exception
4 files changed, 28 insertions, 23 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java index 8bb26b09..8eb577d2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/CoreTaskLevel.java @@ -128,13 +128,14 @@ public class CoreTaskLevel { } int sbXpBankUpgrades = 0; - - JsonArray completedTasks = object.getAsJsonObject("leveling").get("completed_tasks").getAsJsonArray(); - JsonObject bankUpgradesXp = coreTask.getAsJsonObject("bank_upgrades_xp"); - for (JsonElement completedTask : completedTasks) { - String name = completedTask.getAsString(); - if (bankUpgradesXp.has(name)) { - sbXpBankUpgrades += bankUpgradesXp.get(name).getAsInt(); + if (object.has("leveling") && object.getAsJsonObject("leveling").has("completed_tasks")) { + JsonArray completedTasks = object.getAsJsonObject("leveling").get("completed_tasks").getAsJsonArray(); + JsonObject bankUpgradesXp = coreTask.getAsJsonObject("bank_upgrades_xp"); + for (JsonElement completedTask : completedTasks) { + String name = completedTask.getAsString(); + if (bankUpgradesXp.has(name)) { + sbXpBankUpgrades += bankUpgradesXp.get(name).getAsInt(); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EventTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EventTaskLevel.java index 04ace872..a5dc994a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EventTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EventTaskLevel.java @@ -56,12 +56,14 @@ public class EventTaskLevel { sbXpMiningFiesta = getCapOrAmount(miningFiestaOresMined, 1_000_000, 5_000); sbXpFishingFestival = getCapOrAmount(fishingFestivalSharksKilled, 5_000, 50); - JsonArray completedTasks = leveling.get("completed_tasks").getAsJsonArray(); - JsonObject spookyFestivalXp = eventTask.getAsJsonObject("spooky_festival_xp"); - for (JsonElement completedTask : completedTasks) { - String name = completedTask.getAsString(); - if (spookyFestivalXp.has(name)) { - sbXpSpookyFestival += spookyFestivalXp.get(name).getAsInt(); + if (leveling.has("completed_tasks")) { + JsonArray completedTasks = leveling.get("completed_tasks").getAsJsonArray(); + JsonObject spookyFestivalXp = eventTask.getAsJsonObject("spooky_festival_xp"); + for (JsonElement completedTask : completedTasks) { + String name = completedTask.getAsString(); + if (spookyFestivalXp.has(name)) { + sbXpSpookyFestival += spookyFestivalXp.get(name).getAsInt(); + } } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java index 8b7b9d2b..c9ba7636 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java @@ -88,12 +88,14 @@ public class MiscTaskLevel { // abiphone JsonObject leveling = object.getAsJsonObject("leveling"); - JsonArray completedTask = leveling.get("completed_tasks").getAsJsonArray(); - Stream<JsonElement> stream = StreamSupport.stream(completedTask.spliterator(), true); - long activeContacts = stream.map(JsonElement::getAsString).filter(s -> s.startsWith("ABIPHONE_")).count(); - JsonObject abiphone = netherIslandPlayerData.getAsJsonObject("abiphone"); - if (abiphone.has("active_contacts")) { - sbXpAbiphone = (int) activeContacts * miscellaneousTask.get("abiphone_contacts_xp").getAsInt(); + if (leveling.has("completed_tasks")) { + JsonArray completedTask = leveling.get("completed_tasks").getAsJsonArray(); + Stream<JsonElement> stream = StreamSupport.stream(completedTask.spliterator(), true); + long activeContacts = stream.map(JsonElement::getAsString).filter(s -> s.startsWith("ABIPHONE_")).count(); + JsonObject abiphone = netherIslandPlayerData.getAsJsonObject("abiphone"); + if (abiphone.has("active_contacts")) { + sbXpAbiphone = (int) activeContacts * miscellaneousTask.get("abiphone_contacts_xp").getAsInt(); + } } } @@ -101,8 +103,8 @@ public class MiscTaskLevel { int sbXpGainedHarp = 0; JsonObject harpSongsNames = miscellaneousTask.get("harp_songs_names").getAsJsonObject(); - JsonObject leveling = object.get("leveling").getAsJsonObject(); - if (leveling.has("completed_tasks")) { + JsonObject leveling = object.getAsJsonObject("leveling"); + if (leveling != null && leveling.has("completed_tasks")) { JsonArray completedTasks = leveling.get("completed_tasks").getAsJsonArray(); for (JsonElement completedTask : completedTasks) { String name = completedTask.getAsString(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SkillRelatedTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SkillRelatedTaskLevel.java index 06ab6f8c..176fc899 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SkillRelatedTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SkillRelatedTaskLevel.java @@ -167,8 +167,8 @@ public class SkillRelatedTaskLevel { } int sbXpNucleus = 0; - JsonObject leveling = object.get("leveling").getAsJsonObject(); - if (leveling.has("completions") && leveling.getAsJsonObject("completions").has("NUCLEUS_RUNS")) { + JsonObject leveling = object.getAsJsonObject("leveling"); + if (leveling != null && leveling.has("completions") && leveling.getAsJsonObject("completions").has("NUCLEUS_RUNS")) { int nucleusRuns = leveling.getAsJsonObject("completions").get("NUCLEUS_RUNS").getAsInt(); JsonElement nucleusXp = miningObj.get("crystal_nucleus_xp"); if (nucleusXp == null) { |