feat: compatible brower behavior
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import i18n from '@ccms/i18n'
|
||||
import { injectable } from "@ccms/container";
|
||||
import { injectable } from "@ccms/container"
|
||||
import { plugin } from './interfaces'
|
||||
|
||||
export namespace command {
|
||||
@injectable()
|
||||
@ -10,16 +11,17 @@ export namespace command {
|
||||
* @param name 命令
|
||||
* @param exec 执行器
|
||||
*/
|
||||
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
|
||||
var cmd = this.create(plugin, name);
|
||||
on(plugin: plugin.Plugin, name: string, exec: { cmd: Function, tab?: Function }) {
|
||||
var cmd = this.create(plugin, name)
|
||||
if (!cmd) { throw Error("") }
|
||||
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
|
||||
if (exec.cmd && typeof exec.cmd === "function") {
|
||||
this.onCommand(plugin, cmd, exec.cmd);
|
||||
this.onCommand(plugin, cmd, exec.cmd)
|
||||
} else {
|
||||
throw Error(i18n.translate("ms.api.command.register.input.error", { exec: exec.cmd }))
|
||||
}
|
||||
if (exec.tab && typeof exec.tab === "function") {
|
||||
this.onTabComplete(plugin, cmd, exec.tab);
|
||||
this.onTabComplete(plugin, cmd, exec.tab)
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -27,40 +29,40 @@ export namespace command {
|
||||
* @param plugin 插件
|
||||
* @param name 命令
|
||||
*/
|
||||
off(plugin: any, name: string) {
|
||||
off(plugin: plugin.Plugin, name: string) {
|
||||
console.debug(i18n.translate("ms.api.command.unregister", { plugin: plugin.description.name, name }))
|
||||
this.remove(plugin, name);
|
||||
this.remove(plugin, name)
|
||||
}
|
||||
|
||||
protected abstract create(plugin: any, command: string);
|
||||
protected abstract remove(plugin: any, command: string);
|
||||
protected abstract onCommand(plugin: any, command: any, executor: Function);
|
||||
protected abstract onTabComplete(plugin: any, command: any, tabCompleter: Function);
|
||||
protected setExecutor(plugin: any, command: any, executor: Function) {
|
||||
protected abstract create(plugin: plugin.Plugin, command: string): any
|
||||
protected abstract remove(plugin: plugin.Plugin, command: string): void
|
||||
protected abstract onCommand(plugin: plugin.Plugin, command: any, executor: Function)
|
||||
protected abstract onTabComplete(plugin: plugin.Plugin, command: any, tabCompleter: Function)
|
||||
protected setExecutor(plugin: plugin.Plugin, command: any, executor: Function) {
|
||||
return (sender: any, _: any, command: string, args: string[]) => {
|
||||
try {
|
||||
return executor(sender, command, Java.from(args));
|
||||
return executor(sender, command, Java.from(args))
|
||||
} catch (ex) {
|
||||
console.i18n("ms.api.command.execute.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
|
||||
console.ex(ex);
|
||||
console.ex(ex)
|
||||
if (sender.name != 'CONSOLE') {
|
||||
console.sender(sender, [i18n.translate("ms.api.command.execute.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)])
|
||||
}
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
protected setTabCompleter(plugin: any, command: any, tabCompleter: Function) {
|
||||
protected setTabCompleter(plugin: plugin.Plugin, command: any, tabCompleter: Function) {
|
||||
return (sender: any, _: any, command: string, args: string[]) => {
|
||||
try {
|
||||
var token = args[args.length - 1];
|
||||
var complete = tabCompleter(sender, command, Java.from(args)) || [];
|
||||
return this.copyPartialMatches(complete, token);
|
||||
var token = args[args.length - 1]
|
||||
var complete = tabCompleter(sender, command, Java.from(args)) || []
|
||||
return this.copyPartialMatches(complete, token)
|
||||
} catch (ex) {
|
||||
console.i18n("ms.api.command.tab.completer.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
|
||||
console.ex(ex);
|
||||
console.sender(sender, [i18n.translate("ms.api.command.tab.completer.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)]);
|
||||
return [];
|
||||
console.ex(ex)
|
||||
console.sender(sender, [i18n.translate("ms.api.command.tab.completer.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)])
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,7 +72,7 @@ export namespace command {
|
||||
if (typeof e === "string" && e.toLowerCase().startsWith(token.toLowerCase())) {
|
||||
array.push(e)
|
||||
}
|
||||
});
|
||||
})
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
@ -58,9 +58,9 @@ export namespace task {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected run(): void {
|
||||
protected run(...args: any[]): void {
|
||||
try {
|
||||
this.func();
|
||||
this.func(...args);
|
||||
} catch (ex) {
|
||||
console.console('§4插件执行任务时发生错误', ex)
|
||||
console.ex(ex);
|
||||
@ -69,8 +69,9 @@ export namespace task {
|
||||
|
||||
/**
|
||||
* 提交任务
|
||||
* @param args 任务参数
|
||||
*/
|
||||
abstract submit(): Cancelable;
|
||||
abstract submit(...args: any[]): Cancelable;
|
||||
}
|
||||
/**
|
||||
* 返可取消的对象
|
||||
|
Reference in New Issue
Block a user