summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockPiston.patch
blob: 1e7d0100c62d3f70dbc9f7f508b813b3b2ace215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--- /home/matt/mc-dev-private//net/minecraft/server/BlockPiston.java	2015-02-26 22:40:22.195608144 +0000
+++ src/main/java/net/minecraft/server/BlockPiston.java	2015-02-26 22:40:22.199608144 +0000
@@ -2,6 +2,18 @@
 
 import java.util.List;
 
+// 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
+
 public class BlockPiston extends Block {
 
     public static final BlockStateDirection FACING = BlockStateDirection.of("facing");
@@ -56,6 +68,17 @@
                 world.playBlockAction(blockposition, this, 0, enumdirection.a());
             }
         } else if (!flag && ((Boolean) iblockdata.get(BlockPiston.EXTENDED)).booleanValue()) {
+            // CraftBukkit start
+            if (!this.N) {
+                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;
+                }
+            }
+            // CraftBukkit end
             world.setTypeAndData(blockposition, iblockdata.set(BlockPiston.EXTENDED, Boolean.valueOf(false)), 2);
             world.playBlockAction(blockposition, this, 1, enumdirection.a());
         }
@@ -146,7 +169,7 @@
                     }
                 }
 
-                if (!flag1 && block.getMaterial() != Material.AIR && a(block, world, blockposition1, enumdirection.opposite(), false) && (block.k() == 0 || block == Blocks.PISTON || block == Blocks.STICKY_PISTON)) {
+                if (!flag1 && a(block, world, blockposition1, enumdirection.opposite(), false) && (block.k() == 0 || block == Blocks.PISTON || block == Blocks.STICKY_PISTON)) { // CraftBukkit - remove 'block.getMaterial() != Material.AIR' condition
                     this.a(world, blockposition, enumdirection, false);
                 }
             } else {
@@ -286,10 +309,46 @@
         if (!pistonextendschecker.a()) {
             return false;
         } else {
+            // CraftBukkit start
+            final org.bukkit.block.Block bblock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+            final List moved = pistonextendschecker.getMovedBlocks();
+            final List 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());
+                }
+            };
+
             int i = list.size() + list1.size();
             Block[] ablock = new Block[i];
             EnumDirection enumdirection1 = flag ? enumdirection : enumdirection.opposite();
 
+            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()) {
+                return false;
+            }
+            // CraftBukkit end
+
             int j;
             BlockPosition blockposition1;