Skip to content

Commit

Permalink
Fix server status json parse
Browse files Browse the repository at this point in the history
  • Loading branch information
layou233 committed Jan 9, 2024
1 parent 4218c61 commit 9c52bbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/src/main/java/com/launium/mcping/server/MinecraftClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ class MinecraftClient(private val connection: Socket) :
val statusObject =
JSON.parse(statusArray, JSONReader.Feature.InitStringFieldAsEmpty) as JSONObject
val serverFavicon = statusObject["favicon"] as String
val serverDescriptionObject = statusObject["description"] as JSONObject
var serverDescriptionText = serverDescriptionObject["text"] as String
serverDescriptionObject["extra"]?.let {
(it as JSONArray).forEach { item ->
if (item is JSONObject) {
serverDescriptionText += item["text"] as String
var serverDescriptionText = ""
when (val description = statusObject["description"]) {
is JSONObject -> {
serverDescriptionText = description["text"] as String
description["extra"]?.let {
(it as JSONArray).forEach { item ->
if (item is JSONObject) {
serverDescriptionText += item["text"] as String
}
}
}
}

is String -> serverDescriptionText = description
}

// https://wiki.vg/Server_List_Ping#Ping_Request
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/server_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
android:layout_height="wrap_content"
android:editable="false"
android:text="mc.example.com"
android:textIsSelectable="true"
tools:ignore="HardcodedText" />

</com.google.android.material.textfield.TextInputLayout>
Expand Down

0 comments on commit 9c52bbf

Please sign in to comment.