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

[NEW API] Events

Comments in 'Plugin Development' started by laccolite, Jun 12, 2014.

  1. laccolite
    Offline

    laccolite New Member

    Joined:
    Mar 1, 2014
    Posts:
    22
    How to make an event in a plugin and get it from another plugin.

    For examle, old api:

    PHP:
    //adding an event
    $this->api->addHandler('get.player.permission', array($this'returnPermission'), 1);

    public function 
    returnPermission($data)
        {
            return 
    $this->getUserPermission($data);
        }

    //Getting properties from other plugin
    $this->api->dhandle("get.player.permission"$username);
  2. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    For the New API version of a plugin you have to find the event (using http://docs.pocketmine.net) the "use" that file path at the beginning of the plugin and add it to its function.
    Example:
    Plugin Start (before class MainClass extends PluginBase{)
    PHP:
    use pocketmine\event\player\PlayerJoinEvent;
    Inside your onEnable function
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    Then the actual event function
    PHP:
    /**
      * @param PlayerJoinEvent $event
      *
      * @priority NORMAL
      * @ignoreCanceled false
      */
    public function onSpawn(PlayerJoinEvent $event){
    $player $event->getPlayer();
    $player->teleport($this->level->getSpawn());
    }
    NOTE: This is from one of MY plugins and CAN NOT be copied!
  3. laccolite
    Offline

    laccolite New Member

    Joined:
    Mar 1, 2014
    Posts:
    22
    And how to create your own event?
  4. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Not sure but I'm sure you could find out using the docs ;)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Example:
    PHP:
    # FILE AT Main.php
    <?php
    // blah blah blah
            
    $this->getServer()->getPluginManager()->callEvent(new PlayerAuthenticationEvent($player"IP authentication"));
    # EOF
    # FILE AT PlayerAuthenticationEvent.php
    <?php
    namespace your\name\space;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Cancellable;
    use 
    pocketmine\event\player\PlayerEvent;
    class 
    PlayerAuthenticationEvent extends PlayerEvent implements Cancellable{
        private 
    $authMethod;
        public function 
    __construct(Player $player$authMethod){
            
    $this->player $player;
            
    $this->authMethod $authMethod;
        }
        public function 
    getAuthMethod(){
            return 
    $this->authMethod;
        }
    }
    # EOF
    # FILE AT another plugin
        
    public function onAuth(PlayerAuthenticationEvent $event){
            
    $this->getLogger()->info($event->getPlayer()->getDisplayName() . " has logged in using " $event->getAuthMethod() . ".");
        }

Share This Page

Advertisement