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

UI and PlayerJoin

Discussion in 'Development' started by Spajk, Oct 7, 2017.

  1. Spajk

    Spajk Spider

    Messages:
    8
    GitHub:
    spajk7
    PlayerJoinEvent seems to be called too early to show a UI window to the player. Other then delaying it using tasks, is there another way to show the UI as soon as possible?
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Are you certain? PlayerJoinEvent should be called once the player is able to see a UI. The primary factor for if a UI can be seen by the client is the speed at which it loads in everything and internet latency.
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    try player respawn event?
    tho you need to check for first respawn
    same goes you cant transfer player on playerjoinevent but after respawn event
     
  4. Spajk

    Spajk Spider

    Messages:
    8
    GitHub:
    spajk7
    I am pretty sure. I have a GUI and a chat message sent. I get the message but not the GUI. When I trigger the same function from a command, I get both GUI and the message.

    Thanks, I'll check and report back.

    EDIT:
    PlayerRespawnEvent isn't triggered for the first spawn.

    EDIT2: Delaying the GUI 20 ticks after PlayerJoinEvent works great. Out of 10 times I tried, the GUI was shown every time. I am still looking for a better ( right ) way to do this.
     
    Last edited: Oct 7, 2017
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It used to work previously but was later removed due to logical reasons.

    That's the only workaround. If you find it dirty to create a new task class dedicated for such a small thing, use anonymous classes. Pretty much the same thing but it makes everything look arguably cleaner in your case.
    PHP:
    /** @var Player $player */
    /** @var ModalFormRequestPacket $modal */

    $player->getServer()->getScheduler()->scheduleDelayedTask(new class($player$modal) extends Task{

        
    /** @var Player */
        
    private $player;

        
    /** @var ModalFormRequestPacket */
        
    private $modal;

        public function 
    __construct(Player $playerModalFormRequestPacket $modal){
            
    $this->player $player;
            
    $this->modal $modal;
        }

        public function 
    onRun(int $tick){
            
    $this->player->dataPacket($this->modal);
        }
    }, 
    20);
     
    Spajk and jasonwynn10 like 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.