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

How Do I Fix This?

Comments in 'Plugin Development' started by PluginMastered, Jun 25, 2014.

  1. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    Hi guys I made a plugin but my server wont output what I want I made a variable $username = $issuer-> username; and in the console it says undefined variable: issuer here is my plugin code

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=IDisconneted
    description=Plugin created with PMMPPG by SuperChipsLP
    version=1.0
    author=PluginMastered
    class=Disconnect
    apiversion=10
    */

        
    class Disconnect implements plugin{

        private 
    $api;

        public function 
    __construct(ServerAPI $api$server false){

            
    $this->api $api;

        }

        public function 
    init(){

        
    $this->api->addHandler("player.quit", array($this"eventHandler"), 100);

        
    $username $issuer-> username;

        }
       
        public function 
    eventHandler($data$event)
        {
        switch(
    $event)
        {
            case 
    'player.quit':

                
    $this->api->chat->broadcast("$username Has Left The Game");

            break;
        }

        }

        public function 
    __destruct(){

        }

    }
  2. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    The variable $username is out of scope...
    You need to declare it in the eventHandler function:

    Also you need to get the issuer like this:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=IDisconneted
    description=Plugin created with PMMPPG by SuperChipsLP
    version=1.0
    author=PluginMastered
    class=Disconnect
    apiversion=10
    */

        
    class Disconnect implements plugin{

        private 
    $api;

        public function 
    __construct(ServerAPI $api$server false){

            
    $this->api $api;

        }

        public function 
    init(){

        
    $this->api->addHandler("player.quit", array($this"eventHandler"), 100);

        }
      
        public function 
    eventHandler($data$event)
        {
        switch(
    $event)
        {
            case 
    'player.quit':
                
    $issuer $data['player'];
                
    $username $issuer-> username;
                
    $this->api->chat->broadcast("$username Has Left The Game");

            break;
        }

        }

        public function 
    __destruct(){

        }

    }
  3. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    thank you let me test it out !
  4. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    No problem!
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Lambo likes this.

Share This Page

Advertisement