Hi! After one of updates AlwasySpawn plugin stops to work He is trying to teleport player to world spawn position right from onPlayerLogin event. PHP: public function onPlayerLogin(PlayerLoginEvent $event) { $player = $event->getPlayer(); $x = $this->getServer()->getDefaultLevel()->getSafeSpawn()->getX(); $y = $this->getServer()->getDefaultLevel()->getSafeSpawn()-> getY(); $z = $this->getServer()->getDefaultLevel()->getSafeSpawn()->getZ(); $level = $this->getServer()->getDefaultLevel(); $pos = new Position($x, $y, $z, $level); $player->teleport($pos); } But now it doesn't work What is the correct way now to force player to appear always on the particular position after the relogin?
You dont want to check x,y,z of spawn position getSafeSpawn already return position PHP: $player->teleport($level->getSafeSpawn());
What Kyd said does work: PHP: public function onPlayerLogin(PlayerLoginEvent $event) { $player = $event->getPlayer(); $level = $this->getServer()->getDefaultLevel(); $player->teleport($level->getSafeSpawn());} I tested it several times. And it works perfectly fine
Well, I've checked all events that occurs wneh player connects to the server and tryied to setSpawn there PlayerCreationEvent - we cannot do anything yet. Player object not constructed yet PlayerPreLoginEvent - same thing: got Exception: "Attempted to send pocketmine\network\mcpe\protocol\SetSpawnPositionPacket to Steve too early EntitySpawnEvent - SetSpawnPositionPacket sent to the player but no effect PlayerLoginEvent - same But looks like I found solution. In the EntitySpawnEvent I also call $player->setPosition($spawnPos) and it works! Hope there will not be any side effect