From 8e6f21afad1f6ce6c3ca2496195107fbaefb3cd1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 10 Jun 2019 19:58:14 +0100 Subject: [PATCH] clean up gamemode net sync --- src/pocketmine/Player.php | 17 ++--------------- src/pocketmine/network/mcpe/NetworkSession.php | 6 +++++- .../mcpe/handler/InGameSessionHandler.php | 3 +-- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 24b6aa22a..5a89d4a7d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -27,7 +27,6 @@ use pocketmine\block\Bed; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\block\UnknownBlock; -use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\entity\effect\Effect; use pocketmine\entity\effect\EffectInstance; @@ -1262,11 +1261,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * Sets the gamemode, and if needed, kicks the Player. * * @param GameMode $gm - * @param bool $client if the client made this change in their GUI * * @return bool */ - public function setGamemode(GameMode $gm, bool $client = false) : bool{ + public function setGamemode(GameMode $gm) : bool{ if($this->gamemode === $gm){ return false; } @@ -1274,9 +1272,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $ev = new PlayerGameModeChangeEvent($this, $gm); $ev->call(); if($ev->isCancelled()){ - if($client){ //gamemode change by client in the GUI - $this->networkSession->syncGameMode($this->gamemode); - } return false; } @@ -1295,15 +1290,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->spawnToAll(); } - if(!$client){ //Gamemode changed by server, do not send for client changes - $this->networkSession->syncGameMode($this->gamemode); - }else{ - Command::broadcastCommandMessage($this, new TranslationContainer("commands.gamemode.success.self", [$gm->getTranslationKey()])); - } - - $this->networkSession->syncAdventureSettings($this); - $this->networkSession->syncCreativeInventoryContents(); - + $this->networkSession->syncGameMode($this->gamemode); return true; } diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index c6cd8a9c3..adcb0f3d9 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -610,8 +610,12 @@ class NetworkSession{ $this->sendDataPacket(SetSpawnPositionPacket::playerSpawn($newSpawn->getFloorX(), $newSpawn->getFloorY(), $newSpawn->getFloorZ(), false)); //TODO: spawn forced } - public function syncGameMode(GameMode $mode) : void{ + public function syncGameMode(GameMode $mode, bool $isRollback = false) : void{ $this->sendDataPacket(SetPlayerGameTypePacket::create(self::getClientFriendlyGamemode($mode))); + $this->syncAdventureSettings($this->player); + if(!$isRollback){ + $this->syncCreativeInventoryContents(); + } } /** diff --git a/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php b/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php index 6393e48e6..6e1bd11c3 100644 --- a/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/InGameSessionHandler.php @@ -534,8 +534,7 @@ class InGameSessionHandler extends SessionHandler{ public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ if($packet->gamemode !== $this->player->getGamemode()->getMagicNumber()){ //Set this back to default. TODO: handle this properly - $this->session->syncGameMode($this->player->getGamemode()); - $this->session->syncAdventureSettings($this->player); + $this->session->syncGameMode($this->player->getGamemode(), true); } return true; }