tab-completion: filter commands with startswith before checking permissions
@@ -343,7 +343,7 @@ public CommandResult process(CommandSource source, String commandLine) throws Co
final String[] argSplit = arguments.split(" ", 2);
Optional<CommandMapping> cmdOptional = get(argSplit[0], src);
if (argSplit.length == 1) {
- return filterCommands(src).stream().filter(new StartsWithPredicate(argSplit[0])).collect(ImmutableList.toImmutableList());
+ return filterCommands(src, argSplit[0]).stream().collect(ImmutableList.toImmutableList());
} else if (!cmdOptional.isPresent()) {
return ImmutableList.of();
}
@@ -394,6 +394,12 @@ public boolean testPermission(CommandSource source) {
return Multimaps.filterValues(this.commands, input -> input.getCallable().testPermission(src)).keys().elementSet();
}
+ // Filter out commands by String first
+ private Set<String> filterCommands(final CommandSource src, String start) {
+ ListMultimap<String, CommandMapping> map = Multimaps.filterKeys(this.commands, input -> input != null && input.toLowerCase().startsWith(start.toLowerCase()));
+ return Multimaps.filterValues(map, input -> input.getCallable().testPermission(src)).keys().elementSet();
+ }
+
/**
* Gets the number of registered aliases.
*
