From cceb8df8f5a1da3caff4624838515c6607867220 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:33:56 +0100 Subject: Hopefully fixed mayor npe if you cant connect to the election api (#1033) * Hopefully fixed mayor npe if you cant connect to the election api * Remove null check --- .../notenoughupdates/listener/RenderListener.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 1cb015c5..82c9b3b6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -20,7 +20,6 @@ package io.github.moulberry.notenoughupdates.listener; import com.google.common.collect.Lists; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NEUApi; import io.github.moulberry.notenoughupdates.NEUOverlay; @@ -96,6 +95,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -749,7 +749,7 @@ public class RenderListener { valueStringBIN1 = EnumChatFormatting.YELLOW + "Value (BIN): "; valueStringBIN2 = EnumChatFormatting.GOLD + formatCoins(totalValue) + " coins"; } else { - valueStringBIN1 = EnumChatFormatting.YELLOW + "Can't find BIN: "; + valueStringBIN1 = EnumChatFormatting.YELLOW + "Can't find Price: "; valueStringBIN2 = missingItem; } @@ -834,11 +834,12 @@ public class RenderListener { 160 ); } - JsonObject mayorJson = SBInfo.getInstance().getMayorJson(); - JsonElement mayor = mayorJson.get("mayor"); - if (mayorJson.has("mayor") && mayor != null && mayor.getAsJsonObject().has("name") && - mayor.getAsJsonObject().get("name").getAsString().equals("Derpy") - && NotEnoughUpdates.INSTANCE.config.dungeons.shouldWarningDerpy) { + String mayorJson = Utils.getElementAsString( + Utils.getElement(SBInfo.getInstance().getMayorJson(), "mayor.name"), + "" + ); + if (Objects.equals(mayorJson, "Derpy") && + NotEnoughUpdates.INSTANCE.config.dungeons.shouldWarningDerpy) { Utils.drawStringScaled( EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "Mayor Derpy active!", guiLeft + xSize + 4 + 10, -- cgit