diff --git a/plugin.yml b/plugin.yml index 863948b..30c340d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,4 +1,4 @@ name: AggressiveOptz main: muqsit\aggressiveoptz\Loader api: 5.0.0 -version: 0.0.7 \ No newline at end of file +version: 0.0.8 \ No newline at end of file diff --git a/src/muqsit/aggressiveoptz/AggressiveOptzApi.php b/src/muqsit/aggressiveoptz/AggressiveOptzApi.php index 5a768ec..8a41ea5 100644 --- a/src/muqsit/aggressiveoptz/AggressiveOptzApi.php +++ b/src/muqsit/aggressiveoptz/AggressiveOptzApi.php @@ -9,7 +9,6 @@ use Logger; use muqsit\aggressiveoptz\component\defaults\FallingBlockOptimizationComponent; use muqsit\aggressiveoptz\component\defaults\LiquidFallingOptimizationComponent; -use muqsit\aggressiveoptz\component\defaults\NetworkItemOptimizationComponent; use muqsit\aggressiveoptz\component\OptimizationComponentFactory; use muqsit\aggressiveoptz\component\OptimizationComponentManager; use muqsit\aggressiveoptz\helper\AggressiveOptzHelper; @@ -45,7 +44,6 @@ private function loadComponent() : void{ $this->component_factory = new OptimizationComponentFactory(); $this->component_factory->register("{$prefix}:falling_block", FallingBlockOptimizationComponent::class); $this->component_factory->register("{$prefix}:liquid_falling", LiquidFallingOptimizationComponent::class); - $this->component_factory->register("{$prefix}:network_item", NetworkItemOptimizationComponent::class); $this->component_manager = new OptimizationComponentManager($this); } diff --git a/src/muqsit/aggressiveoptz/component/defaults/NetworkItemOptimizationComponent.php b/src/muqsit/aggressiveoptz/component/defaults/NetworkItemOptimizationComponent.php deleted file mode 100644 index 3f3ee83..0000000 --- a/src/muqsit/aggressiveoptz/component/defaults/NetworkItemOptimizationComponent.php +++ /dev/null @@ -1,127 +0,0 @@ - */ - private array $encoded_packets = []; - - public function __construct(){ - } - - public function enable(AggressiveOptzApi $api) : void{ - if($this->unregister !== null){ - throw new LogicException("Tried to register event handler twice"); - } - - $this->unregister = $api->registerEvent(function(DataPacketSendEvent $event) : void{ - $targets = $event->getTargets(); - foreach($event->getPackets() as $index => $packet){ - if($packet instanceof MobEquipmentPacket){ - foreach($targets as $target){ - if($packet->actorRuntimeId === $target->getPlayer()?->getId()){ - continue 2; - } - } - $nbt = $packet->item->getItemStack()->getNbt(); - if($nbt !== null){ - $this->cleanItemStackNbt($nbt); - } - }elseif($packet instanceof MobArmorEquipmentPacket){ - foreach($targets as $target){ - if($packet->actorRuntimeId === $target->getPlayer()?->getId()){ - continue 2; - } - } - - $nbt = $packet->head->getItemStack()->getNbt(); - if($nbt !== null){ - $this->cleanItemStackNbt($nbt); - } - $nbt = $packet->chest->getItemStack()->getNbt(); - if($nbt !== null){ - $this->cleanItemStackNbt($nbt); - } - $nbt = $packet->legs->getItemStack()->getNbt(); - if($nbt !== null){ - $this->cleanItemStackNbt($nbt); - } - $nbt = $packet->feet->getItemStack()->getNbt(); - if($nbt !== null){ - $this->cleanItemStackNbt($nbt); - } - }elseif($packet instanceof CraftingDataPacket || $packet instanceof CreativeContentPacket){ - if(!isset($this->encoded_packets[$pid = $packet::NETWORK_ID][$id = spl_object_id($packet)])){ - // these packets are already cached - just not encoded. - // in case the cache was purged, their spl_object_id would be changed. - // this array structure takes care of such changes - $this->encoded_packets[$pid] = [$id => $packet]; - } - $packets = $event->getPackets(); - $packets[$index] = $this->encoded_packets[$pid][$id]; - $event->setPackets($packets); - } - } - }, EventPriority::HIGHEST); - } - - private function cleanItemStackNbt(CompoundTag $nbt) : void{ - foreach($nbt->getValue() as $name => $tag){ - if( - $name === Armor::TAG_CUSTOM_COLOR || - $name === Banner::TAG_PATTERNS || - $name === Banner::TAG_PATTERN_COLOR || - $name === Banner::TAG_PATTERN_NAME - ){ - continue; - } - - if($name === Item::TAG_ENCH){ - assert($tag instanceof ListTag); - for($i = $tag->count() - 1; $i > 0; $i--){ - $tag->remove($i); - } - continue; - } - - $nbt->removeTag($name); - } - } - - public function disable(AggressiveOptzApi $api) : void{ - if($this->unregister === null){ - throw new LogicException("Tried to unregister an unregistered event handler"); - } - - ($this->unregister)(); - $this->unregister = null; - } -} \ No newline at end of file diff --git a/src/muqsit/aggressiveoptz/helper/LazyEncodedPacket.php b/src/muqsit/aggressiveoptz/helper/LazyEncodedPacket.php deleted file mode 100644 index 69c7605..0000000 --- a/src/muqsit/aggressiveoptz/helper/LazyEncodedPacket.php +++ /dev/null @@ -1,51 +0,0 @@ -inner->pid(); - } - - public function getName() : string{ - return $this->inner->getName(); - } - - public function canBeSentBeforeLogin() : bool{ - return $this->inner->canBeSentBeforeLogin(); - } - - public function decode(PacketSerializer $in) : void{ - $this->inner->decode($in); - } - - public function encode(PacketSerializer $out) : void{ - if($this->encoded === null){ - $serializer = PacketSerializer::encoder($this->context); - $this->inner->encode($serializer); - $this->encoded = $serializer->getBuffer(); - } - $out->put($this->encoded); - } - - public function handle(PacketHandlerInterface $handler) : bool{ - return $this->inner->handle($handler); - } -} \ No newline at end of file