From 8b87cf73b9a2c8a781bb44a4c11db469bf722655 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 29 Jun 2020 22:51:02 +0100 Subject: [PATCH] Player->setSpawn() now accepts NULL (fallback to world spawn) --- src/player/Player.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index a110daacd..937f68c19 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -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{