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] 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 b4dc7c38a..12937e45a 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 @@ public class BlockListener implements Listener { // 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 08b506e8c..cc33e3750 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 @@ class TestSlimefunItemInteractListener { // 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 @@ class TestSlimefunItemInteractListener { // 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();