From a63cb87198b563edd4ac88b226fd004d0c616360 Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Mon, 22 Nov 2021 10:59:12 -0500 Subject: Fix /hotmof error when missing API values --- src/main/java/me/Danker/commands/HOTMCommand.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/me/Danker/commands/HOTMCommand.java b/src/main/java/me/Danker/commands/HOTMCommand.java index bfb10f5..35c0b28 100644 --- a/src/main/java/me/Danker/commands/HOTMCommand.java +++ b/src/main/java/me/Danker/commands/HOTMCommand.java @@ -88,9 +88,23 @@ public class HOTMCommand extends CommandBase { System.out.println("Fetching mining stats..."); JsonObject miningCore = profileResponse.get("profile").getAsJsonObject().get("members").getAsJsonObject().get(uuid).getAsJsonObject().get("mining_core").getAsJsonObject(); - int mithril = miningCore.get("powder_mithril").getAsInt() + miningCore.get("powder_spent_mithril").getAsInt(); - int gemstone = miningCore.get("powder_gemstone").getAsInt() + miningCore.get("powder_spent_gemstone").getAsInt(); - String ability = Node.valueOf(miningCore.get("selected_pickaxe_ability").getAsString()).name; + + int mithril = 0; + if (miningCore.has("powder_mithril")) { + mithril = miningCore.get("powder_mithril").getAsInt(); + if (miningCore.has("powder_spent_mithril")) mithril += miningCore.get("powder_spent_mithril").getAsInt(); + } + + int gemstone = 0; + if (miningCore.has("powder_gemstone")) { + gemstone = miningCore.get("powder_gemstone").getAsInt(); + if (miningCore.has("powder_spent_gemstone")) gemstone += miningCore.get("powder_spent_gemstone").getAsInt(); + } + + String ability = EnumChatFormatting.RED + "None"; + if (miningCore.has("selected_pickaxe_ability")) { + ability = Node.valueOf(miningCore.get("selected_pickaxe_ability").getAsString()).name; + } ChatComponentText tree = new ChatComponentText(EnumChatFormatting.GREEN + "" + EnumChatFormatting.BOLD + "[CLICK]"); tree.setChatStyle(tree.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/hotmtree " + username + " " + latestProfile))); -- cgit