From 5841106bea32343968acda372e0a8e076c04f349 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 7 Aug 2012 22:32:34 -0500 Subject: [PATCH] (by ammaraskar) Fixes an ender pearl clipping exploit with blocks that occupy less than 1 block in width or length --- .../listeners/FactionsExploitListener.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/com/massivecraft/factions/listeners/FactionsExploitListener.java b/src/com/massivecraft/factions/listeners/FactionsExploitListener.java index 133b6800..aebbe3b3 100644 --- a/src/com/massivecraft/factions/listeners/FactionsExploitListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsExploitListener.java @@ -7,6 +7,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.Location; +import org.bukkit.Material; import com.massivecraft.factions.Conf; @@ -33,10 +34,35 @@ public class FactionsExploitListener implements Listener if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return; // this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar... - // simple fix: ender pearl target locations are standardized to be in the center (X/Z) of the target block, not at the edges Location target = event.getTo(); + Location from = event.getFrom(); + + // blocks who occupy less than 1 block width or length wise need to be handled differently + Material mat = event.getTo().getBlock().getType(); + if ( + ((mat == Material.THIN_GLASS || mat == Material.IRON_FENCE) && clippingThrough(target, from, 0.65)) + || ((mat == Material.FENCE || mat == Material.NETHER_FENCE) && clippingThrough(target, from, 0.45)) + ) + { + event.setTo(from); + return; + } + + // simple fix otherwise: ender pearl target locations are standardized to be in the center (X/Z) of the target block, not at the edges target.setX(target.getBlockX() + 0.5); target.setZ(target.getBlockZ() + 0.5); event.setTo(target); + + } + + public static boolean clippingThrough(Location target, Location from, double thickness) + { + return + ( + (from.getX() > target.getX() && (from.getX() - target.getX() < thickness)) + || (target.getX() > from.getX() && (target.getX() - from.getX() < thickness)) + || (from.getZ() > target.getZ() && (from.getZ() - target.getZ() < thickness)) + || (target.getZ() > from.getZ() && (target.getZ() - from.getZ() < thickness)) + ); } }