diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 0d1ae96a3..1826c8618 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -72,8 +72,10 @@ use pocketmine\network\mcpe\protocol\serializer\PacketBatch; use pocketmine\network\mcpe\protocol\ServerboundPacket; use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket; use pocketmine\network\mcpe\protocol\SetActorDataPacket; +use pocketmine\network\mcpe\protocol\SetDifficultyPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; +use pocketmine\network\mcpe\protocol\SetTimePacket; use pocketmine\network\mcpe\protocol\SetTitlePacket; use pocketmine\network\mcpe\protocol\TakeItemActorPacket; use pocketmine\network\mcpe\protocol\TextPacket; @@ -815,8 +817,16 @@ class NetworkSession{ public function onEnterWorld() : void{ $world = $this->player->getWorld(); - $world->sendTime($this->player); - $world->sendDifficulty($this->player); + $this->syncWorldTime($world->getTime()); + $this->syncWorldDifficulty($world->getDifficulty()); + } + + public function syncWorldTime(int $worldTime) : void{ + $this->sendDataPacket(SetTimePacket::create($worldTime)); + } + + public function syncWorldDifficulty(int $worldDifficulty) : void{ + $this->sendDataPacket(SetDifficultyPacket::create($worldDifficulty)); } public function getInvManager() : InventoryManager{ diff --git a/src/world/World.php b/src/world/World.php index 855661059..71de88a1e 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -54,8 +54,6 @@ use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; -use pocketmine\network\mcpe\protocol\SetDifficultyPacket; -use pocketmine\network\mcpe\protocol\SetTimePacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\player\Player; use pocketmine\Server; @@ -644,12 +642,8 @@ class World implements ChunkManager{ * @param Player ...$targets If empty, will send to all players in the world. */ public function sendTime(Player ...$targets) : void{ - $pk = SetTimePacket::create($this->time); - - if(count($targets) === 0){ - $this->broadcastGlobalPacket($pk); - }else{ - $this->server->broadcastPackets($targets, [$pk]); + foreach($targets as $player){ + $player->getNetworkSession()->syncWorldTime($this->time); } } @@ -2362,18 +2356,8 @@ class World implements ChunkManager{ } $this->provider->getWorldData()->setDifficulty($difficulty); - $this->sendDifficulty(); - } - - /** - * @param Player ...$targets - */ - public function sendDifficulty(Player ...$targets) : void{ - $pk = SetDifficultyPacket::create($this->getDifficulty()); - if(count($targets) === 0){ - $this->broadcastGlobalPacket($pk); - }else{ - $this->server->broadcastPackets($targets, [$pk]); + foreach($this->players as $player){ + $player->getNetworkSession()->syncWorldDifficulty($this->getDifficulty()); } }