mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-23 05:54:36 +00:00
PacketStream: added fromPackets() sugar
This commit is contained in:
parent
3415edf600
commit
ce61c6e0fd
@ -1492,10 +1492,7 @@ class Server{
|
||||
}
|
||||
$recipients = $ev->getTargets();
|
||||
|
||||
$stream = new PacketStream();
|
||||
foreach($ev->getPackets() as $packet){
|
||||
$stream->putPacket($packet);
|
||||
}
|
||||
$stream = PacketStream::fromPackets(...$ev->getPackets());
|
||||
|
||||
if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->getBuffer()) < NetworkCompression::$THRESHOLD){
|
||||
foreach($recipients as $target){
|
||||
|
@ -115,11 +115,8 @@ class CraftingManager{
|
||||
$pk->addFurnaceRecipe($recipe);
|
||||
}
|
||||
|
||||
$batch = new PacketStream();
|
||||
$batch->putPacket($pk);
|
||||
|
||||
$this->craftingDataCache = new CompressBatchPromise();
|
||||
$this->craftingDataCache->resolve(NetworkCompression::compress($batch->getBuffer()));
|
||||
$this->craftingDataCache->resolve(NetworkCompression::compress(PacketStream::fromPackets($pk)->getBuffer()));
|
||||
|
||||
Timings::$craftingDataCacheRebuildTimer->stopTiming();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user