From 69fb2786c62990e16056e683eebcae46014ade93 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 29 Jun 2020 22:32:00 +0100 Subject: [PATCH] Player: fixed spawn position sticking to old world spawn when new world spawn is set this will still take effect for preexisting data because the server will still see previously set spawns as custom, but for new players, their spawns will follow the world spawn unless they sleep in a bed. --- src/player/Player.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index a13ed87d6..2d8feec1e 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -347,12 +347,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->setNameTagAlwaysVisible(); $this->setCanClimb(); - if(!$this->hasValidSpawnPosition()){ - if(($world = $this->server->getWorldManager()->getWorldByName($nbt->getString("SpawnLevel", ""))) instanceof World){ - $this->spawnPosition = new Position($nbt->getInt("SpawnX"), $nbt->getInt("SpawnY"), $nbt->getInt("SpawnZ"), $world); - }else{ - $this->spawnPosition = $this->getWorld()->getSafeSpawn(); - } + if(($world = $this->server->getWorldManager()->getWorldByName($nbt->getString("SpawnLevel", ""))) instanceof World){ + $this->spawnPosition = new Position($nbt->getInt("SpawnX"), $nbt->getInt("SpawnY"), $nbt->getInt("SpawnZ"), $world); } } @@ -936,7 +932,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * @return Position */ public function getSpawn(){ - if($this->hasValidSpawnPosition()){ + if($this->hasValidCustomSpawn()){ return $this->spawnPosition; }else{ $world = $this->server->getWorldManager()->getDefaultWorld(); @@ -945,7 +941,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } } - public function hasValidSpawnPosition() : bool{ + public function hasValidCustomSpawn() : bool{ return $this->spawnPosition !== null and $this->spawnPosition->isValid(); } @@ -2081,20 +2077,21 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $nbt->setString("Level", $this->getWorld()->getFolderName()); } - if($this->hasValidSpawnPosition()){ + if($this->hasValidCustomSpawn()){ $nbt->setString("SpawnLevel", $this->spawnPosition->getWorld()->getFolderName()); $nbt->setInt("SpawnX", $this->spawnPosition->getFloorX()); $nbt->setInt("SpawnY", $this->spawnPosition->getFloorY()); $nbt->setInt("SpawnZ", $this->spawnPosition->getFloorZ()); + } - if(!$this->isAlive()){ - //hack for respawn after quit - $nbt->setTag("Pos", new ListTag([ - new DoubleTag($this->spawnPosition->x), - new DoubleTag($this->spawnPosition->y), - new DoubleTag($this->spawnPosition->z) - ])); - } + if(!$this->isAlive()){ + $spawn = $this->getSpawn(); + //hack for respawn after quit + $nbt->setTag("Pos", new ListTag([ + new DoubleTag($spawn->getFloorX()), + new DoubleTag($spawn->getFloorY()), + new DoubleTag($spawn->getFloorZ()) + ])); } $nbt->setInt("playerGameType", $this->gamemode->getMagicNumber());