Permalink
Browse files

Fix Forwarded Commands completion and misc improvements

  • Loading branch information...
aikar committed Feb 4, 2019
1 parent adf5de4 commit 375648e50b5bd3e2aaed66d413c86d6c887b180f
@@ -233,6 +233,8 @@ CommandCompletionHandler setDefaultCompletion(String id, Class... classes) {
Collection<String> getCompletions(C context) throws InvalidCommandArgument;
}
public interface AsyncCommandCompletionHandler <C extends CommandCompletionContext> extends CommandCompletionHandler <C> {}
public static class SyncCompletionRequired extends Exception {}

public static class SyncCompletionRequired extends RuntimeException {
}

}
@@ -44,7 +44,7 @@ public boolean hasPermission(CommandIssuer sender) {
}

@Override
public List<String> tabComplete(CommandIssuer issuer, String alias, String[] args) throws IllegalArgumentException {
public List<String> tabComplete(CommandIssuer issuer, String alias, String[] args, boolean isAsync) throws IllegalArgumentException {
return command.tabComplete(issuer, alias, ApacheCommonsLangUtil.addAll(baseArgs, args));
}

@@ -40,9 +40,6 @@

String getCommandName();
default void addChildShared(List<BaseCommand> children, SetMultimap<String, RegisteredCommand> subCommands, BaseCommand command) {
if (command.manager == null) {
command.manager = getManager();
}
command.subCommands.entries().forEach(e -> {
String key = e.getKey();
RegisteredCommand registeredCommand = e.getValue();
@@ -54,10 +54,14 @@ public void onAsyncTabComplete(AsyncTabCompleteEvent event) {
event.setCompletions(completions);
event.setHandled(true);
}
} catch (Exception ignored) {}
} catch (Exception e) {
if (!(e instanceof CommandCompletions.SyncCompletionRequired)) {
throw e;
}
}
}

public List<String> getCompletions(String buffer, List<String> existingCompletions, CommandSender sender, boolean async) {
private List<String> getCompletions(String buffer, List<String> existingCompletions, CommandSender sender, boolean async) {
String[] args = ACFPatterns.SPACE.split(buffer, -1);

String commandLabel = stripLeadingSlash(args[0]);
@@ -74,24 +78,7 @@ public void onAsyncTabComplete(AsyncTabCompleteEvent event) {
return ACFUtil.preformOnImmutable(existingCompletions, (list) -> list.addAll(completions));
}

private String stripLeadingSlash(String arg) {
String commandLabel = arg;
if (commandLabel.startsWith("/")) {
commandLabel = commandLabel.substring(1);
}
return commandLabel;
}

@EventHandler(ignoreCancelled = true)
public void onTabComplete(TabCompleteEvent event) {
String buffer = event.getBuffer();
if (!event.isCommand() && !buffer.startsWith("/")) {
return;
}

List<String> completions = getCompletions(buffer, event.getCompletions(), event.getSender(), false);
if (completions != null) {
event.setCompletions(completions);
}
private static String stripLeadingSlash(String arg) {
return arg.startsWith("/") ? arg.substring(1) : arg;
}
}

0 comments on commit 375648e

Please sign in to comment.