/** * Gets tab completed data from the given command from the user. * * @param issuer * The user who executed the tabcomplete. * @param commandLabel * The label which is being used by the user. * @param args * The arguments the user has typed so far. * * @return All possibilities in the tab complete. */ public List<String> tabComplete(CommandIssuer issuer, String commandLabel, String[] args) { return tabComplete(issuer, commandLabel, args, false); }
@Override public List<String> tabComplete(CommandIssuer issuer, String alias, String[] args) throws IllegalArgumentException { return command.tabComplete(issuer, alias, ApacheCommonsLangUtil.addAll(baseArgs, args)); }
default List<String> getTabCompletions(CommandIssuer sender, String alias, String[] args, boolean commandsOnly) { Set<String> completions = new HashSet<>(); getChildren().forEach(child -> { if (!commandsOnly) { completions.addAll(child.tabComplete(sender, alias, args)); } completions.addAll(child.getCommandsForCompletion(sender, args)); }); return new ArrayList<>(completions); }
@EventHandler(ignoreCancelled = true) public void onAsyncTabComplete(AsyncTabCompleteEvent event) { String buffer = event.getBuffer(); if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1) { return; } try { //noinspection ConstantConditions,ConstantIfStatement if (false) throw new CommandCompletions.SyncCompletionRequired(); // fake compiler due to SneakyThrows String[] args = ACFPatterns.SPACE.split(buffer, -1); String commandLabel = args[0]; if (commandLabel.startsWith("/")) { commandLabel = commandLabel.substring(1); } args = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[]{""}; BaseCommand cmd = this.manager.getBaseCommand(commandLabel, args); if (cmd == null) { return; } BukkitCommandIssuer issuer = this.manager.getCommandIssuer(event.getSender()); List<String> results = cmd.tabComplete(issuer, commandLabel, args, true); event.setCompletions(ACFUtil.preformOnImmutable( event.getCompletions(), (list) -> list.addAll(results))); event.setHandled(true); } catch (Exception ignored) {} }