diff --git a/src/block/inventory/AnvilInventory.php b/src/block/inventory/AnvilInventory.php index 2e875d3ff..1def8f913 100644 --- a/src/block/inventory/AnvilInventory.php +++ b/src/block/inventory/AnvilInventory.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\block\inventory; use pocketmine\inventory\SimpleInventory; -use pocketmine\player\Player; +use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -class AnvilInventory extends SimpleInventory implements BlockInventory{ +class AnvilInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ use BlockInventoryTrait; public const SLOT_INPUT = 0; @@ -37,13 +37,4 @@ class AnvilInventory extends SimpleInventory implements BlockInventory{ $this->holder = $holder; parent::__construct(2); } - - public function onClose(Player $who) : void{ - parent::onClose($who); - - foreach($this->getContents() as $item){ - $who->dropItem($item); - } - $this->clearAll(); - } } diff --git a/src/block/inventory/CraftingTableInventory.php b/src/block/inventory/CraftingTableInventory.php index 493e5dec0..a885df4be 100644 --- a/src/block/inventory/CraftingTableInventory.php +++ b/src/block/inventory/CraftingTableInventory.php @@ -24,23 +24,14 @@ declare(strict_types=1); namespace pocketmine\block\inventory; use pocketmine\crafting\CraftingGrid; -use pocketmine\player\Player; +use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -final class CraftingTableInventory extends CraftingGrid implements BlockInventory{ +final class CraftingTableInventory extends CraftingGrid implements BlockInventory, TemporaryInventory{ use BlockInventoryTrait; public function __construct(Position $holder){ $this->holder = $holder; parent::__construct(CraftingGrid::SIZE_BIG); } - - public function onClose(Player $who) : void{ - parent::onClose($who); - - foreach($this->getContents() as $item){ - $who->dropItem($item); - } - $this->clearAll(); - } } \ No newline at end of file diff --git a/src/block/inventory/EnchantInventory.php b/src/block/inventory/EnchantInventory.php index aafc90caf..91bfcab5e 100644 --- a/src/block/inventory/EnchantInventory.php +++ b/src/block/inventory/EnchantInventory.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\block\inventory; use pocketmine\inventory\SimpleInventory; -use pocketmine\player\Player; +use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -class EnchantInventory extends SimpleInventory implements BlockInventory{ +class EnchantInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ use BlockInventoryTrait; public const SLOT_INPUT = 0; @@ -37,13 +37,4 @@ class EnchantInventory extends SimpleInventory implements BlockInventory{ $this->holder = $holder; parent::__construct(2); } - - public function onClose(Player $who) : void{ - parent::onClose($who); - - foreach($this->getContents() as $item){ - $who->dropItem($item); - } - $this->clearAll(); - } } diff --git a/src/block/inventory/LoomInventory.php b/src/block/inventory/LoomInventory.php index 24830329a..8e1a763f1 100644 --- a/src/block/inventory/LoomInventory.php +++ b/src/block/inventory/LoomInventory.php @@ -24,10 +24,11 @@ declare(strict_types=1); namespace pocketmine\block\inventory; use pocketmine\inventory\SimpleInventory; +use pocketmine\inventory\TemporaryInventory; use pocketmine\player\Player; use pocketmine\world\Position; -final class LoomInventory extends SimpleInventory implements BlockInventory{ +final class LoomInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ use BlockInventoryTrait; public const SLOT_BANNER = 0; @@ -38,13 +39,4 @@ final class LoomInventory extends SimpleInventory implements BlockInventory{ $this->holder = $holder; parent::__construct($size); } - - public function onClose(Player $who) : void{ - parent::onClose($who); - - foreach($this->getContents() as $item){ - $who->dropItem($item); - } - $this->clearAll(); - } } diff --git a/src/inventory/PlayerCraftingInventory.php b/src/inventory/PlayerCraftingInventory.php index 300346476..d3a817434 100644 --- a/src/inventory/PlayerCraftingInventory.php +++ b/src/inventory/PlayerCraftingInventory.php @@ -26,7 +26,7 @@ namespace pocketmine\inventory; use pocketmine\crafting\CraftingGrid; use pocketmine\player\Player; -final class PlayerCraftingInventory extends CraftingGrid{ +final class PlayerCraftingInventory extends CraftingGrid implements TemporaryInventory{ public function __construct(private Player $holder){ parent::__construct(CraftingGrid::SIZE_SMALL); diff --git a/src/inventory/PlayerCursorInventory.php b/src/inventory/PlayerCursorInventory.php index 9cd948c58..7c219fd00 100644 --- a/src/inventory/PlayerCursorInventory.php +++ b/src/inventory/PlayerCursorInventory.php @@ -25,7 +25,7 @@ namespace pocketmine\inventory; use pocketmine\player\Player; -class PlayerCursorInventory extends SimpleInventory{ +class PlayerCursorInventory extends SimpleInventory implements TemporaryInventory{ /** @var Player */ protected $holder; diff --git a/src/player/Player.php b/src/player/Player.php index 7f43296b1..b1a4034ba 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -77,6 +77,7 @@ use pocketmine\inventory\CallbackInventoryListener; use pocketmine\inventory\Inventory; use pocketmine\inventory\PlayerCraftingInventory; use pocketmine\inventory\PlayerCursorInventory; +use pocketmine\inventory\TemporaryInventory; use pocketmine\inventory\transaction\action\DropItemAction; use pocketmine\inventory\transaction\InventoryTransaction; use pocketmine\inventory\transaction\TransactionBuilderInventory; @@ -2322,8 +2323,10 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ * inventory. */ public function doCloseInventory() : void{ - /** @var Inventory[] $inventories */ $inventories = [$this->craftingGrid, $this->cursorInventory]; + if($this->currentWindow instanceof TemporaryInventory){ + $inventories[] = $this->currentWindow; + } $transaction = new InventoryTransaction($this); $mainInventoryTransactionBuilder = new TransactionBuilderInventory($this->inventory);