pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.25k stars 1.53k forks source link

problems with NetworkBroadcastUtils #5670

Closed SmallkingDev closed 1 year ago

SmallkingDev commented 1 year ago

Issue description

Steps to reproduce the issue

  1. use any method of the Entity class and try to debug the expected package information

OS and versions

dktapps commented 1 year ago

Please provide reproducing code.

SmallkingDev commented 1 year ago

Please provide reproducing code.

Please provide reproducing code.

<?php

declare(strict_types=1);

namespace test;

use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\player\Player;
use pocketmine\event\server\DataPacketSendEvent;

use function var_dump;

final class Loader extends PluginBase implements Listener {

   protected function onEnable(): void {
      $this->getServer()->getPluginManager()->registerEvents($this, $this);

       $this->getServer()->getCommandMap()->register("test", new class extends Command {
                public function __construct() {
                    parent::__construct("test");
                }

                public function execute(CommandSender $sender, string $commandLabel, array $args): void {
                    if ($sender instanceof Player) {
                        foreach ($sender->getViewers() as $viewer) {
                            $viewer->setNameTag("§c§l" . $sender->getName());
                        }
                    }
                }
            });
   }

    public function onDataPacketSend(DataPacketSendEvent $event) : void {
        $packets = $event->getPackets();

        foreach ($packets as $packet) {
            if ($packet instanceof SetActorDataPacket) {
                var_dump($packet);
            }
        }
    }
}
dktapps commented 1 year ago

This problem occurs because EntityEventBroadcaster bypasses NetworkBroadcastUtils, and uses StandardPacketBroadcaster directly.