Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

crashes!!

Comments in 'Plugin Development' started by hamachichi, Jun 6, 2014.

  1. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    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 ??
  2. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    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 ;)
    PEMapModder and hamachichi like this.
  3. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    i liked glitchmaster one but it has been removed and no offense i didnt like pemapmoder
    PEMapModder likes this.
  4. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    tutorial
  5. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    You could also use the plugin generator @SuperChipsLP made. (NOT for the whole plugin. Just to fingure things out)
    hamachichi likes this.
  6. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    i know everything but i cant put them togather
  7. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    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;
  8. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    guys i figured it out...... problem solved :)
  9. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    no falk switch is for multiple subcommands with different function take worldedit as an example
  10. codmadnesspro
    Offline

    codmadnesspro Notable Member Plugin Developer

    Joined:
    Sep 11, 2013
    Posts:
    551
    Plugins:
    1
    Minecraft User:
    Codmadnesspro
    It would be nice if it supported the new api.
    Comedyman937 likes this.
  11. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    ... 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!");
    }else
    if(
    $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!");
    */
    Comedyman937 likes this.
  12. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    hey hey stay on topic
  13. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    thanks lambo
  14. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    lambo do you have to put break; after each case ?
  15. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    No.
    break after every case:
    PHP:
    switch($cmd){
       case 
    "test":
       
    $issuer->sendChat("Test!");
       break;
       case 
    "helloworld":
       
    $issuer->sendChat("Hello world!");
       break;
    }
    //is equal too
    if($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 too
    if($cmd=="test"){
       
    $issuer->sendChat("Test!");
    }else
    if(
    $cmd=="helloworld"){
       
    $issuer->sendChat("Hello world!");
    }
    PEMapModder likes this.
  16. hamachichi
    Offline

    hamachichi Banned

    Joined:
    Jun 5, 2014
    Posts:
    43
    Minecraft User:
    hamachichi
    thanks
  17. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    I didnt see that that was missing :p

    I use switches for every plugin I make.... Its just easier for me :p
  18. Intyre
    Offline

    Intyre Staff Member PocketMine Team

    Joined:
    Aug 24, 2013
    Posts:
    118
    Minecraft User:
    Intyre
    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.
    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
    PEMapModder likes this.
  19. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Oh, oops :p
  20. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    754
    Plugins:
    2
    Minecraft User:
    Darunia18
    Moved to Plugin Development. Please use the correct sections, @hamachichi.

Share This Page

Advertisement