From 9fba3f6b057bca3dc947ad9b7d8de113fa66a49c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:16:25 +0100 Subject: [PATCH 1/2] [CI skip] Update dependency org.mockito:mockito-core to v5.9.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From bcfbd3a598b512cec1fa36721ff33fea82c892b1 Mon Sep 17 00:00:00 2001 From: J3fftw <44972470+J3fftw1@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:26:33 +0100 Subject: [PATCH 2/2] fix slimefun block turning into a vanilla block if there are viewers (#4101) --- .../slimefun4/implementation/listeners/BlockListener.java | 7 ++++--- .../listeners/TestSlimefunItemInteractListener.java | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) 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();