1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 11:15:51 +00:00

fix slimefun block turning into a vanilla block if there are viewers (#4101)

This commit is contained in:
J3fftw 2024-01-17 17:26:33 +01:00 committed by GitHub
parent 9fba3f6b05
commit bcfbd3a598
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -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());

View File

@ -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();