PHP code example of nozell / commando

1. Go to this page and download the library: Download nozell/commando library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nozell / commando example snippets




use CortexPE\Commando\BaseCommand;
use pocketmine\command\CommandSender;

class MyCommand extends BaseCommand {
	protected function prepare(): void {
		// This is where we'll register our arguments and subcommands
	}
	
	public function onRun(CommandSender $sender, string $aliasUsed, array $args): void {
		// This is where the processing will occur if it's NOT handled by other subcommands
	}
}

use CortexPE\Commando\args\RawStringArgument;

	protected function prepare(): void {
		// $this->registerArgument(position, argument object (name, isOptional));
		$this->registerArgument(0, new RawStringArgument("name", true));
	}

	public function onRun(CommandSender $sender, string $aliasUsed, array $args): void {
		if(isset($args["name"])){
			$sender->sendMessage("Hello, " . $args["name"] . "!");
		} else {
			$this->sendUsage();
		}
	}

use CortexPE\Commando\PacketHooker;

// onEnable:
	if(!PacketHooker::isRegistered()) {
		PacketHooker::register($this);
	}

// onEnable:
$this->getServer()->getCommandMap()->register("myplugin", new MyCommand($this, "greet", "Make the server greet you!"));

$cmdCtx->setErrorFormat($errorCode, $format);
// Arrays can be passed on `BaseCommand->setErrorFormats()` to bulk-set other error messages