From 940ce8142df8b78c8ee33443682e27ceb09c3819 Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 7 Aug 2024 23:40:49 +0200 Subject: [PATCH] correct elytra speed calculation --- .../java/me/xginko/aef/modules/elytra/ElytraHelper.java | 7 ++++--- .../src/main/java/me/xginko/aef/config/Config.java | 4 ++-- .../java/me/xginko/aef/modules/elytra/ElytraHelper.java | 9 +++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java index ebba5e78..aab68333 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java @@ -37,6 +37,7 @@ public class ElytraHelper extends AEFModule implements Runnable, PacketListener, private final PacketListenerAbstract packetListener; private ScheduledExecutorService executorService; private ScheduledFuture scheduledTask; + private final long speed_as_ticks = config.elytra_speed_calc_period / 50L; public ElytraHelper() { super("elytra.elytra-speed"); @@ -74,7 +75,7 @@ public void disable() { @Override public void run() { for (Map.Entry entry : playerDataMap.entrySet()) { - entry.getValue().calcSpeedAvg(config.elytra_calculate_3D, config.elytra_speed_calc_period); + entry.getValue().calcSpeedAvg(config.elytra_calculate_3D, speed_as_ticks); } } @@ -160,9 +161,9 @@ public void updateLatestPosition(Location location) { latest.setZ((float) location.getZ()); } - public void calcSpeedAvg(boolean using3D, long period) { + public void calcSpeedAvg(boolean using3D, long tickPeriod) { // Blockdistance per tick - speedAvg = Math.abs(using3D ? LocationUtil.getRelDistance3D(previous, latest) : LocationUtil.getRelDistance2D(previous, latest)) / ((double) period / 50); + speedAvg = Math.abs(using3D ? LocationUtil.getRelDistance3D(previous, latest) : LocationUtil.getRelDistance2D(previous, latest)) / tickPeriod; previous = latest.clone(); } }; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java index fbe3c90d..d64a3232 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java @@ -21,7 +21,7 @@ public class Config { public final String cmd_say_format; public final Sound elytra_too_fast_sound; public final Duration tps_cache_duration; - public final long elytra_speed_calc_period, elytra_old_chunk_limit; + public final long elytra_speed_calc_period_millis, elytra_old_chunk_limit; public final int nether_ceiling_max_y, nether_floor_min_y, overworld_floor_min_y, elytra_spawn_radius; public final boolean auto_lang, packets_disabled, connectionMsgsAreOnByDefault, cmd_say_enabled, cmd_help_enabled, cmd_toggleConMsgs_enabled, @@ -74,7 +74,7 @@ public Config() throws Exception { "Time in ticks that a chunk has to have been inhabited to count as old chunk.\n" + "Note that the time is incremented once per tick per player within mob spawning\n" + "distance of a chunk."); - this.elytra_speed_calc_period = getInt("elytra.elytra-speed.check-period-millis", 500, + this.elytra_speed_calc_period_millis = getInt("elytra.elytra-speed.check-period-millis", 500, "The period in millis players will be checked to determine their speed.\n" + "If you have lagging players with consistent high ping, you can increase this number."); this.elytra_calculate_3D = getBoolean("elytra.elytra-speed.calculate-3D-speed", false, diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java index 8a44cd6e..98e6a463 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/elytra/ElytraHelper.java @@ -42,6 +42,7 @@ public class ElytraHelper extends AEFModule implements Runnable, PacketListener, private NewChunksListener newChunksListener; private ScheduledExecutorService executorService; private ScheduledFuture scheduledTask; + private final long speed_as_ticks = config.elytra_speed_calc_period_millis / 50L; public ElytraHelper() { super("elytra.elytra-speed"); @@ -60,7 +61,7 @@ public void enable() { PacketEvents.getAPI().getEventManager().registerListener(packetListener); executorService = Executors.newScheduledThreadPool(1); scheduledTask = executorService.scheduleAtFixedRate( - this, 50L, config.elytra_speed_calc_period, TimeUnit.MILLISECONDS); + this, 50L, config.elytra_speed_calc_period_millis, TimeUnit.MILLISECONDS); if (!ChunkUtil.canGetInhabitedTime()) newChunksListener = new NewChunksListener(); } @@ -82,7 +83,7 @@ public boolean shouldEnable() { @Override public void run() { for (Map.Entry entry : playerDataMap.entrySet()) { - entry.getValue().calcSpeedAvg(config.elytra_calculate_3D, config.elytra_speed_calc_period); + entry.getValue().calcSpeedAvg(config.elytra_calculate_3D, speed_as_ticks); } } @@ -162,9 +163,9 @@ public void updateLatestPosition(Location location) { latest.setZ((float) location.getZ()); } - public void calcSpeedAvg(boolean using3D, long period) { + public void calcSpeedAvg(boolean using3D, long tickPeriod) { // Blockdistance per tick - speedAvg = Math.abs(using3D ? LocationUtil.getRelDistance3D(previous, latest) : LocationUtil.getRelDistance2D(previous, latest)) / ((double) period / 50); + speedAvg = Math.abs(using3D ? LocationUtil.getRelDistance3D(previous, latest) : LocationUtil.getRelDistance2D(previous, latest)) / tickPeriod; previous = latest.clone(); } };