Kill BatchPacket, clean up batching related things

DataPacketSendEvent and DataPacketReceiveEvent will no longer capture BatchPackets
In most places strings are now used instead of DataPackets, to remove limitations on what data can be sent to a network interface
Removed CraftingManager's cyclic dependency on Server

There is a lot more work to do aside from this, but this commit is intended to clean up what is necessary to fix the handling of BatchPacket.
This commit is contained in:
Dylan K. Taylor
2018-07-19 14:52:34 +01:00
parent 85647c03bf
commit bdd9a7eb52
15 changed files with 152 additions and 256 deletions

View File

@ -25,9 +25,9 @@ namespace pocketmine\inventory;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\NetworkCompression;
use pocketmine\network\mcpe\PacketStream;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\Server;
use pocketmine\timings\Timings;
class CraftingManager{
@ -38,7 +38,7 @@ class CraftingManager{
/** @var FurnaceRecipe[] */
protected $furnaceRecipes = [];
/** @var BatchPacket */
/** @var string */
private $craftingDataCache;
public function __construct(){
@ -102,21 +102,19 @@ class CraftingManager{
$pk->encode();
$batch = new BatchPacket();
$batch->addPacket($pk);
$batch->setCompressionLevel(Server::getInstance()->networkCompressionLevel);
$batch->encode();
$batch = new PacketStream();
$batch->putPacket($pk);
$this->craftingDataCache = $batch;
$this->craftingDataCache = NetworkCompression::compress($batch->buffer);
Timings::$craftingDataCacheRebuildTimer->stopTiming();
}
/**
* Returns a pre-compressed CraftingDataPacket for sending to players. Rebuilds the cache if it is not found.
*
* @return BatchPacket
* @return string
*/
public function getCraftingDataPacket() : BatchPacket{
public function getCraftingDataPacket() : string{
if($this->craftingDataCache === null){
$this->buildCraftingDataCache();
}