File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
src/main/kotlin/NoMathExpectation/chatExchange/neoForged Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -63,4 +63,18 @@ data class PlayerDieEvent(
6363data class PlayerAdvancementEvent (
6464 val name : String ,
6565 val advancement : String ,
66+ ) : ExchangeEvent
67+
68+ @Serializable
69+ @SerialName(" status_ping" )
70+ data object StatusPingEvent : ExchangeEvent
71+
72+ @Serializable
73+ @SerialName(" status" )
74+ data class StatusEvent (
75+ val version : String ,
76+ val brand : String ,
77+ val playerNumber : Int ,
78+ val maxPlayerNumber : Int ,
79+ val playerNames : List <String >,
6680) : ExchangeEvent
Original file line number Diff line number Diff line change @@ -96,6 +96,12 @@ class ExchangeServer(
9696 kotlin.runCatching {
9797 val event = channel.readExchangeEvent()
9898 logger.info(" Received event: $event " )
99+
100+ if (event is StatusPingEvent ) {
101+ sendEvent(buildStatusEvent())
102+ return @runCatching
103+ }
104+
99105 if (event !is MessageEvent ) {
100106 return @runCatching
101107 }
@@ -146,6 +152,17 @@ class ExchangeServer(
146152
147153 fun componentToString (component : Component ) = component.getStringWithLanguage(language)
148154
155+ private fun buildStatusEvent (): StatusEvent {
156+ val players = minecraftServer.playerList
157+ return StatusEvent (
158+ version = minecraftServer.serverVersion,
159+ brand = minecraftServer.serverModName,
160+ playerNumber = players.playerCount,
161+ maxPlayerNumber = players.maxPlayers,
162+ playerNames = players.playerNamesArray.filterNotNull(),
163+ )
164+ }
165+
149166 fun launch () {
150167 if (launched) {
151168 error(" Server is already launched!" )
You can’t perform that action at this time.
0 commit comments