1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #2595 from AnotherMC/master

Fix ghost blocks
This commit is contained in:
TheBusyBiscuit 2020-12-10 21:51:00 +01:00 committed by GitHub
commit 5aa5ca1aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,10 +38,11 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
/**
* The {@link BlockListener} is responsible for listening to the {@link BlockPlaceEvent}
* and {@link BlockBreakEvent}.
*
*
* @author TheBusyBiscuit
* @author Linox
*
* @author Patbox
*
* @see BlockPlaceHandler
* @see BlockBreakHandler
* @see ToolUseHandler
@ -58,7 +59,20 @@ public class BlockListener implements Listener {
// This prevents Players from placing a block where another block already exists
// While this can cause ghost blocks it also prevents them from replacing grass
// or saplings etc...
if (BlockStorage.hasBlockInfo(e.getBlock())) {
Block block = e.getBlock();
if (e.getBlockReplacedState().getType().isAir()) {
SlimefunItem sfItem = BlockStorage.check(block);
if (sfItem != null) {
for (ItemStack item : sfItem.getDrops()) {
if (item != null && !item.getType().isAir()) {
block.getWorld().dropItemNaturally(block.getLocation(), item);
}
}
BlockStorage.clearBlockInfo(block);
}
} else if (BlockStorage.hasBlockInfo(e.getBlock())) {
e.setCancelled(true);
}
}
@ -170,7 +184,7 @@ public class BlockListener implements Listener {
* This method checks for a sensitive {@link Block}.
* Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken
* when the block beneath is broken as well.
*
*
* @param p
* The {@link Player} who broke this {@link Block}
* @param b