fix: 修复子命令权限处理异常

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2022-04-04 04:27:47 +08:00
parent 41e5754492
commit a1df719dc9

View File

@ -57,6 +57,7 @@ export class PluginCommandManager {
let subcommandexec = pluginInstance[cmdKey] let subcommandexec = pluginInstance[cmdKey]
if (!subcommandexec) { if (!subcommandexec) {
subcommandexec = pluginInstance['cmdmain'] subcommandexec = pluginInstance['cmdmain']
subcommand = 'main'
} else { } else {
args.shift() args.shift()
} }
@ -66,30 +67,37 @@ export class PluginCommandManager {
sender, sender,
pluginInstance['cmdhelp'] ? pluginInstance['cmdhelp'] ?
`§6请执行 §b/${command} §ahelp §6查看帮助!` : `§6请执行 §b/${command} §ahelp §6查看帮助!` :
`§b版本: §a ${pluginInstance.description.version}` [
`§6插件: §b${pluginInstance.description.name}`,
`§6版本: §a${pluginInstance.description.version}`
]
) )
return return
} }
let permission: string let permission: string
if (typeof cmd.permission == "string") { if (cmd.permission && sender.hasPermission) {
permission = cmd.permission as string if (typeof cmd.permission == "string") {
} else if (cmd.permission) { permission = cmd.permission as string
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}.${subcommand}` } else {
} permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}.${subcommand}`
if (sender.hasPermission && !sender.hasPermission(permission)) { }
return pluginInstance.logger.sender(sender, `§c你需要 ${permission} 权限 才可执行此命令.`) if (!sender.hasPermission(permission)) {
return pluginInstance.logger.sender(sender, `§c你需要 ${permission} 权限 才可执行此命令.`)
}
} }
return subcommandexec.apply(pluginInstance, [sender, ...args]) return subcommandexec.apply(pluginInstance, [sender, ...args])
} }
let originCompleter = cmdCompleter let originCompleter = cmdCompleter
cmdCompleter = (sender: any, command: string, args: string[]) => { cmdCompleter = (sender: any, command: string, args: string[]) => {
let permission: string let permission: string
if (typeof cmd.permission == "string") { if (cmd.permission && sender.hasPermission) {
permission = cmd.permission as string if (typeof cmd.permission == "string") {
} else if (cmd.permission) { permission = cmd.permission as string
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}` } else {
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}`
}
if (!sender.hasPermission(permission)) { return [] }
} }
if (sender.hasPermission && !sender.hasPermission(permission)) { return [] }
return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(pluginInstance, [sender, command, args]) || []) return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(pluginInstance, [sender, command, args]) || [])
} }
} }