summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockPressurePlateWeighted.patch
blob: 4b1f6e2dc7dcb3b2c94ce676a80eb54164ea7d82 (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
--- a/net/minecraft/server/BlockPressurePlateWeighted.java
+++ b/net/minecraft/server/BlockPressurePlateWeighted.java
@@ -1,5 +1,7 @@
 package net.minecraft.server;
 
+import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit
+
 public class BlockPressurePlateWeighted extends BlockPressurePlateAbstract {
 
     public static final BlockStateInteger POWER = BlockStateInteger.of("power", 0, 15);
@@ -16,7 +18,31 @@
     }
 
     protected int f(World world, BlockPosition blockposition) {
-        int i = Math.min(world.a(Entity.class, this.getBoundingBox(blockposition)).size(), this.weight);
+        // CraftBukkit start
+        //int i = Math.min(world.a(Entity.class, this.a(blockposition)).size(), this.b);
+        int i = 0;
+        java.util.Iterator iterator = world.a(Entity.class, this.getBoundingBox(blockposition)).iterator();
+
+        while (iterator.hasNext()) {
+            Entity entity = (Entity) iterator.next();
+
+            org.bukkit.event.Cancellable cancellable;
+
+            if (entity instanceof EntityHuman) {
+                cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null);
+            } else {
+                cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+                world.getServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+            }
+
+            // We only want to block turning the plate on if all events are cancelled
+            if (!cancellable.isCancelled()) {
+                i++;
+            }
+        }
+
+        i = Math.min(i, this.weight);
+        // CraftBukkit end
 
         if (i > 0) {
             float f = (float) Math.min(this.weight, i) / (float) this.weight;