mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
PacketStream: added fromPackets() sugar
This commit is contained in:
@ -57,10 +57,7 @@ class ChunkRequestTask extends AsyncTask{
|
||||
$pk->chunkZ = $this->chunkZ;
|
||||
$pk->data = $this->chunk;
|
||||
|
||||
$stream = new PacketStream();
|
||||
$stream->putPacket($pk);
|
||||
|
||||
$this->setResult(NetworkCompression::compress($stream->getBuffer(), $this->compressionLevel));
|
||||
$this->setResult(NetworkCompression::compress(PacketStream::fromPackets($pk)->getBuffer(), $this->compressionLevel));
|
||||
}
|
||||
|
||||
public function onError() : void{
|
||||
|
@ -43,4 +43,19 @@ class PacketStream extends NetworkBinaryStream{
|
||||
public function getPacket() : Packet{
|
||||
return PacketPool::getPacket($this->getString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a packet batch from the given list of packets.
|
||||
*
|
||||
* @param Packet ...$packets
|
||||
*
|
||||
* @return PacketStream
|
||||
*/
|
||||
public static function fromPackets(Packet ...$packets) : self{
|
||||
$result = new self();
|
||||
foreach($packets as $packet){
|
||||
$result->putPacket($packet);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user