2019-09-07 04:23:15 +00:00
|
|
|
import '@ms/nashorn'
|
|
|
|
|
2019-09-10 09:21:27 +00:00
|
|
|
import { command, plugin } from '@ms/api'
|
|
|
|
import * as reflect from '@ms/common/dist/reflect'
|
|
|
|
import { injectable, postConstruct, inject } from '@ms/container'
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2019-09-19 10:58:01 +00:00
|
|
|
let Bukkit = org.bukkit.Bukkit;
|
2019-09-10 09:21:27 +00:00
|
|
|
let TabCompleter = Java.type('org.bukkit.command.TabCompleter');
|
|
|
|
let PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
|
|
|
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor');
|
2019-09-07 04:23:15 +00:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class BukkitCommand extends command.Command {
|
2019-09-10 09:21:27 +00:00
|
|
|
@inject(plugin.PluginInstance)
|
|
|
|
private pluginInstance: any
|
|
|
|
private commandMap: any;
|
2019-09-07 04:23:15 +00:00
|
|
|
|
|
|
|
@postConstruct()
|
|
|
|
init() {
|
2019-09-19 10:58:01 +00:00
|
|
|
this.commandMap = reflect.on(Bukkit.getPluginManager()).get('commandMap').get();
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-21 07:04:25 +00:00
|
|
|
create(plugin: any, command: string) {
|
|
|
|
var cmd = this.commandMap.getCommand(command)
|
2019-09-07 04:23:15 +00:00
|
|
|
if (cmd && cmd instanceof PluginCommand) { return cmd };
|
2019-09-21 07:04:25 +00:00
|
|
|
cmd = reflect.on(PluginCommand).create(command, this.pluginInstance).get();
|
|
|
|
this.commandMap.register(plugin.description.name, cmd);
|
2019-09-07 04:23:15 +00:00
|
|
|
return cmd;
|
|
|
|
}
|
2019-09-21 07:04:25 +00:00
|
|
|
onCommand(plugin: any, command: any, executor: Function) {
|
2019-09-07 04:23:15 +00:00
|
|
|
// 必须指定需要实现的接口类型 否则MOD服会报错
|
2019-09-21 07:04:25 +00:00
|
|
|
command.setExecutor(new CommandExecutor({
|
|
|
|
onCommand: super.setExecutor(plugin, command, executor)
|
2019-09-07 04:23:15 +00:00
|
|
|
}));
|
|
|
|
}
|
2019-09-21 07:04:25 +00:00
|
|
|
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
2019-09-07 04:23:15 +00:00
|
|
|
// 必须指定需要实现的接口类型 否则MOD服会报错
|
2019-09-21 07:04:25 +00:00
|
|
|
command.setTabCompleter(new TabCompleter({
|
|
|
|
onTabComplete: super.setTabCompleter(plugin, command, tabCompleter)
|
2019-09-07 04:23:15 +00:00
|
|
|
}));
|
|
|
|
}
|
2019-09-21 07:04:25 +00:00
|
|
|
}
|