Skip to content

Instantly share code, notes, and snippets.

@DavyCraft648
Created November 12, 2022 21:26
Show Gist options
  • Select an option

  • Save DavyCraft648/09bb99225dc0e4140d9bedea91b50b1f to your computer and use it in GitHub Desktop.

Select an option

Save DavyCraft648/09bb99225dc0e4140d9bedea91b50b1f to your computer and use it in GitHub Desktop.
A plugin that fixes a bug where players fly when using shield on wdpe proxy by sending EntityMetadataProperties::FLAGS when sending EntityMetadataProperties::FLAGS2
<?php
namespace DavyCraft648\FlyingShield;
use pocketmine\event\EventPriority;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\network\mcpe\protocol\SetActorDataPacket;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
/**
* @name FlyingShield
* @version 0.0.1
* @main DavyCraft648\FlyingShield\FlyingShield
* @api 4.0.0
*/
class FlyingShield extends \pocketmine\plugin\PluginBase{
protected function onEnable() : void{
$this->getServer()->getPluginManager()->registerEvent(DataPacketSendEvent::class, function(DataPacketSendEvent $event) : void{
foreach($event->getPackets() as $packet){
if($packet instanceof SetActorDataPacket){
foreach($event->getTargets() as $session){
$player = $session->getPlayer();
if($player === null){
continue;
}
$entity = $player->getWorld()->getEntity($packet->actorRuntimeId);
if($entity === null){
continue;
}
if(isset($packet->metadata[EntityMetadataProperties::FLAGS2]) && !isset($packet->metadata[EntityMetadataProperties::FLAGS])){
$packet->metadata[EntityMetadataProperties::FLAGS] = $entity->getNetworkProperties()->getAll()[EntityMetadataProperties::FLAGS];
break;
}
}
}
}
}, EventPriority::LOWEST, $this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment