-
Notifications
You must be signed in to change notification settings - Fork 0
2. Creating Command
Simple way to create a command using SimpleCommand
The SimpleCommand Can handle multiple commands in one class. So you can add multiple commands in one class!
public class SomeCommand extends SimpleCommand {
public SomeCommand() {
this.addCommand(new SimpleCommandManager("a") {
@Nullable
@Override
public Map<Integer, List<String>> args() {
return Map.of(0, List.of("args1", "args2", "args3"));
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
sender.sendMessage("Hello World!");
}
}, CommandSenderType.BOTH);
}
}
This method is used to provide a list of strings that can be used as arguments in the command.
You can edit the way it works by overriding the tabComplete
method.
This method is working the same as the onTabComplete
method in the TabCompleter
interface.
public SomeCommand() {
this.addCommand(new SimpleCommandManager("a") {
// rest of the code ...
@Override
public List<String> tabComplete(CommandSender sender, Command command, String[] args) {
// Provide a list of strings that can be used as arguments in the command
}
}, CommandSenderType.BOTH);
}
This is a simple way to add arguments to the command, so you don't have to wasting time by checking strings length for providing an argument.
This method works the same as the onCommand
method in the CommandExecutor
interface.
I saw that when ever I create a command, I always need to check if the command can be executed by console or player. So I created a CommandSenderType
to make it easier to check if the command can be executed by console or player.
-
CommandSenderType.BOTH
- Command can be executed by both console and player -
CommandSenderType.CONSOLE
- Command can only be executed by console -
CommandSenderType.PLAYER
- Command can only be executed by player
Coming soon full version on 2025!
Coming soon full version on 2025!