From 421058670de21c5bcfffc05c43c464de1d4f4ea1 Mon Sep 17 00:00:00 2001 From: Lloyd Dilley Date: Sun, 5 Nov 2023 13:39:18 -0500 Subject: [PATCH] Fix JSON MotD string --- Java/me/dilley/MineStat.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Java/me/dilley/MineStat.java b/Java/me/dilley/MineStat.java index 7b3194c..d70d9a1 100644 --- a/Java/me/dilley/MineStat.java +++ b/Java/me/dilley/MineStat.java @@ -749,15 +749,23 @@ public ConnectionStatus jsonRequest(String address, int port, int timeout) // Populate object from JSON data JsonObject jobj = new Gson().fromJson(new String(rawData), JsonObject.class); setProtocol(jobj.get("version").getAsJsonObject().get("protocol").getAsInt()); - setMotd(jobj.get("description").getAsString()); - try + + if(!jobj.has("description")) { - setStrippedMotd(stripMotdFormatting(jobj.get("description").getAsJsonObject())); + setMotd(""); + setStrippedMotd(""); } - catch(Exception e) + else if(jobj.get("description").isJsonPrimitive()) { + setMotd(jobj.get("description").getAsString()); setStrippedMotd(stripMotdFormatting(jobj.get("description").getAsString())); } + else + { + setMotd(jobj.get("description").toString()); + setStrippedMotd(stripMotdFormatting(jobj.get("description").getAsJsonObject())); + } + setVersion(jobj.get("version").getAsJsonObject().get("name").getAsString()); setCurrentPlayers(jobj.get("players").getAsJsonObject().get("online").getAsInt()); setMaximumPlayers(jobj.get("players").getAsJsonObject().get("max").getAsInt());