From 5a4fbc6f5aae730269c7d9b1e72aa00a10245eb8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 12 Aug 2017 19:11:57 +0100 Subject: [PATCH] Handle exception for crafting and resend inventories --- src/pocketmine/Player.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 3adcd3502a..86c27372c1 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2149,6 +2149,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } + protected function sendAllInventories(){ + foreach($this->windowIndex as $id => $inventory){ + $inventory->sendContents($this); + if($inventory instanceof PlayerInventory){ + $inventory->sendArmorContents($this); + $inventory->sendHotbar(); + } + } + } + /** * Don't expect much from this handler. Most of it is roughly hacked and duct-taped together. * @@ -2161,7 +2171,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $transaction = new SimpleInventoryTransaction($this); foreach($packet->actions as $action){ - $transaction->addAction($action); + try{ + $transaction->addAction($action); + }catch(\InvalidStateException $e){ + $this->server->getLogger()->debug($e->getMessage()); + $this->sendAllInventories(); + return false; + } } if(!$transaction->execute()){ @@ -2183,13 +2199,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if(count($packet->actions) > 0){ $this->server->getLogger()->debug("Expected 0 actions for mismatch, got " . count($packet->actions) . ", " . json_encode($packet->actions)); } - foreach($this->windowIndex as $id => $inventory){ - $inventory->sendContents($this); - if($inventory instanceof PlayerInventory){ - $inventory->sendArmorContents($this); - } - } - $this->inventory->sendHotbar(); + $this->sendAllInventories(); + return true; case InventoryTransactionPacket::TYPE_USE_ITEM: $blockVector = new Vector3($packet->transactionData->x, $packet->transactionData->y, $packet->transactionData->z);