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

Pop Up with Playerjoinevent?

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

  1. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Hi! So i want to have a little Welcome Popup when a player joins. My first thought was the following code but i think its more complicated right?

    https://pastebin.com/CGXGVAnJ
     
  2. iDarkQ

    iDarkQ Spider

    Messages:
    12
    GitHub:
    idarkq
    This should work, did you get any error when entering the server? If you do not get any error try to check if you have registered event listener class
     
  3. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Oh nevermind, i thought this is the text in the middle. Do you know if there is a function for this?
     
  4. iDarkQ

    iDarkQ Spider

    Messages:
    12
    GitHub:
    idarkq
    can you send your full code?
     
  5. timistwild

    timistwild Spider Jockey

    Messages:
    33
  6. iDarkQ

    iDarkQ Spider

    Messages:
    12
    GitHub:
    idarkq
    And you still don't get any errors and nothing happen?
     
  7. timistwild

    timistwild Spider Jockey

    Messages:
    33
  8. iDarkQ

    iDarkQ Spider

    Messages:
    12
    GitHub:
    idarkq
    Aaaaa if something it isn't a popup, but a title to send it to the player use:

    $player->addTitle("Title", "SubTitle");

    (you don't need to add subtitle)
     
  9. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    $player->addTitle("Title""Subtitle"$fadeInTime$displayTime$fadeOutTime);
     
    Primus likes this.
  10. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Thank you for the help! :)
     
  11. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Thank you!
     
    minijaham likes this.
  12. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Isnt working. Do you see my failure?
    PHP:
     public function onJoin(PlayerJoinEvent $event)
        {
            
    $player $event->getPlayer();
            
    $name $player->getName();
            
    $fadeInTime 2;
            
    $displayTime 5;
            
    $fadeOutTime 2;
            
    $player->addTitle("Title""Subtitle"$fadeInTime$displayTime$fadeOutTime);
        }
     
  13. Primus

    Primus Zombie Pigman

    Messages:
    749
    Are you sure that code is actually executing? Try printing something in console. You probably haven't registered the listener.
     
  14. iDarkQ

    iDarkQ Spider

    Messages:
    12
    GitHub:
    idarkq
    It doesn't work because time value must be ticks (1 second is 20 ticks) so your code should look like this:


    PHP:
        public function onJoinTitle(PlayerJoinEvent $event) : void {
            
    $player $event->getPlayer();
            
    $fadeInTime 20;
            
    $displayTime 20;
            
    $fadeOutTime 20;
            
    $player->addTitle("Title""Subtitle"$fadeInTime$displayTime$fadeOutTime);
        }
     
  15. timistwild

    timistwild Spider Jockey

    Messages:
    33
    My listener is thereo_O
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    Tim\Test1;

    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;
    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 
    onJoinTitle(PlayerJoinEvent $event) : void {
           
            
    $player $event->getPlayer();
            
    $fadeInTime 20;
            
    $fadeOutTime 20;
            
    $displayTime 20;
            
    $player->addTitle("Title""Subtitle"$fadeInTime$displayTime$fadeOutTime);
        }

     
  16. Primus

    Primus Zombie Pigman

    Messages:
    749
    Completely ignored my suggestion of the way that you can debug your code. Make it print something if it actually got executed!

    Also, let it use default values, which are known to work. So you know that your parameters aren't messing things up.
     
  17. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Sorry for not using your suggestion. Test command worked and i set everything to 1 second. still not working. any ideas left?
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    Tim\Test1;

    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;
    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 
    onJoinTitle(PlayerJoinEvent $event) : void {
            
    $this->getServer()->getLogger()->info("Test Command");
            
    $player $event->getPlayer();
            
    $fadeInTime 20;
            
    $fadeOutTime 20;
            
    $displayTime 20;
            
    $player->addTitle("Title""Subtitle"$fadeInTime$displayTime$fadeOutTime);
        }








    }
     
  18. iDarkQ

    iDarkQ Spider

    Messages:
    12
    GitHub:
    idarkq
    it should work, try this:

    $player->addTitle("Test", "test 2");
     
  19. timistwild

    timistwild Spider Jockey

    Messages:
    33
  20. iDarkQ

    iDarkQ Spider

    Messages:
    12
    GitHub:
    idarkq
    I checked it and it works for me, make sure you don't have any other texturepack enabled because it might be blocking the title
     
  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.