mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
fix slimefun block turning into a vanilla block if there are viewers (#4101)
This commit is contained in:
parent
9fba3f6b05
commit
bcfbd3a598
@ -226,9 +226,10 @@ public class BlockListener implements Listener {
|
|||||||
// The main fix is in SlimefunItemInteractListener preventing opening to begin with
|
// The main fix is in SlimefunItemInteractListener preventing opening to begin with
|
||||||
// Close the inventory for all viewers of this block
|
// Close the inventory for all viewers of this block
|
||||||
BlockMenu inventory = BlockStorage.getInventory(e.getBlock());
|
BlockMenu inventory = BlockStorage.getInventory(e.getBlock());
|
||||||
// TODO(future): Remove this check when MockBukkit supports viewers
|
if (inventory != null) {
|
||||||
if (inventory != null && !Slimefun.instance().isUnitTest()) {
|
for (HumanEntity human : new ArrayList<>(inventory.toInventory().getViewers())) {
|
||||||
inventory.toInventory().getViewers().forEach(HumanEntity::closeInventory);
|
human.closeInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Remove the block data
|
// Remove the block data
|
||||||
BlockStorage.clearBlockInfo(e.getBlock());
|
BlockStorage.clearBlockInfo(e.getBlock());
|
||||||
|
@ -116,7 +116,9 @@ class TestSlimefunItemInteractListener {
|
|||||||
// TODO: Create an event for open inventory so this isn't guess work
|
// TODO: Create an event for open inventory so this isn't guess work
|
||||||
Assertions.assertTrue(BlockMenuPreset.isInventory(electricFurnace.getId()));
|
Assertions.assertTrue(BlockMenuPreset.isInventory(electricFurnace.getId()));
|
||||||
Assertions.assertTrue(BlockStorage.getStorage(block.getWorld()).hasInventory(block.getLocation()));
|
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
|
// Break the block
|
||||||
BlockBreakEvent blockBreakEvent = new BlockBreakEvent(block, player);
|
BlockBreakEvent blockBreakEvent = new BlockBreakEvent(block, player);
|
||||||
@ -129,6 +131,9 @@ class TestSlimefunItemInteractListener {
|
|||||||
// Assert the block is queued for removal
|
// Assert the block is queued for removal
|
||||||
Assertions.assertTrue(Slimefun.getTickerTask().isDeletedSoon(block.getLocation()));
|
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
|
// Clear event queue since we'll be running duplicate events
|
||||||
server.getPluginManager().clearEvents();
|
server.getPluginManager().clearEvents();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user