summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockConcretePowder.patch
blob: bebc324a8cb3e0996c151de9f832c3f7e951451a (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
--- a/net/minecraft/server/BlockConcretePowder.java
+++ b/net/minecraft/server/BlockConcretePowder.java
@@ -1,5 +1,10 @@
 package net.minecraft.server;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.event.block.BlockFormEvent;
+// CraftBukkit end
+
 public class BlockConcretePowder extends BlockFalling {
 
     private final IBlockData a;
@@ -11,7 +16,7 @@
 
     public void a(World world, BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {
         if (x(iblockdata1)) {
-            world.setTypeAndData(blockposition, this.a, 3);
+            org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(world, blockposition, this.a, 3); // CraftBukkit
         }
 
     }
@@ -20,7 +25,24 @@
         World world = blockactioncontext.getWorld();
         BlockPosition blockposition = blockactioncontext.getClickPosition();
 
-        return !x(world.getType(blockposition)) && !a((IBlockAccess) world, blockposition) ? super.getPlacedState(blockactioncontext) : this.a;
+        // CraftBukkit start
+        if (!x(world.getType(blockposition)) && !a((IBlockAccess) world, blockposition)) {
+            return super.getPlacedState(blockactioncontext);
+        }
+
+        // TODO: An event factory call for methods like this
+        CraftBlockState blockState = CraftBlockState.getBlockState(world, blockposition);
+        blockState.setData(this.a);
+
+        BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
+        world.getMinecraftServer().server.getPluginManager().callEvent(event);
+
+        if (!event.isCancelled()) {
+            return blockState.getHandle();
+        }
+
+        return super.getPlacedState(blockactioncontext);
+        // CraftBukkit end
     }
 
     private static boolean a(IBlockAccess iblockaccess, BlockPosition blockposition) {
@@ -51,6 +73,20 @@
     }
 
     public IBlockData updateState(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) {
-        return a((IBlockAccess) generatoraccess, blockposition) ? this.a : super.updateState(iblockdata, enumdirection, iblockdata1, generatoraccess, blockposition, blockposition1);
+        // CraftBukkit start
+        if (a((IBlockAccess) generatoraccess, blockposition)) {
+            CraftBlockState blockState = CraftBlockState.getBlockState(generatoraccess, blockposition);
+            blockState.setData(this.a);
+
+            BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
+            generatoraccess.getMinecraftWorld().getMinecraftServer().server.getPluginManager().callEvent(event);
+
+            if (!event.isCancelled()) {
+                return blockState.getHandle();
+            }
+        }
+
+        return super.updateState(iblockdata, enumdirection, iblockdata1, generatoraccess, blockposition, blockposition1);
+        // CraftBukkit end
     }
 }