diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java index 7360f1c01..c1e4965a3 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java @@ -3,9 +3,9 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; @@ -22,7 +22,6 @@ public class NetherRoof implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private final int ceilingY; private final boolean safe_teleport_enabled; public NetherRoof() { @@ -31,7 +30,6 @@ public NetherRoof() { Config config = AnarchyExploitFixes.getConfiguration(); config.addComment("preventions.prevent-nether-roof.enable", "Prevent players from going above the nether roof."); this.safe_teleport_enabled = config.getBoolean("preventions.prevent-nether-roof.safely-teleport-players", true); - this.ceilingY = config.nether_ceiling_max_y; } @Override @@ -59,40 +57,38 @@ public void disable() { HandlerList.unregisterAll(this); } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void onTeleport(PlayerTeleportEvent event) { - final Location teleportDestination = event.getTo(); - if (!teleportDestination.getWorld().getEnvironment().equals(World.Environment.NETHER)) return; - - if (teleportDestination.getY() >= ceilingY) { - if (event.getPlayer().hasPermission("anarchyexploitfixes.netherroofbypass")) return; + if ( + LocationUtil.isNetherCeiling(event.getTo()) + && !event.getPlayer().hasPermission("anarchyexploitfixes.netherroofbypass") + ) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - if (!player.getWorld().getEnvironment().equals(World.Environment.NETHER)) return; - - if (event.getTo().getY() >= ceilingY || player.getLocation().getY() >= ceilingY) { - if (player.hasPermission("anarchyexploitfixes.netherroofbypass")) return; - teleportFromCeiling(player); + if ( + LocationUtil.isNetherCeiling(player.getLocation()) + && !player.hasPermission("anarchyexploitfixes.netherroofbypass") + ) { + this.teleportFromCeiling(player); } } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); - if (!player.getWorld().getEnvironment().equals(World.Environment.NETHER)) return; - - if (event.getBlock().getY() > ceilingY) { - if (player.hasPermission("anarchyexploitfixes.netherroofbypass")) return; + if (player.hasPermission("anarchyexploitfixes.netherroofbypass")) return; + if (LocationUtil.isNetherCeiling(event.getBlock().getLocation())) { event.setCancelled(true); - if (player.getLocation().getY() >= ceilingY) { - teleportFromCeiling(player); - } + } + + if (LocationUtil.isNetherCeiling(player.getLocation())) { + this.teleportFromCeiling(player); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.java index 4dd912e11..35e763c10 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.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 net.kyori.adventure.text.TextReplacementConfig; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -15,7 +16,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; -import java.awt.*; import java.util.HashMap; import java.util.Map; @@ -77,20 +77,15 @@ private void onCreatureSpawn(CreatureSpawnEvent event) { final Integer disabledRadius = worldsAndTheirRadiuses.get(world); Location witherLocation = wither.getLocation(); - if (!isInDisabledRange(witherLocation, disabledRadius)) return; + if (LocationUtil.getDistanceTo00(witherLocation) > disabledRadius) return; event.setCancelled(true); if (playersShouldBeInformed) { for (Player nearbyPlayer : witherLocation.getNearbyPlayers(8, 8, 8)) { nearbyPlayer.sendMessage(AnarchyExploitFixes.getLang(nearbyPlayer.locale()).preventions_witherSpawningDisabledInRadius - .replaceText(TextReplacementConfig.builder().matchLiteral("%radius%").replacement(disabledRadius.toString()).build()) - ); + .replaceText(TextReplacementConfig.builder().matchLiteral("%radius%").replacement(disabledRadius.toString()).build())); } } } - - private static boolean isInDisabledRange(Location witherLocation, Integer disabledRadius) { - return new Point(witherLocation.getBlockX(), witherLocation.getBlockZ()).distance(new Point(0, 0)) < disabledRadius; - } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java index b4a6e0342..f702507c7 100644 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java @@ -72,6 +72,6 @@ public static double getXYDistance(Location from, Location to) { public static boolean isNetherCeiling(Location location) { return location.getWorld().getEnvironment().equals(World.Environment.NETHER) - && location.y() > AnarchyExploitFixes.getConfiguration().nether_ceiling_max_y - 1; + && location.y() > AnarchyExploitFixes.getConfiguration().nether_ceiling_max_y; } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java index aa293a64e..f2008d543 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/NetherRoof.java @@ -4,9 +4,9 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; @@ -19,21 +19,17 @@ public class NetherRoof implements AnarchyExploitFixesModule, Listener { - private final int ceilingY; + private final Material AIR, NETHER_PORTAL, NETHERRACK; private final boolean safe_teleport_enabled; - private final Material air, nether_portal, netherrack; - public NetherRoof() { shouldEnable(); + this.AIR = XMaterial.AIR.parseMaterial(); + this.NETHER_PORTAL = XMaterial.NETHER_PORTAL.parseMaterial(); + this.NETHERRACK = XMaterial.NETHERRACK.parseMaterial(); Config config = AnarchyExploitFixes.getConfiguration(); config.addComment("preventions.prevent-nether-roof.enable", "Prevent players from going above the nether roof."); this.safe_teleport_enabled = config.getBoolean("preventions.prevent-nether-roof.safely-teleport-players", true); - this.ceilingY = config.nether_ceiling_max_y; - - this.air = XMaterial.AIR.parseMaterial(); - this.nether_portal = XMaterial.NETHER_PORTAL.parseMaterial(); - this.netherrack = XMaterial.NETHERRACK.parseMaterial(); } @Override @@ -57,38 +53,38 @@ public boolean shouldEnable() { return AnarchyExploitFixes.getConfiguration().getBoolean("preventions.prevent-nether-roof.enable", true); } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void onTeleport(PlayerTeleportEvent event) { - final Location teleportDestination = event.getTo(); - if (!teleportDestination.getWorld().getEnvironment().equals(World.Environment.NETHER)) return; - - if (teleportDestination.getY() >= ceilingY) { - if (event.getPlayer().hasPermission("anarchyexploitfixes.netherroofbypass")) return; + if ( + LocationUtil.isNetherCeiling(event.getTo()) + && !event.getPlayer().hasPermission("anarchyexploitfixes.netherroofbypass") + ) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - if (!player.getWorld().getEnvironment().equals(World.Environment.NETHER)) return; - - if (event.getTo().getY() >= ceilingY || player.getLocation().getY() >= ceilingY) { - if (player.hasPermission("anarchyexploitfixes.netherroofbypass")) return; - teleportFromCeiling(player); + if ( + LocationUtil.isNetherCeiling(player.getLocation()) + && !player.hasPermission("anarchyexploitfixes.netherroofbypass") + ) { + this.teleportFromCeiling(player); } } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); - if (!player.getWorld().getEnvironment().equals(World.Environment.NETHER)) return; - - if (event.getBlock().getY() > ceilingY) { - if (player.hasPermission("anarchyexploitfixes.netherroofbypass")) return; + if (player.hasPermission("anarchyexploitfixes.netherroofbypass")) return; + if (LocationUtil.isNetherCeiling(event.getBlock().getLocation())) { event.setCancelled(true); - teleportFromCeiling(player); + } + + if (LocationUtil.isNetherCeiling(player.getLocation())) { + this.teleportFromCeiling(player); } } @@ -102,33 +98,33 @@ private void teleportFromCeiling(Player player) { // Check block above for liquid or falling block Block blockAboveHead = teleportDestination.clone().add(0,2,0).getBlock(); if (blockAboveHead.isLiquid() || blockAboveHead.getType().hasGravity()) - blockAboveHead.setType(netherrack, false); + blockAboveHead.setType(NETHERRACK, false); // Create air pocket for player Block blockAtPlayerLegs = teleportDestination.getBlock(); - if (!blockAtPlayerLegs.getType().equals(air) && !blockAtPlayerLegs.getType().equals(nether_portal)) - blockAtPlayerLegs.setType(air, false); + if (!blockAtPlayerLegs.getType().equals(AIR) && blockAtPlayerLegs.getType().equals(NETHER_PORTAL)) + blockAtPlayerLegs.setType(AIR, false); Block blockAtPlayerTorso = blockAtPlayerLegs.getRelative(BlockFace.UP); - if (!blockAtPlayerTorso.getType().equals(air) && !blockAtPlayerTorso.getType().equals(nether_portal)) - blockAtPlayerTorso.setType(air, false); + if (!blockAtPlayerTorso.getType().equals(AIR) && !blockAtPlayerTorso.getType().equals(NETHER_PORTAL)) + blockAtPlayerTorso.setType(AIR, false); // Check all sides of air pocket for liquids and fill with netherrack for (int i = 0; i < 2; i++) { Block airPocketBlock = blockAtPlayerLegs.getRelative(BlockFace.UP, i); if (airPocketBlock.getRelative(BlockFace.NORTH).isLiquid()) - airPocketBlock.getRelative(BlockFace.NORTH).setType(netherrack, false); + airPocketBlock.getRelative(BlockFace.NORTH).setType(NETHERRACK, false); if (airPocketBlock.getRelative(BlockFace.EAST).isLiquid()) - airPocketBlock.getRelative(BlockFace.EAST).setType(netherrack, false); + airPocketBlock.getRelative(BlockFace.EAST).setType(NETHERRACK, false); if (airPocketBlock.getRelative(BlockFace.SOUTH).isLiquid()) - airPocketBlock.getRelative(BlockFace.SOUTH).setType(netherrack, false); + airPocketBlock.getRelative(BlockFace.SOUTH).setType(NETHERRACK, false); if (airPocketBlock.getRelative(BlockFace.WEST).isLiquid()) - airPocketBlock.getRelative(BlockFace.WEST).setType(netherrack, false); + airPocketBlock.getRelative(BlockFace.WEST).setType(NETHERRACK, false); } // Create block below feet if not solid Block blockBelowFeet = blockAtPlayerLegs.getRelative(BlockFace.DOWN); if (blockBelowFeet.isLiquid() || blockBelowFeet.getType().hasGravity()) - blockBelowFeet.setType(netherrack, false); + blockBelowFeet.setType(NETHERRACK, false); } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.java index d06850965..407e56533 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/WitherSpawningAtSpawn.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 org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -13,7 +14,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; -import java.awt.*; import java.util.HashMap; import java.util.Map; @@ -72,20 +72,15 @@ private void onCreatureSpawn(CreatureSpawnEvent event) { final Integer disabledRadius = worldsAndTheirRadiuses.get(world); final Location witherLocation = entity.getLocation(); - if (!isInDisabledRange(witherLocation, disabledRadius)) return; + if (LocationUtil.getDistanceTo00(witherLocation) > disabledRadius) return; event.setCancelled(true); if (playersShouldBeInformed) { for (Player nearbyPlayer : witherLocation.getNearbyPlayers(8, 8, 8)) { nearbyPlayer.sendMessage(AnarchyExploitFixes.getLang(nearbyPlayer.getLocale()).withers_SpawningDisabledInRadius - .replace("%radius%", disabledRadius.toString()) - ); + .replace("%radius%", disabledRadius.toString())); } } } - - private static boolean isInDisabledRange(Location witherLocation, Integer disabledRadius) { - return new Point(witherLocation.getBlockX(), witherLocation.getBlockZ()).distance(new Point(0, 0)) < disabledRadius; - } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java index e3e2c9e77..82404ebdd 100644 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java @@ -72,6 +72,6 @@ public static double getXYDistance(Location from, Location to) { public static boolean isNetherCeiling(Location location) { return location.getWorld().getEnvironment().equals(World.Environment.NETHER) - && location.getY() > AnarchyExploitFixes.getConfiguration().nether_ceiling_max_y - 1; + && location.getY() > AnarchyExploitFixes.getConfiguration().nether_ceiling_max_y; } }