-
Notifications
You must be signed in to change notification settings - Fork 8
Add a subcommand to a main command
In this tutorial, you will learn how to avoid extremely long command classes handling multiple subcommands and other nested commands and parameters by using Kelp-subcommands.
It is recommended to read the previous tutorial on how to create a basic command to have a better understanding of this tutorial.
For every subcommand, you have to create a new class with the idea to split your command into multiple classes in order to avoid cluttered classes. This new class also has to have an annotation:
@CreateSubCommand(name = "test1", executorType = ExecutorType.PLAYER_ONLY, parentCommand = YourCommandClass.class)
public class YourSubCommandClass {
}
The parameters name
and executorType
both act the same as in the normal command annotation, where name only is the name of the subcommand (in this case the entire command would be /testcommand test1
). The only difference is the parentCommand
parameter. As the name indicates, you have to pass the class of the parent command class here by typing the name of the class and adding .class at the end.
As in a normal command, your class has to inherit from KelpCommand
and include the correct onCommand
method. Your command class should now look like this:
@CreateSubCommand(name = "test1", executorType = ExecutorType.PLAYER_ONLY, parentCommand = YourCommandClass.class)
public class YourSubCommandClass extends KelpCommand {
@Override
public void onCommand(KelpPlayer player, String[] args) {
player.sendActionbar("You have executed the subcommand test1 of testcommand.");
}
}
For sub-commands KelpCommand
contains additional methods to allow/forbid custom parameters or administrate arguments. To learn more about these features look at the detailed documentation for the KelpCommand
class.
(c) 2019-2021 pxav.
Kelp is an open-source project maintained by multiple developers. If you have additions/questions/problems to report about the wiki, feel free to create an issue here on GitHub or join the Discord
- SQL Module coming soon
- Documentation in progress