Skip to content

Commit

Permalink
Implement server version & player list display conf, fix #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Under-estimate committed Dec 2, 2022
1 parent 91f3857 commit ffaa28f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
| -- | -- | -- |
| fontName | 字符串(默认`Microsoft YaHei`) | 指定渲染图片时使用的字体名称 |
| showTrueAddress | 布尔值(默认`false`) | 设置为`true`时,服务器状态图片中显示服务器的真实地址。设置为`false`时,服务器状态图片中显示服务器的SRV地址 |
| showServerVersion | 布尔值(默认`false`) | 设置为`true`时,服务器状态图片中显示服务器版本号 |
| showPlayerList | 布尔值(默认`true`) | 设置为`true`时,服务器状态图片中显示当前在线的部分玩家(某些服务器可能不提供此信息,或提供非玩家信息的任意文本) |
| dnsServerList | 字符串列表 | 指定进行SRV解析时所用的DNS服务器 |
| recordOnlinePlayer | 字符串列表 | 已启用历史在线人数记录的服务器 |
| recordInterval | 整数 | 记录在线人数的时间间隔(秒) |
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "org.zrnq"
version = "1.1.9"
version = "1.1.10"

repositories {
maven("https://maven.aliyun.com/repository/public")
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/org/zrnq/mclient/MClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.zrnq.mclient.output.AbstractOutputHandler
import java.awt.Color
import java.awt.RenderingHints
import java.awt.image.BufferedImage
import java.lang.StringBuilder
import java.net.Inet4Address
import java.net.InetSocketAddress
import java.net.Socket
Expand Down Expand Up @@ -88,11 +89,10 @@ fun renderBasicInfoImage(info : ServerInfo) : BufferedImage {
g.drawRect(border, border, height - 2 * border, height - 2 * border)
paintDescription(info.description, g, height, border, width - border - height, height / 2 - border)

paintString("""
访问地址: ${info.serverAddress} Ping: ${info.latency}
${info.version.limitLength(50)}
${info.playerDescription}""".trimIndent()
, g, height, height / 2, width - border - height, height / 2 - border)
val sb = StringBuilder("访问地址: ${info.serverAddress} Ping: ${info.latency}")
if(MClientOptions.showServerVersion) sb.append("\n${info.version.limitLength(50)}")
sb.append("\n${info.playerDescription}")
paintString(sb.toString(), g, height, height / 2, width - border - height, height / 2 - border)
return result
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/zrnq/mclient/MClientOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ object MClientOptions {
lateinit var FONT : Font
var dnsServerList = listOf("223.5.5.5", "8.8.8.8")
var showTrueAddress = false
var recordInterval = 300
var showServerVersion = false
var showPlayerList = true

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
showServerVersion = PluginConfig.showServerVersion
showPlayerList = PluginConfig.showPlayerList

val fontList = mutableListOf<Font>()
for(f in GraphicsEnvironment.getLocalGraphicsEnvironment().allFonts) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/zrnq/mclient/ServerInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class ServerInfo(response : String, val latency : String) {

playerDescription = run {
if(onlinePlayerCount == null) return@run "服务器未提供在线玩家信息"
val playerCount = "在线人数: $onlinePlayerCount/$maxPlayerCount 玩家列表: "
var playerCount = "在线人数: $onlinePlayerCount/$maxPlayerCount "
if(!MClientOptions.showPlayerList) return@run playerCount
playerCount += "玩家列表: "
if(samplePlayerList == null) return@run playerCount + "没有信息"
return@run playerCount + samplePlayerList.limitLength(50)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/zrnq/mcmotd/McMotd.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object McMotd : KotlinPlugin(
JvmPluginDescription(
id = "org.zrnq.mcmotd",
name = "Minecraft MOTD Fetcher",
version = "1.1.9",
version = "1.1.10",
) {
author("ZRnQ")
info("""以图片的形式获取指定Minecraft服务器的基本信息""")
Expand Down Expand Up @@ -61,7 +61,7 @@ object McMotd : KotlinPlugin(
)
}
}
}, MClientOptions.recordInterval.toLong() * 1000, MClientOptions.recordInterval.toLong() * 1000)
}, PluginConfig.recordInterval.toLong() * 1000, PluginConfig.recordInterval.toLong() * 1000)
}

private fun stopRecord() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/zrnq/mcmotd/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import net.mamoe.mirai.console.data.value
object PluginConfig : AutoSavePluginConfig("mcmotd") {
val fontName by value("Microsoft YaHei")
val showTrueAddress by value(false)
val showServerVersion by value(false)
val showPlayerList by value(true)
val dnsServerList by value(mutableListOf("223.5.5.5", "8.8.8.8"))
val recordOnlinePlayer by value(mutableListOf<String>())
val recordInterval by value(300)
Expand Down

0 comments on commit ffaa28f

Please sign in to comment.