clean up gamemode net sync

This commit is contained in:
Dylan K. Taylor 2019-06-10 19:58:14 +01:00
parent f0d56f25b6
commit 8e6f21afad
3 changed files with 8 additions and 18 deletions

View File

@ -27,7 +27,6 @@ use pocketmine\block\Bed;
use pocketmine\block\BlockFactory; use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds; use pocketmine\block\BlockLegacyIds;
use pocketmine\block\UnknownBlock; use pocketmine\block\UnknownBlock;
use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\entity\effect\Effect; use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance; 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. * Sets the gamemode, and if needed, kicks the Player.
* *
* @param GameMode $gm * @param GameMode $gm
* @param bool $client if the client made this change in their GUI
* *
* @return bool * @return bool
*/ */
public function setGamemode(GameMode $gm, bool $client = false) : bool{ public function setGamemode(GameMode $gm) : bool{
if($this->gamemode === $gm){ if($this->gamemode === $gm){
return false; return false;
} }
@ -1274,9 +1272,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$ev = new PlayerGameModeChangeEvent($this, $gm); $ev = new PlayerGameModeChangeEvent($this, $gm);
$ev->call(); $ev->call();
if($ev->isCancelled()){ if($ev->isCancelled()){
if($client){ //gamemode change by client in the GUI
$this->networkSession->syncGameMode($this->gamemode);
}
return false; return false;
} }
@ -1295,15 +1290,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$this->spawnToAll(); $this->spawnToAll();
} }
if(!$client){ //Gamemode changed by server, do not send for client changes
$this->networkSession->syncGameMode($this->gamemode); $this->networkSession->syncGameMode($this->gamemode);
}else{
Command::broadcastCommandMessage($this, new TranslationContainer("commands.gamemode.success.self", [$gm->getTranslationKey()]));
}
$this->networkSession->syncAdventureSettings($this);
$this->networkSession->syncCreativeInventoryContents();
return true; return true;
} }

View File

@ -610,8 +610,12 @@ class NetworkSession{
$this->sendDataPacket(SetSpawnPositionPacket::playerSpawn($newSpawn->getFloorX(), $newSpawn->getFloorY(), $newSpawn->getFloorZ(), false)); //TODO: spawn forced $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->sendDataPacket(SetPlayerGameTypePacket::create(self::getClientFriendlyGamemode($mode)));
$this->syncAdventureSettings($this->player);
if(!$isRollback){
$this->syncCreativeInventoryContents();
}
} }
/** /**

View File

@ -534,8 +534,7 @@ class InGameSessionHandler extends SessionHandler{
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
if($packet->gamemode !== $this->player->getGamemode()->getMagicNumber()){ if($packet->gamemode !== $this->player->getGamemode()->getMagicNumber()){
//Set this back to default. TODO: handle this properly //Set this back to default. TODO: handle this properly
$this->session->syncGameMode($this->player->getGamemode()); $this->session->syncGameMode($this->player->getGamemode(), true);
$this->session->syncAdventureSettings($this->player);
} }
return true; return true;
} }