mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Added static create() functions for many packets
There are a few motivations here: 1) Less boilerplate code (this can be written inline) 2) It's possible to provide multiple constructors for different packet variations to reduce the chance of errors. 3) It makes things catch fire on updates in ways that static analysers can understand.
This commit is contained in:
@ -829,10 +829,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
protected function sendSpawnPacket(Player $player) : void{
|
||||
if(!($this instanceof Player)){
|
||||
/* we don't use Server->updatePlayerListData() because that uses batches, which could cause race conditions in async compression mode */
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
$pk->entries = [PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $this->skin)];
|
||||
$player->sendDataPacket($pk);
|
||||
$player->sendDataPacket(PlayerListPacket::add([PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $this->skin)]));
|
||||
}
|
||||
|
||||
$pk = new AddPlayerPacket();
|
||||
@ -853,10 +850,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
$player->getNetworkSession()->onMobArmorChange($this);
|
||||
|
||||
if(!($this instanceof Player)){
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_REMOVE;
|
||||
$pk->entries = [PlayerListEntry::createRemovalEntry($this->uuid)];
|
||||
$player->sendDataPacket($pk);
|
||||
$player->sendDataPacket(PlayerListPacket::remove([PlayerListEntry::createRemovalEntry($this->uuid)]));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user