diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8b0944f33..2d0a5b3de 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2210,15 +2210,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var InventoryAction[] $actions */ $actions = []; foreach($packet->actions as $networkInventoryAction){ - $action = $networkInventoryAction->createInventoryAction($this); - - if($action === null){ - $this->server->getLogger()->debug("Unmatched inventory action from " . $this->getName() . ": " . json_encode($networkInventoryAction)); + try{ + $action = $networkInventoryAction->createInventoryAction($this); + if($action !== null){ + $actions[] = $action; + } + }catch(\Throwable $e){ + $this->server->getLogger()->debug("Unhandled inventory action from " . $this->getName() . ": " . $e->getMessage()); $this->sendAllInventories(); return false; } - - $actions[] = $action; } if($packet->isCraftingPart){ diff --git a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php index 18663b037..27ed44d02 100644 --- a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php +++ b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php @@ -170,13 +170,13 @@ class NetworkInventoryAction{ return new SlotChangeAction($window, $this->inventorySlot, $this->oldItem, $this->newItem); } - return null; + throw new \InvalidStateException("Player " . $player->getName() . " has no open container with window ID $this->windowId"); case self::SOURCE_WORLD: - if($this->inventorySlot === self::ACTION_MAGIC_SLOT_DROP_ITEM){ - return new DropItemAction($this->oldItem, $this->newItem); + if($this->inventorySlot !== self::ACTION_MAGIC_SLOT_DROP_ITEM){ + throw new \UnexpectedValueException("Only expecting drop-item world actions from the client!"); } - return null; + return new DropItemAction($this->oldItem, $this->newItem); case self::SOURCE_CREATIVE: switch($this->inventorySlot){ case self::ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM: @@ -186,7 +186,7 @@ class NetworkInventoryAction{ $type = CreativeInventoryAction::TYPE_CREATE_ITEM; break; default: - return null; + throw new \UnexpectedValueException("Unexpected creative action type $this->inventorySlot"); } @@ -210,16 +210,16 @@ class NetworkInventoryAction{ //DROP_CONTENTS doesn't bother telling us what slot the item is in, so we find it ourselves $inventorySlot = $window->first($this->oldItem, true); if($inventorySlot === -1){ - return null; + throw new \InvalidStateException("Fake container " . get_class($window) . " for " . $player->getName() . " does not contain $this->oldItem"); } return new SlotChangeAction($window, $inventorySlot, $this->oldItem, $this->newItem); } //TODO: more stuff - return null; + throw new \UnexpectedValueException("Player " . $player->getName() . " has no open container with window ID $this->windowId"); + default: + throw new \UnexpectedValueException("Unknown inventory source type $this->sourceType"); } - - return null; } } \ No newline at end of file