hello guys today i was testing my server by making small plugin and put it in the plugin folder. here <?php /* __PocketMine Plugin__ name=test description=it worked version=0.0.1 author=hamachichi class=test apiversion=12,13 */ class test implements Plugin{ public function __construct(ServerAPI $api, $server=false){ } public function init(){ $this->api->console->register("test","the main command", array($this, "handlecommand")); } public function handlecommand($cmd,$args,$issuer) { $this->api->chat->broadcast("it worked!!"); } public function __destruct(){ } } and when i started the server it sowed me the following errors [ERROR] A E_NOTICE error happened: "Undefined property: kitcat::$api" in "C:\Users\Public\Videos\Sample Videos\PocketMine-MP\plugins\Kitcat.php" at line 15 03:04:05 [ERROR] A E_NOTICE error happened: "Trying to get property of non-object" in "C:\Users\Public\Videos\Sample Videos\PocketMine-MP\plugins\Kitcat.php" at line 15 Fatal error: Call to a member function register() on a non-object in C:\Users\Public\Videos\Sample Videos\PocketMine-MP\plugins\Kitcat.php on line 15 03:04:05 [SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump 03:04:05 [ERROR] A E_WARNING error happened: "Division by zero" in "C:\Users\Public\Videos\Sample Videos\PocketMine-MP\src\PocketMinecraftServer.php" at line 92 03:04:05 [SEVERE] Please submit the "Error_Dump_Fri_Jun_6-03.04.05-UTC_2014.log" file to the Bug Reporting page. Give as much info as you can. 03:04:05 [INFO] Stopping server... bin\php\php.exe: Segmentation fault what should i do ??
The command isnt actually in the funtion "commandhandle" you need to use a switch() and then use case "test": to make a command and then end it with break; Also theres a ton of plugin tutorials around here. Why not look into one
You could also use the plugin generator @SuperChipsLP made. (NOT for the whole plugin. Just to fingure things out)
What? No. The switch is only if you have multiple commands being sent to the same function. You need to insert the following line into the construct function: PHP: $this->api = $api;
... switch is optional and makes handling commands easier for some people. This: PHP: switch($cmd){ case "test": $issuer->sendChat("Hello world!"); case "sendme": $issuer->sendChat("You have called the sendme command!"); break;} is the same as PHP: if($cmd=="test"){ $issuer->sendChat("Hello world!");}elseif($cmd=="sendme"){ $issuer->sendChat("You have called the sendme command!");}/* or:if($cmd=="test") $issuer->sendChat("Hello world!");elseif($cmd=="sendme") $issuer->sendChat("You have called the sendme command!");*/
No. break after every case: PHP: switch($cmd){ case "test": $issuer->sendChat("Test!"); break; case "helloworld": $issuer->sendChat("Hello world!"); break;}//is equal tooif($cmd=="test"){ $issuer->sendChat("Test!");}if($cmd=="helloworld"){ $issuer->sendChat("Hello world!");} break only after last case: PHP: switch($cmd){ case "test": $issuer->sendChat("Test!"); case "helloworld": $issuer->sendChat("Hello world!"); break;}//is equal tooif($cmd=="test"){ $issuer->sendChat("Test!");}elseif($cmd=="helloworld"){ $issuer->sendChat("Hello world!");}
Yes, after each case you need a break. http://www.php.net/manual/en/control-structures.switch.php This is wrong, a break is needed after each case. Spoiler It is important to understand how the switch statement is executed in order to avoid mistakes. The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don't write a break statement at the end of a case's statement list, PHP will go on executing the statements of the following case Source: http://www.php.net/manual/en/control-structures.switch.php