mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 17:29:44 +00:00
World: relocate packet stuff for time and difficulty behind NetworkSession API
This commit is contained in:
parent
c8c0a1533c
commit
bb11cbd89c
@ -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{
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user