Skip to content

Commit

Permalink
fix: 修复服务器描述显示的颜色代码
Browse files Browse the repository at this point in the history
  • Loading branch information
limbang committed Feb 19, 2022
1 parent 07eec4d commit 5946d87
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ plugins {
}

group = "top.limbang"
version = "1.1.6"
version = "1.1.7"

repositories {
maven("https://maven.fanua.top:8015/repository/maven-public/")
mavenCentral()
}

dependencies {
implementation("top.fanua.doctor:doctor-client:1.3.5")
testImplementation("org.slf4j:slf4j-simple:1.7.32")
implementation("top.fanua.doctor:doctor-client:1.3.7")
implementation("top.fanua.doctor:doctor-plugin-forge-fix:1.3.7")
testImplementation("org.slf4j:slf4j-simple:1.7.36")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import top.limbang.mirai.minecraft.service.ServerService.pingServer
object MiraiConsoleMinecraftPlugin : KotlinPlugin(
JvmPluginDescription(
id = "top.limbang.mirai-console-minecraft-plugin",
version = "1.1.6",
version = "1.1.7",
) {
author("limbang")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import top.fanua.doctor.client.utils.ServerInfoUtils
import top.fanua.doctor.client.utils.substringBetween
import top.fanua.doctor.network.handler.onPacket
import top.fanua.doctor.network.handler.oncePacket
import top.fanua.doctor.plugin.fix.PluginFix
import top.fanua.doctor.protocol.definition.play.client.JoinGamePacket
import top.fanua.doctor.protocol.definition.play.client.PlayerPositionAndLookPacket
import top.limbang.mirai.minecraft.MinecraftPluginData
Expand Down Expand Up @@ -48,12 +49,12 @@ object ServerService {
fun pingServer(name: String): Any? {
if (name.isEmpty()) return Unit
val server = MinecraftPluginData.serverMap[name] ?: return Unit
return pingServer(server.address, server.port,name)
return pingServer(server.address, server.port, name)
}

fun pingServer(address:String,port:Int,name:String): Any? {
fun pingServer(address: String, port: Int, name: String): Any? {
val serverInfo = try {
val json = MinecraftClient.ping(address,port)
val json = MinecraftClient.ping(address, port)
.get(5000, TimeUnit.MILLISECONDS) ?: return null
ServerInfoUtils.getServiceInfo(json)
} catch (e: Exception) {
Expand All @@ -72,7 +73,7 @@ object ServerService {
return "服务器信息如下:\n" +
"名 称: $name\n" +
"版 本: ${serverInfo.versionName}\n" +
"描 述: ${serverInfo.description}\n" +
"描 述: ${descriptionColourHandle(serverInfo.description)}\n" +
"在线人数: ${serverInfo.playerOnline}/${serverInfo.playerMax}\n" +
"$sampleName\n" +
"mod个数: ${serverInfo.modNumber}\n" +
Expand All @@ -91,8 +92,9 @@ object ServerService {
.user(serverInfo.loginInfo.username, serverInfo.loginInfo.password)
.authServerUrl(serverInfo.loginInfo.authServerUrl)
.sessionServerUrl(serverInfo.loginInfo.sessionServerUrl)
.plugin(TpsPlugin())
.plugin(AutoVersionForgePlugin())
.plugin(TpsPlugin())
.plugin(PluginFix())
.build()

if (!client.start(serverInfo.address, serverInfo.port, 5000)) {
Expand Down Expand Up @@ -134,4 +136,11 @@ object ServerService {
}
return "服务器列表为:\n$names"
}

/**
* 服务器描述颜色处理
*/
private fun descriptionColourHandle(description: String): String {
return description.replace("§[0-9a-z]".toRegex(),"")
}
}

0 comments on commit 5946d87

Please sign in to comment.