-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aggressiveoptz:network_item: cache encoded CraftingDataPacket and Cre…
…ativeContentPacket data
- Loading branch information
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: AggressiveOptz | ||
main: muqsit\aggressiveoptz\Loader | ||
api: 5.0.0 | ||
version: 0.0.6 | ||
version: 0.0.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace muqsit\aggressiveoptz\helper; | ||
|
||
use pocketmine\network\mcpe\protocol\ClientboundPacket; | ||
use pocketmine\network\mcpe\protocol\PacketHandlerInterface; | ||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; | ||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext; | ||
|
||
final class LazyEncodedPacket implements ClientboundPacket{ | ||
|
||
public const NETWORK_ID = -1; | ||
|
||
private ?string $encoded = null; | ||
|
||
public function __construct( | ||
readonly private PacketSerializerContext $context, | ||
readonly private ClientboundPacket $inner | ||
){} | ||
|
||
public function pid() : int{ | ||
return $this->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); | ||
} | ||
} |