feat: add sender check & add prun subcommand

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-09-24 18:36:53 +08:00
parent 8af69c98f3
commit 3c33ebf4e6
2 changed files with 24 additions and 4 deletions

View File

@ -289,6 +289,7 @@ export class MiaoReward extends interfaces.Plugin {
cmdbind(sender: org.bukkit.entity.Player, server: boolean) { cmdbind(sender: org.bukkit.entity.Player, server: boolean) {
if (this.bindCheck(sender, 60)) return if (this.bindCheck(sender, 60)) return
if (!sender.getItemInHand) { return this.logger.sender(sender, '§c手持物品检测异常 请检查是否在客户端执行命令!') }
if (sender.getItemInHand()?.getType() !== Material.AIR) { return this.logger.sender(sender, "§c请空手执行此命令!") } if (sender.getItemInHand()?.getType() !== Material.AIR) { return this.logger.sender(sender, "§c请空手执行此命令!") }
if (server) { if (server) {
if (!sender.isOp()) { return this.logger.sender(sender, '§4您没有配置服务器的权限!') } if (!sender.isOp()) { return this.logger.sender(sender, '§4您没有配置服务器的权限!') }
@ -300,6 +301,7 @@ export class MiaoReward extends interfaces.Plugin {
} }
cmddraw(sender: org.bukkit.entity.Player, amount: number) { cmddraw(sender: org.bukkit.entity.Player, amount: number) {
if (!sender.getItemInHand) { return this.logger.sender(sender, '§c手持物品检测异常 请检查是否在客户端执行命令!') }
amount = Number(amount) amount = Number(amount)
if (!Number.isInteger(amount)) { if (!Number.isInteger(amount)) {
return this.logger.sender(sender, '§4金额必须是数字!') return this.logger.sender(sender, '§4金额必须是数字!')
@ -405,6 +407,7 @@ export class MiaoReward extends interfaces.Plugin {
cmdratio(sender: any, ratioStr: string, confirm: string) { cmdratio(sender: any, ratioStr: string, confirm: string) {
if (!sender.isOp()) { return this.logger.sender(sender, '§4你没有此命令的权限!') } if (!sender.isOp()) { return this.logger.sender(sender, '§4你没有此命令的权限!') }
if (!sender.getItemInHand) { return this.logger.sender(sender, '§c手持物品检测异常 请检查是否在客户端执行命令!') }
let [ratio, mbr, msg] = this.ratio2string(ratioStr) let [ratio, mbr, msg] = this.ratio2string(ratioStr)
if (!confirm) { if (!confirm) {
return this.logger.sender(sender, [ return this.logger.sender(sender, [

View File

@ -54,6 +54,7 @@ let langMap = {
'deploy.token.not.exists': '§4请先配置发布Token!', 'deploy.token.not.exists': '§4请先配置发布Token!',
'deploy.success': '§6插件 §b{name} §6版本 §3{version} §a发布成功! §6服务器返回: §a{msg}', 'deploy.success': '§6插件 §b{name} §6版本 §3{version} §a发布成功! §6服务器返回: §a{msg}',
'deploy.fail': '§6插件 §b{name} §6版本 §3{version} §c发布失败! §6服务器返回: §c{msg}', 'deploy.fail': '§6插件 §b{name} §6版本 §3{version} §c发布失败! §6服务器返回: §c{msg}',
'prun.script': '§6指定插件:§b {name}',
'run.script': '§b运行脚本:§r {script}', 'run.script': '§b运行脚本:§r {script}',
'run.result': '§a返回结果:§r {result}', 'run.result': '§a返回结果:§r {result}',
'run.noresult': '§4没有返回结果!', 'run.noresult': '§4没有返回结果!',
@ -387,14 +388,27 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
try { try {
let script = args.join(' ') let script = args.join(' ')
this.i18n(sender, 'run.script', { script }) this.i18n(sender, 'run.script', { script })
let result = this.runCode(script, sender) let result = this.runCode(script, sender, this)
this.i18n(sender, 'run.result', { result: result == undefined ? this.translate.translate('run.noresult') : result + '' }) this.i18n(sender, 'run.result', { result: result == undefined ? this.translate.translate('run.noresult') : result + '' })
} catch (ex) { } catch (ex) {
this.logger.sender(sender, this.logger.stack(ex)) this.logger.sender(sender, this.logger.stack(ex))
} }
} }
private runCode(code: string, sender: any) { cmdprun(sender: any, name: string, ...args: any[]) {
try {
if (!this.pluginManager.getPlugins().has(name)) { return this.logger.sender(sender, `§4插件 §c${name} §4不存在!`) }
let script = args.join(' ')
this.i18n(sender, 'prun.script', { name })
this.i18n(sender, 'run.script', { script })
let result = this.runCode(script, sender, this.pluginManager.getPlugins().get(name))
this.i18n(sender, 'run.result', { result: result == undefined ? this.translate.translate('run.noresult') : result + '' })
} catch (ex) {
this.logger.sender(sender, this.logger.stack(ex))
}
}
private runCode(code: string, sender: any, _this: any) {
let paramNames = [ let paramNames = [
'sender', 'sender',
'reflect', 'reflect',
@ -416,7 +430,7 @@ if (this.serverType == "spring") {
var df = base.getInstance().getAutowireCapableBeanFactory() var df = base.getInstance().getAutowireCapableBeanFactory()
} }
return ''+ eval(${JSON.stringify(code)});`) return ''+ eval(${JSON.stringify(code)});`)
return tfunc.apply(this, params) + '' return tfunc.apply(_this, params) + ''
} }
cmddeploy(sender: any, name: any) { cmddeploy(sender: any, name: any) {
@ -446,7 +460,7 @@ return ''+ eval(${JSON.stringify(code)});`)
@Tab({ alias: ['gmspm', 'bungeemspm'] }) @Tab({ alias: ['gmspm', 'bungeemspm'] })
tabmspm(_sender: any, _command: any, args: string | any[]) { tabmspm(_sender: any, _command: any, args: string | any[]) {
if (args.length === 1) { return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help', 'create', 'deploy'] } if (args.length === 1) { return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'prun', 'help', 'create', 'deploy'] }
if (args.length > 1) { if (args.length > 1) {
switch (args[0]) { switch (args[0]) {
case "list": case "list":
@ -457,6 +471,9 @@ return ''+ eval(${JSON.stringify(code)});`)
if (args.length == 2) return ["system", ...this.pluginManager.getPlugins().keys()] if (args.length == 2) return ["system", ...this.pluginManager.getPlugins().keys()]
if (args.length == 3 && args[1] == "system") return ["confirm"] if (args.length == 3 && args[1] == "system") return ["confirm"]
return [] return []
case "prun":
if (args.length == 2) return [...this.pluginManager.getPlugins().keys()]
return []
case "update": case "update":
case "load": case "load":
case "unload": case "unload":