-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement online player history. fix #8
- Loading branch information
1 parent
305fc1e
commit 39fc764
Showing
12 changed files
with
340 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.zrnq.mclient | ||
|
||
import org.zrnq.mcmotd.McMotd | ||
import org.zrnq.mcmotd.PluginConfig | ||
import java.awt.Font | ||
import java.awt.GraphicsEnvironment | ||
|
||
object MClientOptions { | ||
lateinit var FONT : Font | ||
var dnsServerList = listOf("223.5.5.5", "8.8.8.8") | ||
var showTrueAddress = false | ||
var recordInterval = 300 | ||
|
||
fun loadPluginConfig() { | ||
dnsServerList = if(PluginConfig.dnsServerList.isEmpty()) { | ||
McMotd.logger.warning("配置文件中没有填写DNS服务器地址,正在使用默认的DNS服务器") | ||
listOf("223.5.5.5", "8.8.8.8") | ||
} else PluginConfig.dnsServerList | ||
showTrueAddress = PluginConfig.showTrueAddress | ||
recordInterval = PluginConfig.recordInterval | ||
|
||
val fontList = mutableListOf<Font>() | ||
for(f in GraphicsEnvironment.getLocalGraphicsEnvironment().allFonts) { | ||
if(f.name == PluginConfig.fontName) { | ||
FONT = f.deriveFont(20f) | ||
return | ||
} | ||
if(f.canDisplay('啊')) { | ||
fontList.add(f) | ||
} | ||
} | ||
McMotd.logger.warning("找不到指定的字体 : ${PluginConfig.fontName},您可以在mcmotd.yml中修改字体名称") | ||
FONT = if(fontList.isEmpty()) { | ||
McMotd.logger.error("找不到可用的字体, 请检查您的系统是否安装了中文字体") | ||
Font(PluginConfig.fontName, Font.PLAIN, 20) | ||
} else { | ||
McMotd.logger.info("检测到可用的字体列表: ${fontList.joinToString(",") { it.name }}") | ||
McMotd.logger.warning("正在使用第一个可用的字体: ${fontList[0].name}") | ||
fontList[0].deriveFont(20f) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.zrnq.mclient | ||
|
||
import com.alibaba.fastjson.JSON | ||
import com.alibaba.fastjson.JSONArray | ||
import com.alibaba.fastjson.JSONObject | ||
|
||
class ServerInfo(response : String, val latency : String) { | ||
/**服务器图标*/ | ||
val favicon : String? | ||
/**服务器描述*/ | ||
val description : String | ||
/**服务器版本号*/ | ||
val version : String | ||
/**服务器在线玩家描述*/ | ||
val playerDescription : String | ||
/**在线人数*/ | ||
val onlinePlayerCount : Int? | ||
/**服务器宣称的最大人数*/ | ||
val maxPlayerCount : Int? | ||
/**服务器提供的部分在线玩家列表*/ | ||
val samplePlayerList : String? | ||
/**服务器的显示地址*/ | ||
lateinit var serverAddress : String | ||
|
||
init { | ||
val json = JSON.parseObject(response) | ||
favicon = json.getString("favicon") | ||
description = json.getString("description") | ||
version = json.getJSONObject("version").getString("name") | ||
val playerJson = json.getJSONObject("players") | ||
|
||
onlinePlayerCount = playerJson?.getIntValue("online") | ||
maxPlayerCount = playerJson?.getIntValue("max") | ||
samplePlayerList = playerJson?.getJSONArray("sample")?.toPlayerListString() | ||
|
||
playerDescription = run { | ||
if(onlinePlayerCount == null) return@run "服务器未提供在线玩家信息" | ||
val playerCount = "在线人数: $onlinePlayerCount/$maxPlayerCount 玩家列表: " | ||
if(samplePlayerList == null) return@run playerCount + "没有信息" | ||
return@run playerCount + samplePlayerList.limitLength(50) | ||
} | ||
} | ||
|
||
fun setAddress(address : String) : ServerInfo { | ||
serverAddress = address | ||
return this | ||
} | ||
|
||
|
||
companion object { | ||
fun JSONArray?.toPlayerListString() : String { | ||
return if(this == null) "没有信息" | ||
else if(isEmpty()) "空" | ||
else joinToString(", ") { (it as JSONObject).getString("name") } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.