summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockTripwire.patch
blob: deb34e86e84fbdbaf89295cccffe4777f7ff3760 (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
--- ../work/decompile-8eb82bde//net/minecraft/server/BlockTripwire.java	2014-11-28 17:43:42.977707438 +0000
+++ src/main/java/net/minecraft/server/BlockTripwire.java	2014-11-28 17:38:18.000000000 +0000
@@ -4,6 +4,8 @@
 import java.util.List;
 import java.util.Random;
 
+import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit
+
 public class BlockTripwire extends Block {
 
     public static final BlockStateBoolean POWERED = BlockStateBoolean.of("powered");
@@ -154,6 +156,40 @@
                 }
             }
         }
+        
+        // CraftBukkit start - Call interact even when triggering connected tripwire
+        if (flag != flag1 && flag1 && (Boolean)iblockdata.get(ATTACHED)) {
+            org.bukkit.World bworld = world.getWorld();
+            org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager();
+            org.bukkit.block.Block block = bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+            boolean allowed = false;
+
+            // If all of the events are cancelled block the tripwire trigger, else allow
+            for (Object object : list) {
+                if (object != null) {
+                    org.bukkit.event.Cancellable cancellable;
+
+                    if (object instanceof EntityHuman) {
+                        cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) object, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null);
+                    } else if (object instanceof Entity) {
+                        cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
+                        manager.callEvent((EntityInteractEvent) cancellable);
+                    } else {
+                        continue;
+                    }
+
+                    if (!cancellable.isCancelled()) {
+                        allowed = true;
+                        break;
+                    }
+                }
+            }
+
+            if (!allowed) {
+                return;
+            }
+        }
+        // CraftBukkit end
 
         if (flag1 != flag) {
             iblockdata = iblockdata.set(BlockTripwire.POWERED, Boolean.valueOf(flag1));