mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
InventoryManager: fixed crashes when setting contents or slots of inventories during InventoryCloseEvent (and other similar logic)
This commit is contained in:
parent
f978c1e9a0
commit
58d5126ada
@ -407,8 +407,13 @@ class InventoryManager{
|
||||
}
|
||||
|
||||
public function onSlotChange(Inventory $inventory, int $slot) : void{
|
||||
$inventoryEntry = $this->inventories[spl_object_id($inventory)] ?? null;
|
||||
if($inventoryEntry === null){
|
||||
//this can happen when an inventory changed during InventoryCloseEvent, or when a temporary inventory
|
||||
//is cleared before removal.
|
||||
return;
|
||||
}
|
||||
$currentItem = TypeConverter::getInstance()->coreItemStackToNet($inventory->getItem($slot));
|
||||
$inventoryEntry = $this->inventories[spl_object_id($inventory)];
|
||||
$clientSideItem = $inventoryEntry->predictions[$slot] ?? null;
|
||||
if($clientSideItem === null || !$clientSideItem->equals($currentItem)){
|
||||
//no prediction or incorrect - do not associate this with the currently active itemstack request
|
||||
@ -469,7 +474,12 @@ class InventoryManager{
|
||||
}
|
||||
|
||||
public function syncContents(Inventory $inventory) : void{
|
||||
$entry = $this->inventories[spl_object_id($inventory)];
|
||||
$entry = $this->inventories[spl_object_id($inventory)] ?? null;
|
||||
if($entry === null){
|
||||
//this can happen when an inventory changed during InventoryCloseEvent, or when a temporary inventory
|
||||
//is cleared before removal.
|
||||
return;
|
||||
}
|
||||
if($entry->complexSlotMap !== null){
|
||||
$windowId = ContainerIds::UI;
|
||||
}else{
|
||||
|
Loading…
x
Reference in New Issue
Block a user