Skip to content

Commit

Permalink
Fix JSON MotD string
Browse files Browse the repository at this point in the history
  • Loading branch information
ldilley committed Nov 5, 2023
1 parent 6838b2d commit 4210586
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Java/me/dilley/MineStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 4210586

Please sign in to comment.