Paper/src/main/java/net/minecraft/server/BlockPressurePlateBinary.java
Travis Watkins 444ced306a Cleanup and rework physical interaction events. Fixes BUKKIT-3686
Currently when dealing with physical interactions with pressure plates
and tripwires we immediately block their activation as soon as a single
entity involved has their event cancelled. We also fire events whenever
an entity intersects the block a wooden button is in even if they aren't
actually pressing it. To correct this we move the button interaction to
the correct place and modify all three to only block the activation if
every entity is blocked from using them instead of just one of them.
2013-03-22 17:18:19 -05:00

73 Zeilen
2.3 KiB
Java

package net.minecraft.server;
import java.util.Iterator;
import java.util.List;
import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit
public class BlockPressurePlateBinary extends BlockPressurePlateAbstract {
private EnumMobType a;
protected BlockPressurePlateBinary(int i, String s, Material material, EnumMobType enummobtype) {
super(i, s, material);
this.a = enummobtype;
}
protected int d(int i) {
return i > 0 ? 1 : 0;
}
protected int c(int i) {
return i == 1 ? 15 : 0;
}
protected int e(World world, int i, int j, int k) {
List list = null;
if (this.a == EnumMobType.EVERYTHING) {
list = world.getEntities((Entity) null, this.a(i, j, k));
}
if (this.a == EnumMobType.MOBS) {
list = world.a(EntityLiving.class, this.a(i, j, k));
}
if (this.a == EnumMobType.PLAYERS) {
list = world.a(EntityHuman.class, this.a(i, j, k));
}
if (!list.isEmpty()) {
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
// CraftBukkit start - Fire interact event when turning on a pressure plate
org.bukkit.World bworld = world.getWorld();
org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager();
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(), bworld.getBlockAt(i, j, k));
manager.callEvent((EntityInteractEvent) cancellable);
}
// We only want to block turning the plate on if all events are cancelled
if (cancellable.isCancelled()) {
continue;
}
// CraftBukkit end
if (!entity.at()) {
return 15;
}
}
}
return 0;
}
}