Tittle say all, i try using public function onVoidLoop(PlayerMoveEvent $event){ if($event->getTo()->getFloorY() < 1){ $event->setCancelled(true); $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation()); But, does not work .-.
That is a glitch in the way teleport works. My ManyWorlds plugin has a workaround for that. You can use that workaround in your own plugin. I use this code: PHP: if (($mw = $this->getServer()->getPluginManager()->getPlugin("ManyWorlds")) != null) { // Using ManyWorlds for teleporting... $mw->teleport($event->getPlayer(),$level); } else { $world = $this->getServer()->getLevelByName($level); $event->getPlayer()->teleport($world->getSafeSpawn());}
You can call the ManyWorlds plugin (so that would become an optional dependency for your plugin). On the other hand, that functionality is in a single file TeleportManager.php Keep in mind that I am using a GPL license, so if you include this, then your plugin becomes GPL. If you know how to recreate the bug, make sure that ManyWorlds does indeed solve your problem (mw has a teleport command). Otherwise you would spending your time for nothing.
of cause it not working, try this: public function onVoidLoop(PlayerMoveEvent $event){ if($event->getTo()->getFloorY() < 1){ $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation());
After looking at his code, I don't think this would work. Or if it does, it will not very reliable. You have a race condition. The client moves the player and sends the move event to the server. The server then have to make sure that it cancels the move before the client completes the client move and drops the player to the void. If the server is a bit over loaded, the move cancel may happen after the player drops to the void. Perhaps you should change your condition: PHP: if($event->getTo()->getFloorY() < 1){ To some value other than 1 (to give the server some time to send the cancel).
Don't teleport a player in a cancelled PlayerMoveEvent. EITHER teleport one tick later OR just don't cancel the PlayerMoveEvent.
Sorry but I couldn't resist replying to this thread (I'm searching for something ;P) PHP: $event->setTo($pos);