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

Solved Send a message to a player when they join in the Main.php

Comments in 'Plugin Development' started by DerpyMan101, Jan 30, 2016.

  1. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    Hey I need help figuring out how you send messages to a player when they join.
  2. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    PHP:
    public function onJoin(PlayerJoinEvent $e){
     
    $p $e->getPlayer();
     
    $p->sendMessage("You joined the server!");
    }
  3. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    :)
  4. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    It doesn't work :/
  5. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Did you register events?
    KubixQ and AndrewBit like this.
  6. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    Nope *facepalm*
  7. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    It's still not working :/
  8. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    By not working, what do you mean? Crash? Recoverable error? Nothing?
  9. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    Nothing is happening
  10. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Can you show us the full code?
  11. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    Yeah here it is:

    <?php

    namespace Events;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\event\player\PlayerJoinEvent;
    use pocketmine\utils\TextFormat as Color;

    class Events extends PluginBase {

    public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function playerJoin(PlayerJoinEvent $PJE){
    $player = $PJE->getPlayer();
    if($player->hasPlayedBefore()) {
    $player->getInventory()->addItem(1);
    }
    }
  12. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    looka as if it needs one more closing bracket

    also, personally, i would stick to $e instead of $PJE (personal preference)
  13. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    Ok
  14. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    This is my code but it still doesn't do anything

    class Events extends PluginBase {

    public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onJoin(PlayerJoinEvent $e){
    $p = $e->getPlayer();
    $p->sendMessage("Yo are bossome!");
    }
    }
  15. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    PHP:
    <?php
    namespace Events;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\utils\TextFormat as Color;

    class 
    Events extends PluginBase{
       
       public function 
    onEnable()
       {
           
    $this->getServer()->getPluginManager()->registerEvents($this$this);
       }
       
       public function 
    onJoin(PlayerJoinEvent $e)
       {
           
    $p $e->getPlayer();
           
    $p->sendMessage("Yo are bossome!");
       }
    }
    try this.

    (also, on your namespace, make sure it states the folder path.
    e.g. TheDeibo\plugin

    and class is the file name where this php is stored)
    applqpak likes this.
  16. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    registerEvents must implement Listener ;)
    PHP:
    <?php
    namespace Events;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\utils\TextFormat as Color;

    class 
    Events extends PluginBase implements Listener{
     
       public function 
    onEnable()
       {
           
    $this->getServer()->getPluginManager()->registerEvents($this$this);
       }
     
       public function 
    onJoin(PlayerJoinEvent $e)
       {
           
    $p $e->getPlayer();
           
    $p->sendMessage("Yo are bossome!");
       }
    }
  17. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    exactly what i just said xD
    applqpak likes this.
  18. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
  19. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    Go back to sleep Deibo. your dreaming. xD
    Im sorry, you were right :p
  20. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    so namespace src\Events\Events.php?

Share This Page

Advertisement