InventoryManager: fixed crashes when setting contents or slots of inventories during InventoryCloseEvent (and other similar logic)

This commit is contained in:
Dylan K. Taylor 2023-03-24 13:29:33 +00:00
parent f978c1e9a0
commit 58d5126ada
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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{