-
Notifications
You must be signed in to change notification settings - Fork 1
Developer Tab Complete Command
ludgart edited this page Nov 11, 2020
·
1 revision
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
- Basic
- Installation & Configuration
- Hello World
- Command
- Config
- Material
- Sound
- Particle
- Message
- Title
- ActionBar
- Advanced
- ItemBuilder
- Storage
- Inventory
- Static
- Updatable
- Anvil
- Player Data
- Get
- GetList
- Set
- HasValue
- IsValue
- Insert
- Delete
- OfflineZocker
- Item Serializer
- Custom Event
- Utilit
- Common Problems
- Frequently Asked Questions