Player->setSpawn() now accepts NULL (fallback to world spawn)

This commit is contained in:
Dylan K. Taylor 2020-06-29 22:51:02 +01:00
parent c0af05fcad
commit 8b87cf73b9

View File

@ -949,16 +949,20 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
* Sets the spawnpoint of the player (and the compass direction) to a Vector3, or set it on another world with a
* Position object
*
* @param Vector3|Position $pos
* @param Vector3|Position|null $pos
*/
public function setSpawn(Vector3 $pos) : void{
if(!($pos instanceof Position)){
$world = $this->getWorld();
public function setSpawn(?Vector3 $pos) : void{
if($pos !== null){
if(!($pos instanceof Position)){
$world = $this->getWorld();
}else{
$world = $pos->getWorld();
}
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $world);
}else{
$world = $pos->getWorld();
$this->spawnPosition = null;
}
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $world);
$this->networkSession->syncPlayerSpawnPoint($this->spawnPosition);
$this->networkSession->syncPlayerSpawnPoint($this->getSpawn());
}
public function isSleeping() : bool{