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

Events

Comments in 'Plugin Development' started by minebuilder0110, Oct 2, 2015.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    PHP:
    <?php
    namespace _0110\CallFunction;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\Listener;

    class 
    CallFunction extends PluginBase implements Listener{
        public function 
    onEnable(){
        }
        public function 
    onPlayerJoin(PlayerJoinEvent $event){
            
    $event->getPlayer()->sendMessage("Hello");
        }
    }
    Ok, obviously, I wrote this just to test event stuff, but nothing really happens when I join. What have I forgot?
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You forgot to register the events. Add $this->getServer()->getPluginManager()->registerEvents($this, $this); into onEnable().
  3. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I already tried that, and Im getting crash for undefined method. What do I use for it?
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Code?
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Instead of telling us your errors, try posting your latest code.
  6. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Well that is all I have above :p I was trying to write a plugin, but the functions werent triggered, so I tried to write even simpler code but it didnt work. And that simpler code is that above.
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    What functions were you trying to use? + You need to register events.
    Show the errors you were getting.
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    PHP:
    <?php
    namespace _0110\CallFunction;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\Listener;

    class 
    CallFunction extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        public function 
    onPlayerJoin(PlayerJoinEvent $event){
            
    $event->getPlayer()->sendMessage("Hello");
        }
    }
    This will work.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Instead of saying "instead of", try saying " apart from". The error is important as well.

Share This Page

Advertisement