Skip to content

Developer Tab Complete Command

ludgart edited this page Nov 11, 2020 · 1 revision

Developer Tab Complete Command

For easy handling, you can add our tab complete technology
Go to your TestCommand file and in the bottom you will find a empty onTabComplete() Method.
Add following code:

@Override
public void onExecute(CommandSender sender, String[] args) {
  List<String> completions = new ArrayList<>();

  if (args.length == 0) {
    SUB_COMMANDS.forEach(subCommand -> completions.add(subCommand.getName()));
  } else if (args.length == 1) {
    SUB_COMMANDS.stream().filter(subCommand -> subCommand.getName().toLowerCase().startsWith(args[0].toLowerCase()))
      .forEach(subCommand -> completions.add(subCommand.getName()));
   } else {
     SubCommand command = findSubCommand(args[0]);

     if (command != null) {
       return command.getCompletions(user, args);
     }
  }
  return completions;
}

We also need an new function.

private SubCommand findSubCommand(String name) {
  return SUB_COMMANDS.stream().filter(subCommand -> subCommand.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}

Optional - SubCommand class

@Override
public List<String> onTabComplete(CommandSender commandSender, String[] strings) {
 return Arrays.asList("example", "example2", "example3");
}

Information

Server Owner

Developer

Clone this wiki locally