A virion for PocketMine-MP developers aiming to assist registration of commands with added support for registering and executing SubCommands.
First of all you need to make a variable (save it somewhere since you might need it elsewhere).
$citation = new Citation(Plugin $plugin, ?string $prefix);
$plugin
is pretty self explanatory.$prefix
is the text (that if set) would appear before the messages sent to the command sender.
Citation provides a neat and easy to use API for developers for registering commands.
- Your command class must extend
JackMD\Citation\Command\BaseCommand
class in order for it to be registered. - Refer to the class for all the API methods it has.
- To register the command get handler from citation and register the command class.
$citation->getHandler()->registerCommand(BaseCommand $command): void;
-
$command
being the command class you want to register. -
For more API methods please refer to
JackMD\Citation\Handler
class.
Citation provides a neat and easy way for plugins to register sub commands in separate classes.
- Your SubCommand class must extend
JackMD\Citation\Command\SubCommand
class. - You may refer to the aforementioned class for all the API methods it hides.
- You need to register the SubCommand from the same command class that extends BaseCommand class like so.
$this->registerSubCommand(SubCommand $command): void;
- This will register the SubCommand for the command.
- For executing the sub commands in the
onCommand()
method of your BaseCommand add
$this->executeSubCommand(CommandSender $sender, array $args): void;
- This will check if the subcommand or its alias exist and execute it. If it doesn't then it will send the error to the command sender.
- It will also check if the sender has the permission to use the subcommand and notify if he doesn't.
Some default commands are provided within Citation for aiding the developer.
- A default help sub command is provided within Citation.
- Register the sub command to get a pre-set help command which automatically generates help pages for your commands.
$help = new JackMD\Citation\Command\Defaults\HelpSubCommand(BaseCommand $command, string $headerName, string $permission, string $usage, array $aliases = []);
$command
being the command whose sub command you want to add.$headerName
is the text that would appear on the top message of the help command when executed.$permission
,$usage
and$alias
are pretty self explanatory.
- Hopefully I mentioned every required detail.
- For any feature additions or bug reports to open an issue.
- PRs are always welcomed.