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?
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.
try player respawn event? tho you need to check for first respawn same goes you cant transfer player on playerjoinevent but after respawn event
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.
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 $player, ModalFormRequestPacket $modal){ $this->player = $player; $this->modal = $modal; } public function onRun(int $tick){ $this->player->dataPacket($this->modal); }}, 20);