mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-23 14:04:38 +00:00
PacketStream: added fromPackets() sugar
This commit is contained in:
parent
3415edf600
commit
ce61c6e0fd
@ -1492,10 +1492,7 @@ class Server{
|
|||||||
}
|
}
|
||||||
$recipients = $ev->getTargets();
|
$recipients = $ev->getTargets();
|
||||||
|
|
||||||
$stream = new PacketStream();
|
$stream = PacketStream::fromPackets(...$ev->getPackets());
|
||||||
foreach($ev->getPackets() as $packet){
|
|
||||||
$stream->putPacket($packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->getBuffer()) < NetworkCompression::$THRESHOLD){
|
if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->getBuffer()) < NetworkCompression::$THRESHOLD){
|
||||||
foreach($recipients as $target){
|
foreach($recipients as $target){
|
||||||
|
@ -115,11 +115,8 @@ class CraftingManager{
|
|||||||
$pk->addFurnaceRecipe($recipe);
|
$pk->addFurnaceRecipe($recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
$batch = new PacketStream();
|
|
||||||
$batch->putPacket($pk);
|
|
||||||
|
|
||||||
$this->craftingDataCache = new CompressBatchPromise();
|
$this->craftingDataCache = new CompressBatchPromise();
|
||||||
$this->craftingDataCache->resolve(NetworkCompression::compress($batch->getBuffer()));
|
$this->craftingDataCache->resolve(NetworkCompression::compress(PacketStream::fromPackets($pk)->getBuffer()));
|
||||||
|
|
||||||
Timings::$craftingDataCacheRebuildTimer->stopTiming();
|
Timings::$craftingDataCacheRebuildTimer->stopTiming();
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,7 @@ class ChunkRequestTask extends AsyncTask{
|
|||||||
$pk->chunkZ = $this->chunkZ;
|
$pk->chunkZ = $this->chunkZ;
|
||||||
$pk->data = $this->chunk;
|
$pk->data = $this->chunk;
|
||||||
|
|
||||||
$stream = new PacketStream();
|
$this->setResult(NetworkCompression::compress(PacketStream::fromPackets($pk)->getBuffer(), $this->compressionLevel));
|
||||||
$stream->putPacket($pk);
|
|
||||||
|
|
||||||
$this->setResult(NetworkCompression::compress($stream->getBuffer(), $this->compressionLevel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onError() : void{
|
public function onError() : void{
|
||||||
|
@ -43,4 +43,19 @@ class PacketStream extends NetworkBinaryStream{
|
|||||||
public function getPacket() : Packet{
|
public function getPacket() : Packet{
|
||||||
return PacketPool::getPacket($this->getString());
|
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