1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Fix discrepancies between block storage data and server events

1) Stop falling blocks from falling into a spot where an SF machine was just mined. Typically the blockstorage does not update fast enough, causing machine duplication. The event is cancelled, and the falling entities drop as items instead of disappearing.

2) Nearly the same as above, but with pistons pushing solid blocks into air blocks which had a slimefun machine in it a moment prior. Typically the blockstorage does not update fast enough, causing machine duplication.
This commit is contained in:
VoidAngel 2018-02-21 09:50:59 -08:00 committed by GitHub
parent c33c8e065e
commit 1e5d7e0d2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,14 +16,17 @@ import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
public class BlockListener implements Listener { public class BlockListener implements Listener {
@ -31,6 +34,19 @@ public class BlockListener implements Listener {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
@EventHandler
public void onBlockFall(EntityChangeBlockEvent event) {
if (event.getEntity() instanceof FallingBlock) {
if (BlockStorage.hasBlockInfo(event.getBlock())) {
event.setCancelled(true);
FallingBlock fb = (FallingBlock) event.getEntity();
if (fb.getDropItem()) {
fb.getWorld().dropItemNaturally(fb.getLocation(), new ItemStack(fb.getMaterial(), 1, fb.getBlockData()));
}
}
}
}
@EventHandler @EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) { public void onPistonExtend(BlockPistonExtendEvent e) {
for (Block b : e.getBlocks()) { for (Block b : e.getBlocks()) {
@ -38,6 +54,10 @@ public class BlockListener implements Listener {
e.setCancelled(true); e.setCancelled(true);
return; return;
} }
else if(b.getRelative(e.getDirection()) == null && BlockStorage.hasBlockInfo(b.getRelative(e.getDirection()))) {
e.setCancelled(true);
return;
}
} }
} }
@ -49,6 +69,10 @@ public class BlockListener implements Listener {
e.setCancelled(true); e.setCancelled(true);
return; return;
} }
else if(b.getRelative(e.getDirection()) == null && BlockStorage.hasBlockInfo(b.getRelative(e.getDirection()))) {
e.setCancelled(true);
return;
}
} }
} }
} }