mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 11:26:37 +00:00
World: ensure that addParticle/addSound don't send stuff to players who are not in range, even when an array of targets is given
closes #5347
This commit is contained in:
parent
572def9245
commit
cd04a3db2e
@ -630,6 +630,28 @@ class World implements ChunkManager{
|
|||||||
unset($this->unloadCallbacks[spl_object_id($callback)]);
|
unset($this->unloadCallbacks[spl_object_id($callback)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of players who are in the given filter and also using the chunk containing the target position.
|
||||||
|
* Used for broadcasting sounds and particles with specific targets.
|
||||||
|
*
|
||||||
|
* @param Player[] $allowed
|
||||||
|
* @phpstan-param list<Player> $allowed
|
||||||
|
*
|
||||||
|
* @return array<int, Player>
|
||||||
|
*/
|
||||||
|
private function filterViewersForPosition(Vector3 $pos, array $allowed) : array{
|
||||||
|
$candidates = $this->getViewersForPosition($pos);
|
||||||
|
$filtered = [];
|
||||||
|
foreach($allowed as $player){
|
||||||
|
$k = spl_object_id($player);
|
||||||
|
if(isset($candidates[$k])){
|
||||||
|
$filtered[$k] = $candidates[$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $filtered;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Player[]|null $players
|
* @param Player[]|null $players
|
||||||
*/
|
*/
|
||||||
@ -641,7 +663,7 @@ class World implements ChunkManager{
|
|||||||
$this->broadcastPacketToViewers($pos, $e);
|
$this->broadcastPacketToViewers($pos, $e);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$this->server->broadcastPackets($players, $pk);
|
$this->server->broadcastPackets($this->filterViewersForPosition($pos, $players), $pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -657,7 +679,7 @@ class World implements ChunkManager{
|
|||||||
$this->broadcastPacketToViewers($pos, $e);
|
$this->broadcastPacketToViewers($pos, $e);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$this->server->broadcastPackets($players, $pk);
|
$this->server->broadcastPackets($this->filterViewersForPosition($pos, $players), $pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user