Fix default config issue (remove / prefix)

Fix public command not handling aliases
This commit is contained in:
2022-09-13 21:16:15 +08:00
parent 137bf7d4f5
commit 78a3c09b43
3 changed files with 31 additions and 33 deletions

View File

@ -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'
```
# 指令列表

View File

@ -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)

View File

@ -36,22 +36,22 @@ object PluginConfig : AutoSavePluginConfig("config") {
@ValueDescription("命令别名")
val commandAlias: MutableMap<String, String> 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<String> by value(mutableSetOf(
"/list", "/list uid"
"list", "list uid"
))
}