Skip to content
Permalink
Browse files

Fire block breaks for piston extends, not just places.

  • Loading branch information
wizjany committed Mar 21, 2020
1 parent e6bdf8a commit a09ccc5b455b92f27fbe9d7ad082a70c19023cfa
@@ -346,6 +346,7 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR));
if (originalSize != blocks.size()) {
event.setCancelled(true);
return;
}
for (Block b : blocks) {
Location loc = b.getRelative(direction).getLocation();
@@ -365,8 +366,14 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
EventDebounce.Entry entry = pistonExtendDebounce.getIfNotPresent(new BlockPistonExtendKey(event), event);
if (entry != null) {
Cause cause = create(event.getBlock());
List<Block> blocks = new ArrayList<>(event.getBlocks());
int originalLength = blocks.size();
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR));
if (originalLength != blocks.size()) {
event.setCancelled(true);
return;
}
BlockFace dir = event.getDirection();
for (int i = 0; i < blocks.size(); i++) {
Block existing = blocks.get(i);
@@ -376,7 +383,7 @@ public void onBlockPistonExtend(BlockPistonExtendEvent event) {
blocks.set(i, existing.getRelative(dir));
}
}
Events.fireBulkEventToCancel(event, new PlaceBlockEvent(event, create(event.getBlock()), event.getBlock().getWorld(), blocks, Material.STONE));
Events.fireBulkEventToCancel(event, new PlaceBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.STONE));
if (blocks.size() != originalLength) {
event.setCancelled(true);
}

0 comments on commit a09ccc5

Please sign in to comment.
You can’t perform that action at this time.