2
0
mirror of https://github.com/EngineHub/WorldEdit.git synced 2024-12-27 05:00:08 +08:00

Fix /worldedit:xyz commands on Bukkit. (execution and completions)

This commit is contained in:
wizjany 2019-11-09 10:22:54 -05:00
parent d81fd99340
commit dd5b8b1a37

View File

@ -337,7 +337,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + commandLabel;
split[0] = "/" + cmd.getName();
CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
getWorldEdit().getEventBus().post(event);
@ -351,7 +351,7 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String comm
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + commandLabel;
split[0] = "/" + cmd.getName();
String arguments = Joiner.on(" ").join(split);
CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), arguments);
@ -496,19 +496,24 @@ public void onAsyncTabComplete(com.destroystokyo.paper.event.server.AsyncTabComp
String buffer = event.getBuffer();
int firstSpace = buffer.indexOf(' ');
if (firstSpace < 0) return;
final String label = buffer.substring(0, firstSpace);
String label = buffer.substring(0, firstSpace);
Plugin owner = server.getDynamicCommands().getCommandOwner(label);
if (owner != WorldEditPlugin.this) {
return;
}
int plSep = label.indexOf(":");
if (plSep >= 0 && plSep < label.length() + 1) {
label = "/" + label.substring(plSep + 1);
buffer = "/" + buffer.substring(plSep + 1);
}
final Optional<org.enginehub.piston.Command> command
= WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label);
if (!command.isPresent()) return;
CommandSuggestionEvent suggestEvent = new CommandSuggestionEvent(wrapCommandSender(event.getSender()), event.getBuffer());
CommandSuggestionEvent suggestEvent = new CommandSuggestionEvent(wrapCommandSender(event.getSender()), buffer);
getWorldEdit().getEventBus().post(suggestEvent);
event.setCompletions(CommandUtil.fixSuggestions(event.getBuffer(), suggestEvent.getSuggestions()));
event.setCompletions(CommandUtil.fixSuggestions(buffer, suggestEvent.getSuggestions()));
event.setHandled(true);
}
}