feat: add bungee tab complate

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-09 22:07:00 +08:00
parent be114e6d1b
commit 6797761a2f

View File

@ -2,10 +2,14 @@ import { command, plugin } from "@ms/api";
import { inject, injectable } from "@ms/container"; import { inject, injectable } from "@ms/container";
import * as ref from '@ms/common/dist/reflect' import * as ref from '@ms/common/dist/reflect'
const Command = Java.type('net.md_5.bungee.api.plugin.Command'); const Arrays = Java.type('java.util.Arrays')
const Command = Java.extend(Java.type('net.md_5.bungee.api.plugin.Command'), Java.type('net.md_5.bungee.api.plugin.TabExecutor'));
const createCommand = eval(` const createCommand = eval(`
function(cls, name, exec){ function(cls, name, exec, tab){
return new cls(name) {execute:exec} return new cls(name) {
execute: exec,
onTabComplete: tab
}
} }
`) `)
@ -13,13 +17,18 @@ class SimpleCommand {
public callable: any; public callable: any;
private name: string; private name: string;
private executor: Function; private executor: Function;
private tabComplete: Function = () => [];
constructor(command: string) { constructor(command: string) {
this.name = command; this.name = command;
this.callable = createCommand(Command, command, (sender, args) => this.executor(sender, '', command, args)); this.callable = createCommand(Command, command,
(sender, args) => this.executor(sender, '', command, args),
(sender, args) => Arrays.asList(this.tabComplete(sender, '', command, args))
);
} }
setExecutor = (executor: Function) => this.executor = executor; setExecutor = (executor: Function) => this.executor = executor;
setTabComplete = (tabComplete: Function) => this.tabComplete = tabComplete;
toString = () => `Bungee SimpleCommand(${this.name})` toString = () => `Bungee SimpleCommand(${this.name})`
} }
@ -48,7 +57,7 @@ export class BungeeCommand extends command.Command {
command.setExecutor(super.setExecutor(plugin, command, executor)); command.setExecutor(super.setExecutor(plugin, command, executor));
} }
onTabComplete(plugin: any, command: any, tabCompleter: Function) { onTabComplete(plugin: any, command: any, tabCompleter: Function) {
console.warn(`[${plugin.description.name}] command ${command.name} register tab failed. BungeeCord not support !`) command.setTabComplete(super.setTabCompleter(plugin, command, tabCompleter))
} }
private getCommandKey(plugin: any, command: string) { private getCommandKey(plugin: any, command: string) {