diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java index addfaf5ad..7ac0323ac 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java @@ -11,8 +11,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.PlayerInventory; -import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isSpawnEgg; - public class PreventUsingSpawnEggs implements AnarchyExploitFixesModule, Listener { public PreventUsingSpawnEggs() { @@ -57,7 +55,7 @@ private void onInteract(PlayerInteractEvent event) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onDispense(BlockDispenseEvent event) { - if (isSpawnEgg(event.getItem())) { + if (MaterialUtil.isSpawnEgg(event.getItem())) { event.setCancelled(true); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java index 2125c78c3..11a42bab8 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java @@ -4,6 +4,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; @@ -20,7 +21,6 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; -import java.awt.*; import java.util.HashSet; import java.util.List; import java.util.logging.Level; @@ -89,15 +89,19 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onBlockDispense(BlockDispenseEvent event) { - if ( - MaterialUtil.isLiquidBucket(event.getItem().getType()) - && event.getVelocity().clone().toLocation(event.getBlock().getWorld()).getBlock().getType().equals(Material.END_PORTAL) - ) { + if (MaterialUtil.isBlockDispenseBucket(event.getItem().getType()) && isNearEndPortal(event.getBlock())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Prevented a dispenser from destroying an end portal!"); } } + private boolean isNearEndPortal(Block dispenser) { + for (BlockFace face : BlockFace.values()) { + if (dispenser.getRelative(face).getType().equals(Material.END_PORTAL)) return true; + } + return false; + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerBucketEvent(PlayerBucketEmptyEvent event) { if (event.getBlockClicked().getRelative(event.getBlockFace()).getType().equals(Material.END_PORTAL)) { @@ -161,7 +165,7 @@ private void onPistonExplode(EntityExplodeEvent event) { private boolean isWithinEndProtectedRadius(Location location) { if (!location.getWorld().getEnvironment().equals(World.Environment.THE_END)) return false; - return new Point(location.getBlockX(), location.getBlockZ()).distance(new Point(0,0)) <= endBedrockProtectRadius; + return LocationUtil.getFlatDistanceTo00(location) <= endBedrockProtectRadius; } private boolean isEndPortal(Material material) { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java index 62ae47c66..b86c6fe31 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java @@ -6,12 +6,12 @@ public class MaterialUtil { - public static boolean isLiquidBucket(ItemStack item) { + public static boolean isBlockDispenseBucket(ItemStack item) { if (item == null) return false; - return isLiquidBucket(item.getType()); + return isBlockDispenseBucket(item.getType()); } - public static boolean isLiquidBucket(Material material) { + public static boolean isBlockDispenseBucket(Material material) { if (material == null) return false; return switch (material) { case WATER_BUCKET, diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java index 159b9d10f..d09c057fa 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/portals/EndPortalDestruction.java @@ -4,6 +4,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; @@ -19,7 +20,6 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; -import java.awt.*; import java.util.Arrays; import java.util.HashSet; import java.util.logging.Level; @@ -86,15 +86,19 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onBlockDispense(BlockDispenseEvent event) { - if ( - MaterialUtil.LIQUID_BUCKETS.contains(event.getItem().getType()) - && event.getVelocity().clone().toLocation(event.getBlock().getWorld()).getBlock().getType().equals(end_portal) - ) { + if (MaterialUtil.BLOCK_DISPENSE_BUCKETS.contains(event.getItem().getType()) && isNearEndPortal(event.getBlock())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Prevented a dispenser from destroying an end portal!"); } } + private boolean isNearEndPortal(Block dispenser) { + for (BlockFace face : BlockFace.values()) { + if (dispenser.getRelative(face).getType().equals(end_portal)) return true; + } + return false; + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerBucketEvent(PlayerBucketEmptyEvent event) { if (event.getBlockClicked().getRelative(event.getBlockFace()).getType().equals(end_portal)) { @@ -160,7 +164,7 @@ private void onPistonExplode(EntityExplodeEvent event) { private boolean isWithinEndProtectedRadius(Location location) { if (!location.getWorld().getEnvironment().equals(World.Environment.THE_END)) return false; - return new Point(location.getBlockX(), location.getBlockZ()).distance(new Point(0,0)) <= endBedrockProtectRadius; + return LocationUtil.getFlatDistanceTo00(location) <= endBedrockProtectRadius; } private boolean isEndPortal(Material material) { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComBlockDigPacketListener.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComBlockDigPacketListener.java index 2464b300d..fa5686f8e 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComBlockDigPacketListener.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComBlockDigPacketListener.java @@ -45,5 +45,4 @@ public void onPacketReceiving(PacketEvent event) { } } } - } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java index ae20de70b..54fe6bf64 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java @@ -189,7 +189,7 @@ public static boolean isSpawnEgg(ItemStack item) { .map(XMaterial::parseMaterial) .collect(Collectors.toCollection(HashSet::new)); - public static final HashSet LIQUID_BUCKETS = Stream.of( + public static final HashSet BLOCK_DISPENSE_BUCKETS = Stream.of( XMaterial.WATER_BUCKET, XMaterial.LAVA_BUCKET, XMaterial.COD_BUCKET,