--- a/net/minecraft/server/BlockPiston.java +++ b/net/minecraft/server/BlockPiston.java @@ -6,6 +6,14 @@ import java.util.List; import java.util.Set; +// CraftBukkit start +import com.google.common.collect.ImmutableList; +import java.util.AbstractList; +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +// CraftBukkit end + public class BlockPiston extends BlockDirectional { public static final BlockStateBoolean EXTENDED = BlockProperties.g; @@ -112,6 +120,18 @@ } } + // CraftBukkit start + if (!this.sticky) { + org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + BlockPistonRetractEvent event = new BlockPistonRetractEvent(block, ImmutableList.<org.bukkit.block.Block>of(), CraftBlock.notchToBlockFace(enumdirection)); + world.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return; + } + } + // PAIL: checkME - what happened to setTypeAndData? + // CraftBukkit end world.playBlockAction(blockposition, this, b0, enumdirection.a()); } @@ -281,6 +301,48 @@ IBlockData[] aiblockdata = new IBlockData[j]; EnumDirection enumdirection1 = flag ? enumdirection : enumdirection.opposite(); Set<BlockPosition> set = Sets.newHashSet(list); + // CraftBukkit start + final org.bukkit.block.Block bblock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + + final List<BlockPosition> moved = pistonextendschecker.getMovedBlocks(); + final List<BlockPosition> broken = pistonextendschecker.getBrokenBlocks(); + + List<org.bukkit.block.Block> blocks = new AbstractList<org.bukkit.block.Block>() { + + @Override + public int size() { + return moved.size() + broken.size(); + } + + @Override + public org.bukkit.block.Block get(int index) { + if (index >= size() || index < 0) { + throw new ArrayIndexOutOfBoundsException(index); + } + BlockPosition pos = (BlockPosition) (index < moved.size() ? moved.get(index) : broken.get(index - moved.size())); + return bblock.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()); + } + }; + org.bukkit.event.block.BlockPistonEvent event; + if (flag) { + event = new BlockPistonExtendEvent(bblock, blocks, CraftBlock.notchToBlockFace(enumdirection1)); + } else { + event = new BlockPistonRetractEvent(bblock, blocks, CraftBlock.notchToBlockFace(enumdirection1)); + } + world.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + for (BlockPosition b : broken) { + world.notify(b, Blocks.AIR.getBlockData(), world.getType(b), 3); + } + for (BlockPosition b : moved) { + world.notify(b, Blocks.AIR.getBlockData(), world.getType(b), 3); + b = b.shift(enumdirection1); + world.notify(b, Blocks.AIR.getBlockData(), world.getType(b), 3); + } + return false; + } + // CraftBukkit end BlockPosition blockposition3; int k;