-
Notifications
You must be signed in to change notification settings - Fork 8
CommandReceiver and language file
The CommandReceiver provided an easy way to construct command handler.
Simply extends CommandReceiver<PluginMainClass> and done!
You should and only should register your main command handler this way
commandHandler = new CommandHandler(this, i18n);
getCommand("nyaautils").setExecutor(commandHandler);Command line is automatically parsed by CommandReceiver.Arguments class.
Arguments are separated by space, extra spaces are allowed.
Singe argument containing special characters should be embraced by `
Backslash \ is used as the escape character but it is only valid inside the backquote
For example
/examplecommand first `second` `thir\`d` `fourt\\h` ``
contains five arguments:
firstsecondthir`dfourt\h- an empty string
A subcommand handler is a field or a method inside a command handler class.
It should be annotated with @SubCommand annotation.
If it's a field, this field type should have a constructor in this form
public <init>(Object plugin, Internationalization i18n);If it's a method, it should be in this form
public void commandName(CommandSender sender, Arguments args);The abstract method getHelpPrefix is used to determine the correct command prefix of a subcommand.
A command handler annotated with @SubCommand(value="subcmd") should return subcmd as it's helpPrefix.
The main command handler should return an empty string.
Specially, the help subcommand is provided for every CommandReceiver since the method is defined in CommandReceiver it self.
Each subcommand is automatically related to a set of descriptions in the language file.
manual.<subCommand>.<subsubCommand>.descriptionmanual.<subCommand>.<subsubCommand>.usage
For real example, please refer to the language file
Remember to write document for the help subcommand.
By default, CommandReceiver picks the first argument and search for matching subcommand handler.
It will print the help message then return if no suitable handler is found.
If you want to customize this behavior, you can overwrite the acceptCommand method.
Example