From 6daf090b0112478b382cbbfe6ad33c95bde546fb Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 24 Jan 2024 21:05:25 +0100 Subject: [PATCH] fix #183 --- .../modules/elytra/ElytraHelper.java | 3 ++- .../utils/LocationUtil.java | 25 +++++++++++++++++++ .../modules/elytra/ElytraHelper.java | 2 +- .../utils/LocationUtil.java | 25 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java index a83378670..9ec651f32 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java @@ -6,6 +6,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.apache.commons.math3.util.FastMath; import org.bukkit.Chunk; import org.bukkit.Location; @@ -73,7 +74,7 @@ public void enable() { Location currentLocation = player.getLocation().clone(); Location lastLocation = LAST_GLIDE_POS.getIfPresent(player.getUniqueId()); if (lastLocation != null) PLAYER_SPEEDS_INTERVAL.put(player.getUniqueId(), - lastLocation.distance(currentLocation) / checkIntervalTicks); + LocationUtil.getNormalizedDistance(lastLocation, currentLocation) / checkIntervalTicks); LAST_GLIDE_POS.put(player.getUniqueId(), currentLocation); } }, null); 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 2719285a4..0e57c5c55 100644 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java @@ -4,6 +4,7 @@ import org.apache.commons.math3.util.FastMath; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.util.NumberConversions; public class LocationUtil { @@ -33,6 +34,30 @@ public static double getFlatDistance(Location from, Location to) { return FastMath.hypot(toX - fromX, toZ - fromZ); } + public static double getNormalizedDistance(Location from, Location to) { + double toX = to.x(); + double toZ = to.z(); + double fromX = from.x(); + double fromZ = from.z(); + + final World.Environment toEnv = to.getWorld().getEnvironment(); + final World.Environment fromEnv = from.getWorld().getEnvironment(); + if (toEnv != fromEnv) { + if (fromEnv == World.Environment.NETHER) { + fromX *= 8; + fromZ *= 8; + } + if (toEnv == World.Environment.NETHER) { + toX *= 8; + toZ *= 8; + } + } + + return Math.sqrt(NumberConversions.square(fromX - toX) + + NumberConversions.square(from.getY() - to.getY()) + + NumberConversions.square(fromZ - toZ)); + } + public static boolean isNetherCeiling(Location location) { return location.getWorld().getEnvironment() == World.Environment.NETHER && location.y() > AnarchyExploitFixes.getConfiguration().nether_ceiling_max_y; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java index 5b080a000..6b3b25add 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java @@ -79,7 +79,7 @@ public void run() { Location currentLocation = player.getLocation().clone(); Location lastLocation = LAST_GLIDE_POS.getIfPresent(player.getUniqueId()); if (lastLocation != null) PLAYER_SPEEDS_INTERVAL.put(player.getUniqueId(), - lastLocation.distance(currentLocation) / checkIntervalTicks); + LocationUtil.getNormalizedDistance(lastLocation, currentLocation) / checkIntervalTicks); LAST_GLIDE_POS.put(player.getUniqueId(), currentLocation); } } 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 4d0128990..cd225dfce 100644 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java @@ -4,6 +4,7 @@ import org.apache.commons.math3.util.FastMath; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.util.NumberConversions; public class LocationUtil { @@ -33,6 +34,30 @@ public static double getFlatDistance(Location from, Location to) { return FastMath.hypot(toX - fromX, toZ - fromZ); } + public static double getNormalizedDistance(Location from, Location to) { + double toX = to.getX(); + double toZ = to.getZ(); + double fromX = from.getX(); + double fromZ = from.getZ(); + + final World.Environment toEnv = to.getWorld().getEnvironment(); + final World.Environment fromEnv = from.getWorld().getEnvironment(); + if (toEnv != fromEnv) { + if (fromEnv == World.Environment.NETHER) { + fromX *= 8; + fromZ *= 8; + } + if (toEnv == World.Environment.NETHER) { + toX *= 8; + toZ *= 8; + } + } + + return Math.sqrt(NumberConversions.square(fromX - toX) + + NumberConversions.square(from.getY() - to.getY()) + + NumberConversions.square(fromZ - toZ)); + } + public static boolean isNetherCeiling(Location location) { return location.getWorld().getEnvironment() == World.Environment.NETHER && location.getY() > AnarchyExploitFixes.getConfiguration().nether_ceiling_max_y;