Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

CommandReceiver and language file

Recursive G edited this page Dec 2, 2016 · 8 revisions

The CommandReceiver provided an easy way to construct command handler.
Simply extends CommandReceiver<PluginMainClass> and done!

Register

You should and only should register your main command handler this way

commandHandler = new CommandHandler(this, i18n);
getCommand("nyaautils").setExecutor(commandHandler);

Command line arguments

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:

  • first
  • second
  • thir`d
  • fourt\h
  • an empty string

Subcommands

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.

Clone this wiki locally