Why when I do /tntrun on or /tntrun off it doesn't display anything at all in the console ? Thank you PHP: <?php/*__PocketMine Plugin__name=TNTRundescription=When a player steps on a tnt, it disappearversion=1.0author=Guillaume351class=tntrunapiversion=12*/class tntrun implements Plugin { private $api; public function __construct(ServerAPI $api, $server = false) { $this->api = $api; } public function init() { $this->config = new Config($this->api->plugin->configPath($this)."config.txt", CONFIG_YAML, array('TNTRun' =>true,)); $this->api->event("entity.move", array($this, "tntcheck")); $this->api->console->register("tntrun", "tntrun [ON/OFF]", array($this, "commandHandler")); } public function commandHandler($args,$issuer,$cmd){ $here = ($this->api->plugin->configPath($this). "config.txt"); $arguments = $args[0]; $subCmd = strtolower(array_shift($args));switch($subCmd){ case "on": console("on"); break; case "off": console("off"); break;} } public function tntcheck($data){ $check = $this->config->get('TNTRun'); $block = $data->level->getBlock(new Vector3($data->x, ($data->y -1), $data->z)); if ($check == true){ if($block->getID() == 46){ $data->level->setBlock(new Vector3($data->x, $data->y-1, $data->z,$data->level), new AirBlock()); }} else{} } public function __destruct(){ }}?>
PHP: public function commandHandler($args,$issuer,$cmd){$here = ($this->api->plugin->configPath($this). "config.txt");$arguments = $args[0];$subCmd = strtolower(array_shift($args));switch($subCmd){ case "on":console("on"); break; case "off":console("off"); break;}}
You also need to change it from "($args,$issuer,$cmd)" to "($cmd,$args,$issuer)". The order does matter.
So then this may work? Code: <?php /* __PocketMine Plugin__ name=Test description=Just an example version=1.0 author=iksaku class=test apiversion=12 */ class test implements Plugin { private $api; public function __construct(ServerAPI $api, $server = false) { $this->api = $api; } public function init() { $this->api->console->register("test", "[1/2]", array($this, "test")); } public function test($cmd,$args,$issuer){ $arguments = $args[0]; $subCmd = strtolower(array_shift($args)); switch($subCmd){ case "1": $this->api->chat->broadcast("Test message 1"); break; case "2": $this->api->chat->broadcast("Test message 2"); break; } public function __destruct(){ } }
You can make it easier. Just do a function like Code: public function commandHandler($cmd, $params, $issuer, $args){ switch($params[0]){ case "test": break; } }