Commands
To create a command you have to extend your VCommand class. This abstract class will allow you to manage your command very easily
The perform
function will execute the command, you must return the type of the command, this enumeration will determine if the command has been executed correctly or not.
So here you have a simple command that will send the message Hello world
to the user who will execute the command and which has the template.example permission. Permissions are managed with an enumeration.
You can add subcommands very easily with the addSubCommand
method.
Order the construtor of your command you must add this:
This gives us the command /example sub
.
Register
Now that you have created your order you need to register it. For this you have two different ways to do it. The classic way, where you need to register your order in the plugin.yml
. Or you can directly register your order from your plugin.
Register plugin.yml
So you have to add the command in the plugin.yml and then you have to call the method registerCommand(string, command)
of the class CommandManager
.
Register bukkit injection
The fastest way to add a command is to directly add your command with the injection in bukkit. For this you have the method registerCommand(string, command, aliases)
.
You can call this method from your main class, a function with the same arguments exists in the ZUtils class.
Constructor
In the builder you can put all the information of your command
Description
You can give a description to your command with the method setDescription
.
So you have a description directly in string and a description with the Message enumeration.
Permission
You can give a permission to your command with the method setPermission.
So you have a permission directly in string and a description with the Permission enumeration.
Console
You can disable access to the command for the console, by default the value is true.
Required arguments
You can tell your command that arguments are required for the execution of the command.
You have to give the name of the argument as a parameter, the name will be used for the generation of the command syntax.
Optional arguments
You can tell your command that arguments are optional for the execution of the command.
You have to give the name of the argument as a parameter, the name will be used for the generation of the command syntax.
Sub commands
The subCommand
method will add an alias to your current command and will also allow you to add a subcommand.
Syntax
By default, the syntax will be generated automatically, but you can give the syntax with the method setSyntax
.
Tab
You can also manage the tab completion. The plugin will automatically manage the tab completion with the sub commands. But for your arguments you have to manage it yourself.
Ignore args / parents
You can ignore the argument and parent limit, this allows you to put as many arguments as possible in your command. Perfect for a broadcast command for example.
Arguments
Maintenant que le constructeur de votre commande est terminé, vous devez gérer l'exécution de votre commande. Si votre commande contient des arguments obligatoires ou optionnels, vous pourrez les récupérer très facilement. Vous pouvez directement donner un type à vos arguments avec la classe Arguments.
For each type you can directly get a default value.
Be careful, the index always starts at 0 no matter where your command is. If you have the command /example test sub <need> [<optional>]
. The need
argument will be 0 and the optional
argument will be 1.
Tab
To enable tab completion you need to add setTabCompletor();
to the constructor of your command.
Then you have to override the toTab
function.
You have to check the content of the array and return a string list.
Last updated