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

Why does this NOT work???

Comments in 'Plugin Development' started by Renzo, Jun 24, 2014.

  1. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    31
    Minecraft User:
    Minetox
    PHP:
    <?php
    /*
    __PocketMine Plugin__
    name=PlaceAndBreakNotify
    description=Sends a notify to the console if a player breaks/places a block.
    version=1.0
    author=Renzo
    class=PlaceAndBreakNotify
    apiversion=12
    */
    class PlaceAndBreakNotify implements Plugin{
    private 
    $api;

    private 
    $enabled true;

    public function 
    __construct(ServerAPI $api$server false){$this->api $api;}
    public function 
    init(){
    $this->api->addHandler('player.block.place', array($this"eventHandler"));
    $this->api->addHandler('player.block.break', array($this"eventHandler"));
    $this->api->console->register("pbn""Turns PlaceAndBreakNotify on!", array($this"commandHandler"));
    }
    public function 
    eventHandler($event$issuer){
    switch(
    $event){
    case 
    'player.block.break':
    if(
    $this->enabled == true){
    $name $issuer->getName();
    console($this->name "Has destroyed a block!");
    break;}
    case 
    'player.block.place':
    if(
    $this->enabled == true){
    $name $issuer->getName();
    console($this->name "Has placed a block!");
    break;}
    }
    }

    public function 
    commandHandler($cmd$params$issuer){
            switch(
    $params[0]){
             case 
    '':
                return 
    "Usage: /pbn <on/off>";
                            break;
                case 
    'on':
                    if(
    $this->enabled === true){
                             
    $issuer->sendChat("[PlaceAndBreakNotify] Playerbreak Notify is already on!");
                        } else{
                         
    console("[PlaceAndBreakNotify] Status: " FORMAT_GREEN "on");
                            
    $this->enabled true;
                  
                    }
                break;
                case 
    'off':
                    if(
    $this->enabled === true){
                        
    $this->enabled false;
                        
    console("[PlaceAndBreakNotify] Status: " FORMAT_RED "off");  
                    }else{
                       
    $issuer->sendChat("[PlaceAndBreakNotify] Playerbreak Notify is already off!");
                    }
                break; 
            }
        }
    public function 
    __destruct(){}
    }
    Sorry, I fix it
  2. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    Yeey i fixed the error by myself!
    PEMapModder likes this.
  3. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    :( i just fixed it
  4. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    31
    Minecraft User:
    Minetox
  5. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    Iam going to fix the crash when you use the command pbn off and on two times in a row
  6. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    31
    Minecraft User:
    Minetox
    Ok, sorry for that! Its not tested so i cant see any mistakes :p
  7. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    Ok
  8. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    31
    Minecraft User:
    Minetox
    So i saw your mistake! You forgot the "$data" by the eventHandler

    Here i have corrected your code

    PHP:
    <?php
    /*
    __PocketMine Plugin__
    name=PlaceAndBreakNotify
    description=Sends a notify to the console if a player breaks/places a block.
    version=1.0
    author=Renzo
    class=PlaceAndBreakNotify
    apiversion=12
    */
    class PlaceAndBreakNotify implements Plugin{
    private 
    $api;

    private 
    $enabled true;

    public function 
    __construct(ServerAPI $api$server false){$this->api $api;}
    public function 
    init(){
    $this->api->addHandler('player.block.place', array($this"eventHandler"));
    $this->api->addHandler('player.block.break', array($this"eventHandler"));
    $this->api->console->register("pbn""Turns PlaceAndBreakNotify on!", array($this"commandHandler"));
    }
    public function 
    eventHandler($event$data){ //here i replaced the $issuer with the $data
    switch($event){
    case 
    'player.block.break':
    if(
    $this->enabled == true){
    $name $data['player']->getName();
    console("$name Has destroyed a block!");
    break;}
    case 
    'player.block.place':
    if(
    $this->enabled == true){
    $name $data['player']->getName();
    console("$name Has placed a block!");
    break;}
    }
    }

    public function 
    commandHandler($cmd$params$issuer){
            switch(
    $params[0]){
             case 
    '':
                return 
    "Usage: /pbn <on/off>";
                            break;
                case 
    'on':
                    if(
    $this->enabled === true){
                             
    $issuer->sendChat("[PlaceAndBreakNotify] Playerbreak Notify is already on!");
                        } else{
                         
    console("[PlaceAndBreakNotify] Status: " FORMAT_GREEN "on");
                            
    $this->enabled true;
                  
                    }
                break;
                case 
    'off':
                    if(
    $this->enabled === true){
                        
    $this->enabled false;
                        
    console("[PlaceAndBreakNotify] Status: " FORMAT_RED "off");  
                    }else{
                       
    $issuer->sendChat("[PlaceAndBreakNotify] Playerbreak Notify is already off!");
                    }
                break; 
            }
        }
    public function 
    __destruct(){}
    }
    but i have also re written the code:

    PHP:
    <?php
    /*
    __PocketMine Plugin__
    name=PlaceAndBreakNotify
    description=Sends a notify to the console if a player breaks/places a block.
    version=1.0
    author=Renzo
    class=PlaceAndBreakNotify
    apiversion=12
    */
    class PlaceAndBreakNotify implements Plugin{
    private 
    $api;

    private 
    $enabled true;

    public function 
    __construct(ServerAPI $api$server false){$this->api $api;}
    public function 
    init(){
    $this->api->addHandler('player.block.place', array($this"eventHandler"));
    $this->api->addHandler('player.block.break', array($this"eventHandler"));
    $this->api->console->register("pbn""Turns PlaceAndBreakNotify on!", array($this"commandHandler"));
    }

    public function 
    eventHandler($data$event)
        {
            switch(
    $event)
                {   
                case 
    'player.block.break':
                    if(
    $this->enabled === true){
                    
    console("$name Has destroyed a block!");
                        return 
    false;
                    }
                break;
                case 
    'player.block.place':
                    if(
    $this->enabled === true){
                       
    $name $data["player"]->username();
                       
    console("$name Has placed a block!");
                    }
                break;
                }

        }    

    public function 
    commandHandler($cmd$params$issuer){
            switch(
    $params[0]){
             case 
    '':
                return 
    "Usage: /pbn <on/off>";
                            break;
                case 
    'on':
                    if(
    $this->enabled === true){
                             
    $issuer->sendChat("[PlaceAndBreakNotify] Playerbreak Notify is already on!");
                        } else{
                         
    console("[PlaceAndBreakNotify] Status: " FORMAT_GREEN "on");
                            
    $this->enabled true;
                  
                    }
                break;
                case 
    'off':
                    if(
    $this->enabled === true){
                        
    $this->enabled false;
                        
    console("[PlaceAndBreakNotify] Status: " FORMAT_RED "off");  
                    }else{
                       
    $issuer->sendChat("[PlaceAndBreakNotify] Playerbreak Notify is already off!");
                    }
                break; 
            }
        }
    public function 
    __destruct(){}
    }
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Tip by @wies. Let's see who he is going to blame on the next one :D
    swagboy47 likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is good of him to extract the most important line in the error dump enough ;) people sometimes don't even read error dumps.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder

Share This Page

Advertisement