mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-09 07:20:15 +00:00
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:
parent
57219abc9d
commit
67affcea32
@ -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;
|
||||
|
@ -26,9 +26,6 @@ namespace pocketmine\inventory;
|
||||
use pocketmine\event\inventory\InventoryOpenEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
|
||||
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\ContainerIds;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Utils;
|
||||
use function array_slice;
|
||||
@ -414,16 +411,8 @@ abstract class BaseInventory implements Inventory{
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new InventoryContentPacket();
|
||||
$pk->items = $this->getContents(true);
|
||||
|
||||
foreach($target as $player){
|
||||
if(($id = $player->getWindowId($this)) === ContainerIds::NONE){
|
||||
$this->close($player);
|
||||
continue;
|
||||
}
|
||||
$pk->windowId = $id;
|
||||
$player->sendDataPacket($pk);
|
||||
$player->getNetworkSession()->syncInventoryContents($this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -436,17 +425,8 @@ abstract class BaseInventory implements Inventory{
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new InventorySlotPacket();
|
||||
$pk->inventorySlot = $index;
|
||||
$pk->item = $this->getItem($index);
|
||||
|
||||
foreach($target as $player){
|
||||
if(($id = $player->getWindowId($this)) === ContainerIds::NONE){
|
||||
$this->close($player);
|
||||
continue;
|
||||
}
|
||||
$pk->windowId = $id;
|
||||
$player->sendDataPacket($pk);
|
||||
$player->getNetworkSession()->syncInventorySlot($this, $index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ use pocketmine\event\server\DataPacketReceiveEvent;
|
||||
use pocketmine\event\server\DataPacketSendEvent;
|
||||
use pocketmine\form\Form;
|
||||
use pocketmine\GameMode;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\BadPacketException;
|
||||
use pocketmine\network\mcpe\handler\DeathSessionHandler;
|
||||
@ -45,6 +46,8 @@ use pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
|
||||
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
|
||||
use pocketmine\network\mcpe\protocol\ClientboundPacket;
|
||||
use pocketmine\network\mcpe\protocol\DisconnectPacket;
|
||||
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
|
||||
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
|
||||
use pocketmine\network\mcpe\protocol\MobEffectPacket;
|
||||
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
|
||||
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
|
||||
@ -60,6 +63,7 @@ use pocketmine\network\mcpe\protocol\TransferPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\CommandData;
|
||||
use pocketmine\network\mcpe\protocol\types\CommandEnum;
|
||||
use pocketmine\network\mcpe\protocol\types\CommandParameter;
|
||||
use pocketmine\network\mcpe\protocol\types\ContainerIds;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
||||
use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;
|
||||
use pocketmine\network\NetworkInterface;
|
||||
@ -792,6 +796,27 @@ class NetworkSession{
|
||||
|
||||
}
|
||||
|
||||
public function syncInventorySlot(Inventory $inventory, int $slot) : void{
|
||||
$windowId = $this->player->getWindowId($inventory);
|
||||
if($windowId !== ContainerIds::NONE){
|
||||
$pk = new InventorySlotPacket();
|
||||
$pk->inventorySlot = $slot;
|
||||
$pk->item = $inventory->getItem($slot);
|
||||
$pk->windowId = $windowId;
|
||||
$this->sendDataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
public function syncInventoryContents(Inventory $inventory) : void{
|
||||
$windowId = $this->player->getWindowId($inventory);
|
||||
if($windowId !== ContainerIds::NONE){
|
||||
$pk = new InventoryContentPacket();
|
||||
$pk->items = $inventory->getContents(true);
|
||||
$pk->windowId = $windowId;
|
||||
$this->sendDataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
public function tick() : bool{
|
||||
if($this->handler instanceof LoginSessionHandler){
|
||||
if(time() >= $this->connectTime + 10){
|
||||
|
Loading…
x
Reference in New Issue
Block a user