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

What should I do next if I will send title on join ?

Discussion in 'Facepalm' started by CreeperMonster, Aug 2, 2017.

  1. CreeperMonster

    CreeperMonster Slime

    Messages:
    81
    GitHub:
    CreeperMonster
    Im planning to make a JoinTitle plugin for my server
    But Since Im a beginner,I dont know what to do next
    Can someone pls help me what to do next


    PHP:
    <?php

    namespace creepermonster\jointitlepe;

    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase{
        public function 
    onLoad(){
            
    $this->getLogger()->info("JoinTitlePE Loading");
        }
        public function 
    onEnable(){
            
    $this->getLogger()->info("JoinTitlePE Enabled");
        }
        public function 
    onDisable(){
            
    $this->getLogger()->info("JoinTitlePE Disabled");
        } 
     
  2. CreeperMonster

    CreeperMonster Slime

    Messages:
    81
    GitHub:
    CreeperMonster
    or please send me a code to send title on join event
     
  3. Andrés Komet

    Andrés Komet Creeper

    Messages:
    3
    GitHub:
    GiantQuartz
    Hello, CreeperMonster.

    As you want send a message when a player join, you must use a Event. To use events, you'll need a event listener. This time we are going to use your main class as Listener, simply implement Listener class in your Main class.

    PHP:
    class Main extends PluginBase implements Listener {
    // code
    }
    You must register events to tell PocketMine where are you going to handle the events. You can do this onEnable function.

    PHP:
    class Main extends PluginBase implements Listener{
        public function 
    onLoad(){
            
    $this->getLogger()->info("JoinTitlePE Loading");
        }
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info("JoinTitlePE Enabled");
        }
        public function 
    onDisable(){
            
    $this->getLogger()->info("JoinTitlePE Disabled");
        }
    Now you can handle events on your Main class. As you want add a title when a player join, you can use PlayerJoinEvent.

    PHP:
    public function onJoin(PlayerJoinEvent $event) {
            
    $event->getPlayer()->addTitle("This is a title""This is a subtitle");
    }
     
    Last edited: Aug 2, 2017
  4. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    However, just doing this will not show the title as the player joins.
    You must schedule a delayed task and then proceed to sending the title.
     
    jasonwynn10 and Levi like this.
  5. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    This won't work. You'll have to make a task
     
    Last edited: Aug 6, 2017
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    WTF Its not true
     
  8. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    it's true, the title will popup while you're still in the loading screen
     
    Last edited: Aug 6, 2017
    jasonwynn10 likes this.
  9. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    use
    $event->getPlayer()->addTitle()
     
  10. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
  11. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    True, the duration can be set fro how long the title should stay on the user's screen, however, that doesn't actually add the title AFTER the player joins. It only appears when the player is able to see it, but the title is sent before the player joins which can cause other issues aswell(citation needed)
     
  12. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    i made a task for it and set the time to 0, basically the same thing as noting and it still worked , delayed task ofc
     
  13. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    @CreeperMonster Here use this.
    PHP:
    public function onJoinTitle(PlayerJoinEvent $ev){
      
    $ev $ev->getPlayer();
      
    $ev->addTitle("Text here""sub-title here""fade-in""duration""fade-out");
    }
     
  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.