mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Entity: clean up sendData() handling, remove send-to-self hack
This commit is contained in:
parent
01b44ab0bc
commit
b0b08d45d5
@ -605,7 +605,7 @@ abstract class Entity{
|
||||
|
||||
$changedProperties = $this->getSyncedNetworkData(true);
|
||||
if(count($changedProperties) > 0){
|
||||
$this->sendData($this->hasSpawned, $changedProperties);
|
||||
$this->sendData(null, $changedProperties);
|
||||
$this->networkProperties->clearDirtyProperties();
|
||||
}
|
||||
|
||||
@ -1609,28 +1609,18 @@ abstract class Entity{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player[]|Player $player
|
||||
* @param Player[]|null $targets
|
||||
* @param MetadataProperty[] $data Properly formatted entity data, defaults to everything
|
||||
*
|
||||
* @phpstan-param array<int, MetadataProperty> $data
|
||||
*/
|
||||
public function sendData($player, ?array $data = null) : void{
|
||||
if(!is_array($player)){
|
||||
$player = [$player];
|
||||
}
|
||||
|
||||
public function sendData(?array $targets, ?array $data = null) : void{
|
||||
$targets = $targets ?? $this->hasSpawned;
|
||||
$data = $data ?? $this->getSyncedNetworkData(false);
|
||||
|
||||
foreach($player as $p){
|
||||
if($p === $this){
|
||||
continue;
|
||||
}
|
||||
foreach($targets as $p){
|
||||
$p->getNetworkSession()->syncActorData($this, $data);
|
||||
}
|
||||
|
||||
if($this instanceof Player){
|
||||
//TODO: bad hack, remove
|
||||
$this->getNetworkSession()->syncActorData($this, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -401,7 +401,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
||||
$player->getNetworkSession()->sendDataPacket($pk);
|
||||
|
||||
//TODO: Hack for MCPE 1.2.13: DATA_NAMETAG is useless in AddPlayerPacket, so it has to be sent separately
|
||||
$this->sendData($player, [EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->getNameTag())]);
|
||||
$this->sendData([$player], [EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->getNameTag())]);
|
||||
|
||||
$player->getNetworkSession()->onMobArmorChange($this);
|
||||
|
||||
|
@ -649,8 +649,7 @@ class NetworkSession{
|
||||
}
|
||||
|
||||
public function onRespawn() : void{
|
||||
$this->player->sendData($this->player);
|
||||
$this->player->sendData($this->player->getViewers());
|
||||
$this->player->sendData(null);
|
||||
|
||||
$this->syncAdventureSettings($this->player);
|
||||
$this->invManager->syncAll();
|
||||
|
@ -506,22 +506,22 @@ class InGamePacketHandler extends PacketHandler{
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SPRINT:
|
||||
if(!$this->player->toggleSprint(true)){
|
||||
$this->player->sendData($this->player);
|
||||
$this->player->sendData([$this->player]);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SPRINT:
|
||||
if(!$this->player->toggleSprint(false)){
|
||||
$this->player->sendData($this->player);
|
||||
$this->player->sendData([$this->player]);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SNEAK:
|
||||
if(!$this->player->toggleSneak(true)){
|
||||
$this->player->sendData($this->player);
|
||||
$this->player->sendData([$this->player]);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SNEAK:
|
||||
if(!$this->player->toggleSneak(false)){
|
||||
$this->player->sendData($this->player);
|
||||
$this->player->sendData([$this->player]);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_GLIDE:
|
||||
|
@ -95,7 +95,7 @@ class PreSpawnPacketHandler extends PacketHandler{
|
||||
foreach($this->player->getEffects()->all() as $effect){
|
||||
$this->session->onEntityEffectAdded($this->player, $effect, false);
|
||||
}
|
||||
$this->player->sendData($this->player);
|
||||
$this->player->sendData([$this->player]);
|
||||
|
||||
$this->session->getInvManager()->syncAll();
|
||||
$this->session->getInvManager()->syncCreative();
|
||||
|
@ -2185,6 +2185,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
$properties->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, $this->sleeping ?? new Vector3(0, 0, 0));
|
||||
}
|
||||
|
||||
public function sendData(?array $targets, ?array $data = null) : void{
|
||||
if($targets === null){
|
||||
$targets = $this->getViewers();
|
||||
$targets[] = $this;
|
||||
}
|
||||
parent::sendData($targets, $data);
|
||||
}
|
||||
|
||||
public function broadcastAnimation(Animation $animation, ?array $targets = null) : void{
|
||||
if($this->spawned and $targets === null){
|
||||
$targets = $this->getViewers();
|
||||
|
Loading…
x
Reference in New Issue
Block a user