Added static create() functions for many packets

There are a few motivations here:
1) Less boilerplate code (this can be written inline)
2) It's possible to provide multiple constructors for different packet variations to reduce the chance of errors.
3) It makes things catch fire on updates in ways that static analysers can understand.
This commit is contained in:
Dylan K. Taylor
2019-06-05 15:00:08 +01:00
parent 09afb8e772
commit 287c8c2dd4
51 changed files with 481 additions and 247 deletions

View File

@ -43,6 +43,16 @@ class ResourcePackDataInfoPacket extends DataPacket implements ClientboundPacket
/** @var string */
public $sha256;
public static function create(string $packId, int $maxChunkSize, int $chunkCount, int $compressedPackSize, string $sha256sum) : self{
$result = new self;
$result->packId = $packId;
$result->maxChunkSize = $maxChunkSize;
$result->chunkCount = $chunkCount;
$result->compressedPackSize = $compressedPackSize;
$result->sha256 = $sha256sum;
return $result;
}
protected function decodePayload() : void{
$this->packId = $this->getString();
$this->maxChunkSize = $this->getLInt();