Add the event: WorldSoundEvent (#5322)

This commit is contained in:
Armen Deroian
2022-12-06 08:06:40 -05:00
committed by GitHub
parent 1d4b6dc66e
commit fed2a6d917
3 changed files with 91 additions and 3 deletions

View File

@@ -51,6 +51,7 @@ use pocketmine\event\world\ChunkPopulateEvent;
use pocketmine\event\world\ChunkUnloadEvent;
use pocketmine\event\world\SpawnChangeEvent;
use pocketmine\event\world\WorldSaveEvent;
use pocketmine\event\world\WorldSoundEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemUseResult;
use pocketmine\item\LegacyStringToItemParser;
@@ -665,9 +666,19 @@ class World implements ChunkManager{
* @param Player[]|null $players
*/
public function addSound(Vector3 $pos, Sound $sound, ?array $players = null) : void{
$pk = $sound->encode($pos);
$players ??= $this->getViewersForPosition($pos);
$ev = new WorldSoundEvent($this, $sound, $pos, $players);
$ev->call();
if($ev->isCancelled()){
return;
}
$pk = $ev->getSound()->encode($pos);
$players = $ev->getRecipients();
if(count($pk) > 0){
if($players === null){
if($players === $this->getViewersForPosition($pos)){
foreach($pk as $e){
$this->broadcastPacketToViewers($pos, $e);
}