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. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    Hello, i have made a plugin that notify's the console when a block is placed or breaked but it doesn' t work!
    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$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 on""Turns PlaceAndBreakNotify on!", array($this"commandHandler"));
    $this->api->console->register("pbn off""Turns PlaceAndBreakNotify off!", array($this"commandHandler"));
    $this->api->ban->cmdWhitelist("pbn on");
    $this->api->ban->cmdWhitelist("pbn off");
    }
    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){
    switch(
    $cmd){
    case 
    "pbn on":
    if(
    $issuer instanceof Player){
    $issuer->sendChat("You are NOT the console!");
    }else{
    $this->enabeled true;
    console("[PlaceAndBreakNotify] Status: " FORMAT_GREEN "OFF");
    }break;
    case 
    "pbn off":
    if(
    $issuer instanceof Player){$issuer->sendChat("You are NOT the console");}else{
    $this->enabled false;
    console("[PlaceAndBreakNotify] Status: " FORMAT_RED "OFF");
    break;}
    }
    }
    public function 
    __destruct(){}
    }
    The command pbn off and pbn on doesn' t work!
    Can someone help me?
  2. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    error?
  3. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    It gives no error it just does nothing!
  4. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    oh you should't put issuer . it should be $data at the public function and $name = $issuer->getname() should be name $name = $data["player"]->username
  5. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    and you don't need enable at the begging of the case
  6. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    and you didn't use params. it should be case "bala":
    if(params[0] = on) {
    bla bla
    }
  7. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    tip by @PEMapModder : learn PHP . he use to say it to me when i was like you but when i learned php . i can make plugins
    PEMapModder likes this.
  8. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    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;
                        }
                    }else{
                        return 
    "Error!";        
                    }
                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(){}
    }
    Here is the better coded version, if you need help, you can send me a Private Message! ;)
    Last edited: Jun 24, 2014
  9. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    hmmm . did it work ?
  10. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    Minecraft User:
    Minetox
    Yeah, i think so! Its not tested but i dont see any mistakes.
  11. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Use indention. It will make your code a lot cleaner and easier to read.
    Comedyman937 likes this.
  12. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    is $issuer is only for command issuer ( and sometimes, events) . right?
  13. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    Minecraft User:
    Minetox
  14. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    then why did you use $issuer in the code in both events
  15. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Replace $issuer with $data["player"] when working with events.
    LDX likes this.
  16. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    nope. its importent
  17. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    Minecraft User:
    Minetox
    $issuer was from Renzo, i only rewrite the "CommandHandler" :D
  18. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    Parse error: syntax error, unexpected 'else' (T_ELSE) in E:\TweedePocketMine-MP\plugins\PlaceAndBreakNotify.php on line 49
  19. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    That's an error I think you can fix for yourself.
    PEMapModder likes this.
  20. Renzo
    Offline

    Renzo Active Member

    Joined:
    Mar 12, 2014
    Posts:
    96
    Minecraft User:
    Renzo_4
    I'll try;)

Share This Page

Advertisement