mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 01:16:15 +00:00
InventoryTransaction: Remove action shuffling
we used to have this to prevent dependence on client ordering, and make ordering consistently not work. However, since the introduction of the ItemStackRequest protocol, we don't expect to see client actions in the wrong order anymore, so this shouldn't be needed anymore. closes #6701
This commit is contained in:
@ -95,10 +95,13 @@ class InventoryTransaction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an **unordered** set of actions involved in this transaction.
|
* Returns a set of actions involved in this transaction.
|
||||||
*
|
*
|
||||||
* WARNING: This system is **explicitly designed NOT to care about ordering**. Any order seen in this set has NO
|
* Note: This system is designed to care only about item balances. While you can usually assume that the actions
|
||||||
* significance and should not be relied on.
|
* are provided in the correct order, it will still successfully complete transactions whose actions are provided in
|
||||||
|
* the "wrong" order, as long as the transaction balances.
|
||||||
|
* For example, you may see that an action setting a slot to a particular item may appear before the action that
|
||||||
|
* removes that item from its original slot. While unintuitive, this is still valid.
|
||||||
*
|
*
|
||||||
* @return InventoryAction[]
|
* @return InventoryAction[]
|
||||||
* @phpstan-return array<int, InventoryAction>
|
* @phpstan-return array<int, InventoryAction>
|
||||||
@ -119,19 +122,6 @@ class InventoryTransaction{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shuffles actions in the transaction to prevent external things relying on any implicit ordering.
|
|
||||||
*/
|
|
||||||
private function shuffleActions() : void{
|
|
||||||
$keys = array_keys($this->actions);
|
|
||||||
shuffle($keys);
|
|
||||||
$actions = [];
|
|
||||||
foreach($keys as $key){
|
|
||||||
$actions[$key] = $this->actions[$key];
|
|
||||||
}
|
|
||||||
$this->actions = $actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Item[] $needItems
|
* @param Item[] $needItems
|
||||||
* @param Item[] $haveItems
|
* @param Item[] $haveItems
|
||||||
@ -308,8 +298,6 @@ class InventoryTransaction{
|
|||||||
throw new TransactionValidationException("Transaction has already been executed");
|
throw new TransactionValidationException("Transaction has already been executed");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->shuffleActions();
|
|
||||||
|
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
if(!$this->callExecuteEvent()){
|
if(!$this->callExecuteEvent()){
|
||||||
|
Reference in New Issue
Block a user