diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2013-03-22 14:34:18 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2013-03-22 17:18:19 -0500 |
commit | 444ced306aec533bcc242ab0ba2bcded022da5f3 (patch) | |
tree | bd7f7369d3c10d8d4ea24a6608aa362b41a7952e /src | |
parent | ae19f2c46f8232239488d8218ce69a6e5e5ae22a (diff) | |
download | craftbukkit-444ced306aec533bcc242ab0ba2bcded022da5f3.tar craftbukkit-444ced306aec533bcc242ab0ba2bcded022da5f3.tar.gz craftbukkit-444ced306aec533bcc242ab0ba2bcded022da5f3.tar.lz craftbukkit-444ced306aec533bcc242ab0ba2bcded022da5f3.tar.xz craftbukkit-444ced306aec533bcc242ab0ba2bcded022da5f3.zip |
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.
Diffstat (limited to 'src')
3 files changed, 54 insertions, 32 deletions
diff --git a/src/main/java/net/minecraft/server/BlockButtonAbstract.java b/src/main/java/net/minecraft/server/BlockButtonAbstract.java index b8f62e5b..bdc48ffd 100644 --- a/src/main/java/net/minecraft/server/BlockButtonAbstract.java +++ b/src/main/java/net/minecraft/server/BlockButtonAbstract.java @@ -238,15 +238,6 @@ public abstract class BlockButtonAbstract extends Block { if (!world.isStatic) { if (this.a) { if ((world.getData(i, j, k) & 8) == 0) { - // CraftBukkit start - Call interaction when entities (currently arrows) hit wooden buttons - EntityInteractEvent event = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(i, j, k)); - world.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return; - } - // CraftBukkit end - this.n(world, i, j, k); } } @@ -262,6 +253,30 @@ public abstract class BlockButtonAbstract extends Block { List list = world.a(EntityArrow.class, AxisAlignedBB.a().a((double) i + this.minX, (double) j + this.minY, (double) k + this.minZ, (double) i + this.maxX, (double) j + this.maxY, (double) k + this.maxZ)); boolean flag1 = !list.isEmpty(); + // CraftBukkit start - Call interact event when arrows turn on wooden buttons + if (flag != flag1 && flag1) { + org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k); + boolean allowed = false; + + // If all of the events are cancelled block the button press, else allow + for (Object object : list) { + if (object != null) { + EntityInteractEvent event = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block); + world.getServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + allowed = true; + break; + } + } + } + + if (!allowed) { + return; + } + } + // CraftBukkit end + if (flag1 && !flag) { world.setData(i, j, k, i1 | 8, 3); this.d(world, i, j, k, i1); diff --git a/src/main/java/net/minecraft/server/BlockPressurePlateBinary.java b/src/main/java/net/minecraft/server/BlockPressurePlateBinary.java index ba7b6605..3b9de8a7 100644 --- a/src/main/java/net/minecraft/server/BlockPressurePlateBinary.java +++ b/src/main/java/net/minecraft/server/BlockPressurePlateBinary.java @@ -43,7 +43,7 @@ public class BlockPressurePlateBinary extends BlockPressurePlateAbstract { while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); - // CraftBukkit start + // 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; @@ -55,8 +55,9 @@ public class BlockPressurePlateBinary extends BlockPressurePlateAbstract { manager.callEvent((EntityInteractEvent) cancellable); } + // We only want to block turning the plate on if all events are cancelled if (cancellable.isCancelled()) { - return 0; + continue; } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/BlockTripwire.java b/src/main/java/net/minecraft/server/BlockTripwire.java index 520b4e3e..f020300f 100644 --- a/src/main/java/net/minecraft/server/BlockTripwire.java +++ b/src/main/java/net/minecraft/server/BlockTripwire.java @@ -147,31 +147,37 @@ public class BlockTripwire extends Block { } } - // CraftBukkit start - org.bukkit.World bworld = world.getWorld(); - org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager(); - - if (flag != flag1) { - if (flag1) { - 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, i, j, k, -1, null); - } else if (object instanceof Entity) { - cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), bworld.getBlockAt(i, j, k)); - manager.callEvent((EntityInteractEvent) cancellable); - } else { - continue; - } + // CraftBukkit start - Call interact even when triggering connected tripwire + if (flag != flag1 && flag1 && (world.getData(i, j, k) & 4) == 4) { + org.bukkit.World bworld = world.getWorld(); + org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager(); + org.bukkit.block.Block block = bworld.getBlockAt(i, j, k); + 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, i, j, k, -1, null); + } else if (object instanceof Entity) { + cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block); + manager.callEvent((EntityInteractEvent) cancellable); + } else { + continue; + } - if (cancellable.isCancelled()) { - return; - } + if (!cancellable.isCancelled()) { + allowed = true; + break; } } } + + if (!allowed) { + return; + } } // CraftBukkit end |