feat: 优化命令注册
This commit is contained in:
parent
b189732b80
commit
2fcb7f1a1d
@ -31,11 +31,11 @@ var SimpleCommandCallable = function (name) {
|
|||||||
this.callable = new CommandCallable({
|
this.callable = new CommandCallable({
|
||||||
//CommandResult process(CommandSource source, String arguments) throws CommandException;
|
//CommandResult process(CommandSource source, String arguments) throws CommandException;
|
||||||
process: function (src, args) {
|
process: function (src, args) {
|
||||||
return that.cmd(src, null, name, args.split(" ")) ? CommandResult.success() : CommandResult.empty();
|
return that.cmd(src, name, args.split(" ")) ? CommandResult.success() : CommandResult.empty();
|
||||||
},
|
},
|
||||||
//List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException;
|
//List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException;
|
||||||
getSuggestions: function (src, args, target) {
|
getSuggestions: function (src, args, target) {
|
||||||
return that.tab(src, null, name, args.split(" "));
|
return that.tab(src, name, args.split(" "));
|
||||||
},
|
},
|
||||||
//boolean testPermission(CommandSource source);
|
//boolean testPermission(CommandSource source);
|
||||||
testPermission: function () {
|
testPermission: function () {
|
||||||
@ -93,7 +93,7 @@ function on(jsp, name, exec) {
|
|||||||
var c = create(jsp, name);
|
var c = create(jsp, name);
|
||||||
console.debug('插件 %s 设置命令 %s 执行器 ...'.format(jsp.description.name, name));
|
console.debug('插件 %s 设置命令 %s 执行器 ...'.format(jsp.description.name, name));
|
||||||
if (exec.cmd) {
|
if (exec.cmd) {
|
||||||
c.setExecutor(function (sender, cmd, command, args) {
|
c.setExecutor(function (sender, command, args) {
|
||||||
try {
|
try {
|
||||||
return exec.cmd(sender, command, args);
|
return exec.cmd(sender, command, args);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -104,12 +104,10 @@ function on(jsp, name, exec) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (exec.tab) {
|
if (exec.tab) {
|
||||||
c.setTabCompleter(function (sender, cmd, command, args) {
|
c.setTabCompleter(function (sender, command, args) {
|
||||||
try {
|
try {
|
||||||
var completions = new ArrayList();
|
|
||||||
var token = args[args.length - 1];
|
var token = args[args.length - 1];
|
||||||
StringUtil.copyPartialMatches(token, Arrays.asList(exec.tab(sender, command, args)), completions);
|
return Arrays.asList(exec.tab(sender, command, args));
|
||||||
return completions;
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常 §4%s'.format(sender.name, jsp.description.name, command, args, ex));
|
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常 §4%s'.format(sender.name, jsp.description.name, command, args, ex));
|
||||||
console.ex(ex);
|
console.ex(ex);
|
||||||
|
Loading…
Reference in New Issue
Block a user