From 78a3c09b43940266dc24e728b7b003fcbdd2da1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= Date: Tue, 13 Sep 2022 21:16:15 +0800 Subject: [PATCH] Fix default config issue (remove `/` prefix) Fix public command not handling aliases --- README.md | 25 +++++++++++++------------ src/main/kotlin/JGrasscutterCommand.kt | 17 +++++++---------- src/main/kotlin/PluginConfig.kt | 22 +++++++++++----------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 73997dd..855833f 100644 --- a/README.md +++ b/README.md @@ -113,19 +113,20 @@ bindCommand: 绑定 commandPrefix: ! # 命令别名 commandAlias: - 无敌: '/prop god on' - 关闭无敌: '/prop god off' - 无限体力: '/prop ns on' - 关闭无限体力: '/prop ns off' - 无限能量: '/prop ue on' - 关闭无限能量: '/prop ue off' - 点亮地图: '/prop unlockmap 1' - 解锁地图: '/prop unlockmap 1' - 位置: '/pos' - 坐标: '/pos' + 无敌: 'prop god on' + 关闭无敌: 'prop god off' + 无限体力: 'prop ns on' + 关闭无限体力: 'prop ns off' + 无限能量: 'prop ue on' + 关闭无限能量: 'prop ue off' + 点亮地图: 'prop unlockmap 1' + 解锁地图: 'prop unlockmap 1' + 位置: 'pos' + 坐标: 'pos' +# 公开命令,无需绑定账号也可以执行(可用别名)(必须绑定了控制台令牌才可使用) publicCommands: - - '/list' - - '/list uid' + - 'list' + - 'list uid' ``` # 指令列表 diff --git a/src/main/kotlin/JGrasscutterCommand.kt b/src/main/kotlin/JGrasscutterCommand.kt index a80c845..69d19a2 100644 --- a/src/main/kotlin/JGrasscutterCommand.kt +++ b/src/main/kotlin/JGrasscutterCommand.kt @@ -105,18 +105,9 @@ object JGrasscutterCommand : KotlinPlugin( // 处理执行游戏命令 else if (message.startsWith(PluginConfig.commandPrefix)) { var command = message.removePrefix(PluginConfig.commandPrefix).trim() - if (command.isEmpty()) { + if (command.isEmpty() || (command[0] == '/' && command.length == 1)) { return@subscribeAlways } - // 检查是否使用别名 - val t = PluginConfig.commandAlias[command] - if (!t.isNullOrEmpty()) command = t - // 如果是斜杠开头,则移除斜杠,在控制台执行不需要斜杠 - if (command[0] == '/') { - command = command.substring(1) - if (command.isEmpty()) - return@subscribeAlways - } // 执行的用户 var user: User? = null @@ -142,6 +133,12 @@ object JGrasscutterCommand : KotlinPlugin( user.token } } + // 检查是否使用别名 + val t = PluginConfig.commandAlias[command] + if (!t.isNullOrEmpty()) command = t + // 如果是斜杠开头,则移除斜杠,在控制台执行不需要斜杠 + if (command[0] == '/') command = command.substring(1) + try { // 调用接口执行命令 val response = OpenCommandApi.runCommand(server.address, token, command) diff --git a/src/main/kotlin/PluginConfig.kt b/src/main/kotlin/PluginConfig.kt index c7b2ed6..0d62255 100644 --- a/src/main/kotlin/PluginConfig.kt +++ b/src/main/kotlin/PluginConfig.kt @@ -36,22 +36,22 @@ object PluginConfig : AutoSavePluginConfig("config") { @ValueDescription("命令别名") val commandAlias: MutableMap by value(mutableMapOf( - "无敌" to "/prop god on", - "关闭无敌" to "/prop god off", - "无限体力" to "/prop ns on", - "关闭无限体力" to "/prop ns off", - "无限能量" to "/prop ue on", - "关闭无限能量" to "/prop ue off", - "点亮地图" to "/prop unlockmap 1", - "解锁地图" to "/prop unlockmap 1", - "位置" to "/pos", - "坐标" to "/pos", + "无敌" to "prop god on", + "关闭无敌" to "prop god off", + "无限体力" to "prop ns on", + "关闭无限体力" to "prop ns off", + "无限能量" to "prop ue on", + "关闭无限能量" to "prop ue off", + "点亮地图" to "prop unlockmap 1", + "解锁地图" to "prop unlockmap 1", + "位置" to "pos", + "坐标" to "pos", // TODO ... )) @ValueDescription("公开命令,无需绑定账号也可以执行(可用别名)(必须绑定了控制台令牌才可使用)") val publicCommands: MutableSet by value(mutableSetOf( - "/list", "/list uid" + "list", "list uid" )) } \ No newline at end of file