From 19521b7f1c570af427df5525419210e0808d35e3 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 16 Dec 2013 23:16:16 -0500 Subject: [PATCH] [Bleeding] Fire interact events for Weighted Pressure Plates. Fixes BUKKIT-5053 In 1.7, Minecraft changed Weighted Pressure Plates to allow players and entities to interact with them, rather than simply changing redstone signal based on the number of items on the pressure plate. This commit adds calls to PlayerInteractEvent or EntityInteractEvent for every entity that steps on the plate. --- .../server/BlockPressurePlateWeighted.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/BlockPressurePlateWeighted.java b/src/main/java/net/minecraft/server/BlockPressurePlateWeighted.java index 7085569029..8bc708fc33 100644 --- a/src/main/java/net/minecraft/server/BlockPressurePlateWeighted.java +++ b/src/main/java/net/minecraft/server/BlockPressurePlateWeighted.java @@ -2,6 +2,8 @@ package net.minecraft.server; import java.util.List; +import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit + public class BlockPressurePlateWeighted extends BlockPressurePlateAbstract { private final int a; @@ -11,7 +13,30 @@ public class BlockPressurePlateWeighted extends BlockPressurePlateAbstract { } protected int e(World world, int i, int j, int k) { - int l = Math.min(world.a(Entity.class, this.a(i, j, k)).size(), this.a); + // CraftBukkit start + int l = 0; + java.util.Iterator iterator = world.a(Entity.class, this.a(i, j, k)).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, i, j, k, -1, null); + } else { + cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(i, j, k)); + world.getServer().getPluginManager().callEvent((EntityInteractEvent) cancellable); + } + + // We only want to block turning the plate on if all events are cancelled + if (!cancellable.isCancelled()) { + l++; + } + } + + l = Math.min(l, this.a); + // CraftBukkit end if (l <= 0) { return 0;