From 65446674f6a32bd1bd6fe3d17b30e23b378c7063 Mon Sep 17 00:00:00 2001 From: coding Date: Tue, 17 Oct 2017 06:47:23 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA=E6=9C=AA=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/modules/command.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/resources/modules/command.js b/src/main/resources/modules/command.js index 21f9391..71d34d1 100644 --- a/src/main/resources/modules/command.js +++ b/src/main/resources/modules/command.js @@ -10,6 +10,9 @@ var bukkit = require('./bukkit'); var commandMap = ref.on(bukkit.plugin.manager).get('commandMap').get(); var PluginCommand = Java.type('org.bukkit.command.PluginCommand'); +var StringUtil = Java.type('org.bukkit.util.StringUtil'); + +var ArrayList = Java.type('java.util.ArrayList'); var Arrays = Java.type('java.util.Arrays') function enable(jsp){ @@ -37,11 +40,12 @@ function get(name) { } function create(jsp, name) { - return ref.on(PluginCommand).create(name, plugin).get(); + return register(jsp, ref.on(PluginCommand).create(name, plugin).get()); } function register(jsp, cmd){ commandMap.register(jsp.description.name, cmd); + return cmd; } // var exec = { @@ -52,8 +56,10 @@ function register(jsp, cmd){ // // } // }; + function on(jsp, name, exec) { var c = get(name) || create(jsp, name); + log.d('插件 %s 设置命令 %s(%s) 执行器 ...', jsp.description.name, name, c); if (exec.cmd) { c.setExecutor(function (sender, cmd, command, args) { return exec.cmd(sender, command, args); @@ -61,7 +67,10 @@ function on(jsp, name, exec) { } if (exec.tab) { c.setTabCompleter(function (sender, cmd, command, args) { - return Arrays.asList(exec.tab(sender, command, args)); + var completions = new ArrayList(); + var token = args[args.length - 1]; + StringUtil.copyPartialMatches(token, Arrays.asList(exec.tab(sender, command, args)), completions); + return completions; }); } }