mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
NetworkInventoryAction: Allow returning null to ignore weird transactions
Revert "Return null on unmatched inventory action and log details" This reverts commit fd7fb10223f7373919701008970e7e87abc2654e.
This commit is contained in:
parent
78cf875080
commit
2cb81b5f8d
@ -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){
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user