Skip to content

Commit

Permalink
fix #183
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 24, 2024
1 parent be3b9ca commit 6daf090
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6daf090

Please sign in to comment.