From 07f19dd4a101abfadac58b1db8f08ff6c72d4b55 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 5 Nov 2019 22:33:12 -0500 Subject: [PATCH] Fixed respawning --- src/pocketmine/Player.php | 10 +++++++++- .../network/mcpe/PlayerNetworkSessionAdapter.php | 5 +++++ src/pocketmine/network/mcpe/protocol/RespawnPacket.php | 10 +++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b7fa2dbb8..94cd39bc4 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1114,7 +1114,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - protected function sendRespawnPacket(Vector3 $pos, int $respawnState = 1){ + protected function sendRespawnPacket(Vector3 $pos, int $respawnState = RespawnPacket::SEARCHING_FOR_SPAWN){ $pk = new RespawnPacket(); $pk->position = $pos->add(0, $this->baseOffset, 0); $pk->respawnState = $respawnState; @@ -2918,6 +2918,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } + public function handleRespawn(RespawnPacket $packet) : bool{ + if(!$this->isAlive() && $packet->respawnState === RespawnPacket::CLIENT_READY_TO_SPAWN){ + $this->sendRespawnPacket($this, RespawnPacket::READY_TO_SPAWN); + } + + return true; + } + /** * Drops an item on the ground in front of the player. Returns if the item drop was successful. * diff --git a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php index 914b8becc..7a41eb194 100644 --- a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php +++ b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php @@ -59,6 +59,7 @@ use pocketmine\network\mcpe\protocol\PlayerSkinPacket; use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket; use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; +use pocketmine\network\mcpe\protocol\RespawnPacket; use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket; use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; @@ -181,6 +182,10 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ return $this->player->handleAnimate($packet); } + public function handleRespawn(RespawnPacket $packet) : bool{ + return $this->player->handleRespawn($packet); + } + public function handleContainerClose(ContainerClosePacket $packet) : bool{ return $this->player->handleContainerClose($packet); } diff --git a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php index 1f8cb4091..6705877e8 100644 --- a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php @@ -32,22 +32,26 @@ use pocketmine\network\mcpe\NetworkSession; class RespawnPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::RESPAWN_PACKET; + public const SEARCHING_FOR_SPAWN = 0; + public const READY_TO_SPAWN = 1; + public const CLIENT_READY_TO_SPAWN = 2; + /** @var Vector3 */ public $position; /** @var int */ - public $respawnState = 1; //TODO: Add + public $respawnState = self::SEARCHING_FOR_SPAWN; /** @var int */ public $entityRuntimeId; protected function decodePayload(){ $this->position = $this->getVector3(); - $this->respawnState = $this->getInt(); + $this->respawnState = $this->getByte(); $this->entityRuntimeId = $this->getEntityRuntimeId(); } protected function encodePayload(){ $this->putVector3($this->position); - $this->putInt($this->respawnState); + $this->putByte($this->respawnState); $this->putEntityRuntimeId($this->entityRuntimeId); }