World: relocate packet stuff for time and difficulty behind NetworkSession API

This commit is contained in:
Dylan K. Taylor
2020-04-29 18:31:54 +01:00
parent c8c0a1533c
commit bb11cbd89c
2 changed files with 16 additions and 22 deletions

View File

@@ -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());
}
}