1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

PlayerJoinEvent not working

Discussion in 'Plugin Help' started by timistwild, Feb 19, 2021.

  1. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Hi! My first project(Im very new to this) is to change the JoinMessage of the server.
    Of course its not working for me xD The plugin is starting great with loading enabling usw but it doesnt change the join message. Anyone can help me? Thank you :)
    https://pastebin.com/p9YRQjHf
     
    Last edited: Feb 19, 2021
  2. GeistFan

    GeistFan Slime

    Messages:
    86
    GitHub:
    GeistFan
    Your Plugin info is in German.
    Can you say me when your speak German
    German:(Also ich habe ein ähnliches Plugin gecodet und habe hier einen Code der Eigentlich funktioniert ich hoffe es hilft dir...)
    English:(So I coded a similar plugin and here I have a code that actually works i hope it helps you ...)
    public function onJoin(PlayerJoinEvent $event)
    {
    $player = $event->getPlayer();
    $event->setJoinMessage(TextFormat : : DARK_RED . "§name ist beigetreten");
    }
     
    Last edited: Feb 21, 2021
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    public function onJoin(PlayerJoinEvent $event)
    {
          
    $player $event->getPlayer();
          
    $name $player->getName();
          
    $event->setJoinMessage(TextFormat : : DARK_RED $name " ist beigetreten");
    }
    This is the correct code.

    Don't reply without fixing errors in your code.
     
  4. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Logging the message onLoad, onEnable, and onDisable isn't necessary, and it isn't recommended by PMMP as well, which is the reason why plugins with it gets rejected when submitted.

    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    Tim\Test1;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;


    class 
    Main extends PluginBase implements Listener
    {
        public function 
    onEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    onJoin(PlayerJoinEvent $event)
        {
            
    $player $event->getPlayer();
            
    $name $player->getName();
            
    $event->setJoinMessage(TextFormat : : DARK_RED $name " ist beigetreten");
        }
    }
    Here's your final Main.php.
     
  5. GeistFan

    GeistFan Slime

    Messages:
    86
    GitHub:
    GeistFan
    This was an code that haven't errors
    Here is my plugin there i have the code
    https://github.com/GeistFan/JoinLeave
     
  6. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    It clearly does, which questions me if you even know php.

    Variable $name isn’t defined, which will print an error.
     
    Primus likes this.
  7. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Oh i didnt know this. Thank you for the help! :)
     
  8. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    No problem!

    However, if this plugin is for private use, you can still have those messages. It doesn't really matter.
     
    Primus likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.