Player: move sendAllInventories() to network layer

This commit is contained in:
Dylan K. Taylor 2019-05-26 15:58:03 +01:00
parent 85718e2750
commit 33d1203bfd
4 changed files with 16 additions and 9 deletions

View File

@ -2594,7 +2594,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$this->sendData($this->getViewers()); $this->sendData($this->getViewers());
$this->networkSession->syncAdventureSettings($this); $this->networkSession->syncAdventureSettings($this);
$this->sendAllInventories(); $this->networkSession->syncAllInventoryContents();
$this->spawnToAll(); $this->spawnToAll();
$this->scheduleUpdate(); $this->scheduleUpdate();
@ -2878,10 +2878,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
} }
} }
public function sendAllInventories(){ /**
foreach($this->windowIndex as $networkId => $inventory){ * @return Inventory[]
$inventory->sendContents($this); */
} public function getAllWindows() : array{
return $this->windowIndex;
} }
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{ public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{

View File

@ -819,6 +819,12 @@ class NetworkSession{
} }
} }
public function syncAllInventoryContents() : void{
foreach($this->player->getAllWindows() as $inventory){
$this->syncInventoryContents($inventory);
}
}
public function syncInventoryData(Inventory $inventory, int $propertyId, int $value) : void{ public function syncInventoryData(Inventory $inventory, int $propertyId, int $value) : void{
$windowId = $this->player->getWindowId($inventory); $windowId = $this->player->getWindowId($inventory);
if($windowId !== ContainerIds::NONE){ if($windowId !== ContainerIds::NONE){

View File

@ -158,7 +158,7 @@ class InGameSessionHandler extends SessionHandler{
public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{
if($this->player->isSpectator()){ if($this->player->isSpectator()){
$this->player->sendAllInventories(); $this->session->syncAllInventoryContents();
return true; return true;
} }
@ -167,7 +167,7 @@ class InGameSessionHandler extends SessionHandler{
if($packet->trData instanceof NormalTransactionData){ if($packet->trData instanceof NormalTransactionData){
$result = $this->handleNormalTransaction($packet->trData); $result = $this->handleNormalTransaction($packet->trData);
}elseif($packet->trData instanceof MismatchTransactionData){ }elseif($packet->trData instanceof MismatchTransactionData){
$this->player->sendAllInventories(); $this->session->syncAllInventoryContents();
$result = true; $result = true;
}elseif($packet->trData instanceof UseItemTransactionData){ }elseif($packet->trData instanceof UseItemTransactionData){
$result = $this->handleUseItemTransaction($packet->trData); $result = $this->handleUseItemTransaction($packet->trData);
@ -178,7 +178,7 @@ class InGameSessionHandler extends SessionHandler{
} }
if(!$result){ if(!$result){
$this->player->sendAllInventories(); $this->session->syncAllInventoryContents();
} }
return $result; return $result;
} }

View File

@ -91,7 +91,7 @@ class PreSpawnSessionHandler extends SessionHandler{
$this->player->sendPotionEffects($this->player); $this->player->sendPotionEffects($this->player);
$this->player->sendData($this->player); $this->player->sendData($this->player);
$this->player->sendAllInventories(); $this->session->syncAllInventoryContents();
$this->player->getInventory()->sendCreativeContents(); $this->player->getInventory()->sendCreativeContents();
$this->player->getInventory()->sendHeldItem($this->player); $this->player->getInventory()->sendHeldItem($this->player);
$this->session->queueCompressed($this->server->getCraftingManager()->getCraftingDataPacket()); $this->session->queueCompressed($this->server->getCraftingManager()->getCraftingDataPacket());