From 5946d87005a8e95683557d97a9a59c5c6095135c Mon Sep 17 00:00:00 2001 From: limbang <495071565@qq.com> Date: Sat, 19 Feb 2022 16:49:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E6=8F=8F=E8=BF=B0=E6=98=BE=E7=A4=BA=E7=9A=84=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 7 ++++--- .../minecraft/MiraiConsoleMinecraftPlugin.kt | 2 +- .../mirai/minecraft/service/ServerService.kt | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 685a0ff..3905f19 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "top.limbang" -version = "1.1.6" +version = "1.1.7" repositories { maven("https://maven.fanua.top:8015/repository/maven-public/") @@ -15,6 +15,7 @@ repositories { } 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") } diff --git a/src/main/kotlin/top/limbang/mirai/minecraft/MiraiConsoleMinecraftPlugin.kt b/src/main/kotlin/top/limbang/mirai/minecraft/MiraiConsoleMinecraftPlugin.kt index 596fd07..bf22487 100644 --- a/src/main/kotlin/top/limbang/mirai/minecraft/MiraiConsoleMinecraftPlugin.kt +++ b/src/main/kotlin/top/limbang/mirai/minecraft/MiraiConsoleMinecraftPlugin.kt @@ -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") } diff --git a/src/main/kotlin/top/limbang/mirai/minecraft/service/ServerService.kt b/src/main/kotlin/top/limbang/mirai/minecraft/service/ServerService.kt index 0c62924..f2ba2c7 100644 --- a/src/main/kotlin/top/limbang/mirai/minecraft/service/ServerService.kt +++ b/src/main/kotlin/top/limbang/mirai/minecraft/service/ServerService.kt @@ -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 @@ -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) { @@ -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" + @@ -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)) { @@ -134,4 +136,11 @@ object ServerService { } return "服务器列表为:\n$names" } + + /** + * 服务器描述颜色处理 + */ + private fun descriptionColourHandle(description: String): String { + return description.replace("§[0-9a-z]".toRegex(),"") + } } \ No newline at end of file