2020-05-02 16:14:47 +00:00
|
|
|
import '@ccms/nashorn'
|
2020-02-23 20:01:39 +00:00
|
|
|
|
2020-05-02 16:14:47 +00:00
|
|
|
import { command, plugin } from '@ccms/api'
|
|
|
|
import { inject, provideSingleton, postConstruct } from '@ccms/container'
|
2020-02-23 20:01:39 +00:00
|
|
|
|
|
|
|
let PluginCommand = Java.type('cn.nukkit.command.PluginCommand');
|
|
|
|
let CommandExecutor = Java.type('cn.nukkit.command.CommandExecutor');
|
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(command.Command)
|
2020-02-23 20:01:39 +00:00
|
|
|
export class NukkitCommand extends command.Command {
|
|
|
|
@inject(plugin.PluginInstance)
|
|
|
|
private pluginInstance: any
|
|
|
|
private commandMap: any;
|
|
|
|
|
|
|
|
@postConstruct()
|
|
|
|
init() {
|
|
|
|
this.commandMap = base.getInstance().getServer().getCommandMap();
|
|
|
|
}
|
|
|
|
create(plugin: any, command: string) {
|
|
|
|
var cmd = this.commandMap.getCommand(command)
|
|
|
|
if (cmd && cmd instanceof PluginCommand) { return cmd };
|
|
|
|
cmd = new PluginCommand(command, this.pluginInstance)
|
|
|
|
this.commandMap.register(plugin.description.name, cmd);
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
remove(plugin: any, command: string) {
|
|
|
|
var cmd = this.commandMap.getCommand(command)
|
|
|
|
if (cmd && cmd instanceof PluginCommand) {
|
|
|
|
cmd.unregister(this.commandMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onCommand(plugin: any, command: any, executor: Function) {
|
|
|
|
command.setExecutor(new CommandExecutor({
|
|
|
|
onCommand: super.setExecutor(plugin, command, executor)
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
|
|
|
// Not Support
|
|
|
|
}
|
|
|
|
}
|