PaperMC/nms-patches/BlockPiston.patch

99 lines
4.6 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/BlockPiston.java
+++ b/net/minecraft/server/BlockPiston.java
2016-05-10 13:47:39 +02:00
@@ -5,6 +5,18 @@
2015-02-26 23:41:06 +01:00
import java.util.List;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
2015-02-26 23:41:06 +01:00
+// CraftBukkit start
+import java.util.AbstractList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ListIterator;
+
+import com.google.common.collect.ImmutableList;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.block.BlockPistonRetractEvent;
+import org.bukkit.event.block.BlockPistonExtendEvent;
+// CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2016-02-29 22:32:46 +01:00
public class BlockPiston extends BlockDirectional {
2016-02-29 22:32:46 +01:00
public static final BlockStateBoolean EXTENDED = BlockStateBoolean.of("extended");
2016-05-10 13:47:39 +02:00
@@ -99,6 +111,18 @@
world.playBlockAction(blockposition, this, 0, enumdirection.a());
}
} else if (!flag && ((Boolean) iblockdata.get(BlockPiston.EXTENDED)).booleanValue()) {
+ // CraftBukkit start
2015-07-30 08:56:52 +02:00
+ 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;
+ }
+ }
2016-02-29 22:32:46 +01:00
+ // PAIL: checkME - what happened to setTypeAndData?
+ // CraftBukkit end
world.playBlockAction(blockposition, this, 1, enumdirection.a());
}
2016-02-29 22:32:46 +01:00
2016-05-10 13:47:39 +02:00
@@ -189,7 +213,7 @@
}
}
2016-02-29 22:32:46 +01:00
- if (!flag1 && iblockdata1.getMaterial() != Material.AIR && a(iblockdata1, world, blockposition1, enumdirection.opposite(), false) && (iblockdata1.o() == EnumPistonReaction.NORMAL || block == Blocks.PISTON || block == Blocks.STICKY_PISTON)) {
+ if (!flag1 && a(iblockdata1, world, blockposition1, enumdirection.opposite(), false) && (iblockdata1.o() == EnumPistonReaction.NORMAL || block == Blocks.PISTON || block == Blocks.STICKY_PISTON)) { // CraftBukkit - remove 'block.getMaterial() != Material.AIR' condition
this.a(world, blockposition, enumdirection, false);
}
} else {
2016-05-10 13:47:39 +02:00
@@ -286,6 +310,48 @@
2016-02-29 22:32:46 +01:00
int j = list.size() + list1.size();
IBlockData[] aiblockdata = new IBlockData[j];
EnumDirection enumdirection1 = flag ? enumdirection : enumdirection.opposite();
+ // 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) {
2016-02-29 22:32:46 +01:00
+ world.notify(b, Blocks.AIR.getBlockData(), world.getType(b), 3);
+ }
+ for (BlockPosition b : moved) {
2016-02-29 22:32:46 +01:00
+ 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
2016-02-29 22:32:46 +01:00
int k;
BlockPosition blockposition2;