diff --git a/pom.xml b/pom.xml index a7b6c91df6b..48e7d9db95f 100644 --- a/pom.xml +++ b/pom.xml @@ -383,7 +383,7 @@ org.mockito mockito-core - 5.8.0 + 5.9.0 test diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index b4dc7c38aee..12937e45a4d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -226,9 +226,10 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List // The main fix is in SlimefunItemInteractListener preventing opening to begin with // Close the inventory for all viewers of this block BlockMenu inventory = BlockStorage.getInventory(e.getBlock()); - // TODO(future): Remove this check when MockBukkit supports viewers - if (inventory != null && !Slimefun.instance().isUnitTest()) { - inventory.toInventory().getViewers().forEach(HumanEntity::closeInventory); + if (inventory != null) { + for (HumanEntity human : new ArrayList<>(inventory.toInventory().getViewers())) { + human.closeInventory(); + } } // Remove the block data BlockStorage.clearBlockInfo(e.getBlock()); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TestSlimefunItemInteractListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TestSlimefunItemInteractListener.java index 08b506e8c69..cc33e3750ab 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TestSlimefunItemInteractListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TestSlimefunItemInteractListener.java @@ -116,7 +116,9 @@ void testCannotOpenInvOfBrokenBlock() { // TODO: Create an event for open inventory so this isn't guess work Assertions.assertTrue(BlockMenuPreset.isInventory(electricFurnace.getId())); Assertions.assertTrue(BlockStorage.getStorage(block.getWorld()).hasInventory(block.getLocation())); - // TODO(future): Check viewers - MockBukkit does not implement this today + + // Assert player has the inventory open + Assertions.assertEquals(1, BlockStorage.getInventory(block).toInventory().getViewers().size()); // Break the block BlockBreakEvent blockBreakEvent = new BlockBreakEvent(block, player); @@ -129,6 +131,9 @@ void testCannotOpenInvOfBrokenBlock() { // Assert the block is queued for removal Assertions.assertTrue(Slimefun.getTickerTask().isDeletedSoon(block.getLocation())); + // Assert that the inventory was closed + Assertions.assertEquals(0, BlockStorage.getInventory(block).toInventory().getViewers().size()); + // Clear event queue since we'll be running duplicate events server.getPluginManager().clearEvents();