Skip to main content
Version: PM4

Commands


Using commands in a plugin enchants your Plugin! Commands can automatically and easily do things for you!

Ok lets start by adding the "use" statements for you can use commands.

// The Command
use pocketmine\command\Command;

// Person who does command
use pocketmine\command\CommandSender;

To set up the command we're going to use a public function and inside the function we will add the command, like this:

public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
switch($command->getName()){
case "example":
$sender->sendMessage("Hello " . $sender->getName() . "!");

return true;
default:
throw new \AssertionError("This line will never be executed");
}
}