move more packet logic to net session

it seems like net session is turning into a giant dumping ground for sending API ... this needs to be cleaned up somehow.
This commit is contained in:
Dylan K. Taylor
2019-05-18 20:00:05 +01:00
parent 57219abc9d
commit 67affcea32
3 changed files with 31 additions and 33 deletions

View File

@ -25,8 +25,6 @@ namespace pocketmine\inventory;
use pocketmine\entity\Living;
use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\Player;
use function array_merge;
@ -90,14 +88,11 @@ class ArmorInventory extends BaseInventory{
/** @var Player[] $target */
if(($k = array_search($this->holder, $target, true)) !== false){
$pk = new InventorySlotPacket();
$pk->windowId = $target[$k]->getWindowId($this);
$pk->inventorySlot = $index;
$pk->item = $this->getItem($index);
$target[$k]->sendDataPacket($pk);
$target[$k]->getNetworkSession()->syncInventorySlot($this, $index);
unset($target[$k]);
}
if(!empty($target)){
//TODO: this should be handled by change listeners
$pk = new MobArmorEquipmentPacket();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->slots = $this->getContents(true);
@ -113,13 +108,11 @@ class ArmorInventory extends BaseInventory{
$armor = $this->getContents(true);
if(($k = array_search($this->holder, $target, true)) !== false){
$pk = new InventoryContentPacket();
$pk->windowId = $target[$k]->getWindowId($this);
$pk->items = $armor;
$target[$k]->sendDataPacket($pk);
$target[$k]->getNetworkSession()->syncInventoryContents($this);
unset($target[$k]);
}
if(!empty($target)){
//TODO: this should be handled by change listeners
$pk = new MobArmorEquipmentPacket();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->slots = $armor;