diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java index 35a023dc9..093e63b0b 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java @@ -32,8 +32,6 @@ public class AnarchyExploitFixes extends JavaPlugin { private static Logger logger; private static boolean isServerFolia, foundProtocolLib; - public final HashSet NEW_CHUNK_PLAYERS = new HashSet<>(); - @Override public void onEnable() { instance = this; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java index 954dc51b3..2a8eb6980 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -99,12 +99,11 @@ static void reloadModules() { /* Elytra */ + modules.add(new ElytraHelper()); modules.add(new ElytraAtSpawn()); modules.add(new ElytraGlobal()); modules.add(new ElytraOnCeiling()); - modules.add(new NewChunksListener()); modules.add(new ElytraPacketFly()); - modules.add(new ElytraTimer()); /* Illegals */ diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java index ae0d068af..59ed8f198 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java @@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.world.ChunkLoadEvent; import java.util.HashSet; import java.util.List; @@ -84,6 +85,28 @@ public void disable() { if (scheduledTask != null) scheduledTask.cancel(); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onChunkLoad(ChunkLoadEvent event) { + if (event.isNewChunk()) return; + + int droppedItemCount = 0; + + for (Entity entity : event.getChunk().getEntities()) { + if (entity.getType() != EntityType.DROPPED_ITEM) continue; + + droppedItemCount++; + if (droppedItemCount <= maxDroppedItemsPerChunk) continue; + if (usingWhitelist && whitelistedItems.contains(((Item) entity).getItemStack().getType())) continue; + + entity.getScheduler().run(plugin, kill -> { + entity.remove(); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed dropped item at" + + " x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() + + " in world " + entity.getWorld().getName() + ", because reached limit of " + maxDroppedItemsPerChunk); + }, null); + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onItemDrop(ItemSpawnEvent event) { int droppedItemCount = 0; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java index 9cfde74d2..48c544391 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java @@ -22,7 +22,6 @@ public class ElytraAtSpawn implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private static final double tolerance = 0.02; private final int spawn_Radius; private final double spawn_SpeedOldChunks, spawn_SpeedNewChunks, spawn_DenyElytraTPS; private final boolean teleportBack, spawn_shouldCheckPermission, spawn_DenyElytra, spawn_DenyOnLowTPS, @@ -77,12 +76,13 @@ public void disable() { private void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (!player.isGliding()) return; + if (!event.hasExplicitlyChangedPosition()) return; if (spawn_shouldCheckPermission && player.hasPermission("anarchyexploitfixes.bypass")) return; Location playerLoc = player.getLocation(); if (LocationUtil.getFlatDistanceTo00(playerLoc) > spawn_Radius) return; if (spawn_DenyElytra) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -93,7 +93,7 @@ private void onPlayerMove(PlayerMoveEvent event) { } if (spawn_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event) <= spawn_DenyElytraTPS) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -116,12 +116,12 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - double flySpeed = LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + double flySpeed = ElytraHelper.getInstance().getBlocksPerTick(event); - if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) { + if (ElytraHelper.getInstance().isInNewChunks(player.getUniqueId())) { // Speed New Chunks - if (flySpeed > spawn_SpeedNewChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > spawn_SpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -162,8 +162,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Speed Old Chunks - if (flySpeed > spawn_SpeedOldChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > spawn_SpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -204,4 +204,6 @@ private void onPlayerMove(PlayerMoveEvent event) { } } } + + } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java index 1762c5cd9..6d03fe0a1 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java @@ -22,7 +22,6 @@ public class ElytraGlobal implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private static final double tolerance = 0.02; private final int spawn_Radius; private final double global_SpeedOldChunks, global_SpeedNewChunks, global_BurstSpeedOldChunks, global_BurstSpeedNewChunks, global_BurstOldChunk_TPS, global_BurstNewChunk_TPS, global_DenyElytraTPS; @@ -87,13 +86,14 @@ public void disable() { private void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (!player.isGliding()) return; + if (!event.hasExplicitlyChangedPosition()) return; if (global_shouldCheckPermission && player.hasPermission("anarchyexploitfixes.bypass")) return; Location playerLoc = player.getLocation(); if (spawn_SettingsEnabled && LocationUtil.getFlatDistanceTo00(playerLoc) <= spawn_Radius) return; if (ceiling_SettingsEnabled && LocationUtil.isNetherCeiling(playerLoc)) return; if (global_DenyElytra) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -101,8 +101,8 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - if (global_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) <= global_DenyElytraTPS) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (global_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event) <= global_DenyElytraTPS) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -125,14 +125,14 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - double flySpeed = LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + double flySpeed = ElytraHelper.getInstance().getBlocksPerTick(event); - if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) { + if (ElytraHelper.getInstance().isInNewChunks(player.getUniqueId())) { // Speed New Chunks - if (global_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= global_BurstNewChunk_TPS) { + if (global_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event) >= global_BurstNewChunk_TPS) { // Burst Speed New Chunks - if (flySpeed > global_BurstSpeedNewChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > global_BurstSpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -170,9 +170,9 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed New Chunks - if (flySpeed > global_SpeedNewChunks+tolerance) { + if (flySpeed > global_SpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { // too fast - if (teleportBack) player.teleportAsync(event.getFrom()); + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -215,10 +215,10 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Speed Old Chunks - if (global_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= global_BurstOldChunk_TPS) { + if (global_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event) >= global_BurstOldChunk_TPS) { // Burst Speed Old Chunks - if (flySpeed > global_BurstSpeedOldChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > global_BurstSpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -256,8 +256,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed Old Chunks - if (flySpeed > global_SpeedOldChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > global_SpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); 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 new file mode 100755 index 000000000..66e1a4907 --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java @@ -0,0 +1,153 @@ +package me.moomoo.anarchyexploitfixes.modules.elytra; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +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; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.world.ChunkLoadEvent; + +import java.time.Duration; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public class ElytraHelper implements AnarchyExploitFixesModule, Listener { + private static ElytraHelper instance; + private final AnarchyExploitFixes plugin; + private final Set PLAYERS_NEAR_NEW_CHUNKS; + private final Cache PLAYER_SPEEDS_MOVE_EVENT; + private final Cache PLAYER_SPEEDS_INTERVAL; + private final Cache LAST_GLIDE_POS; + public static final double SPEED_TOLERANCE = 0.02; + private final int checkIntervalTicks; + private final boolean doIntervalCheck; + + public ElytraHelper() { + instance = this; + this.plugin = AnarchyExploitFixes.getInstance(); + this.PLAYERS_NEAR_NEW_CHUNKS = new HashSet<>(plugin.getServer().getOnlinePlayers().size()); + Config config = AnarchyExploitFixes.getConfiguration(); + this.doIntervalCheck = config.getBoolean("elytra.patch-generic-speedhacks.enable", true, + "Patches speed-limit bypass using generic speedhacks (Timer) by additionally checking player position every x ticks"); + final int tickInterval = config.getInt("elytra.patch-generic-speedhacks.check-interval-in-ticks", 10, + "Lower value means more accuracy but also more overhead."); + this.checkIntervalTicks = tickInterval > 0 ? tickInterval : 1; + final Duration cacheTime = Duration.ofMillis(FastMath.max(1000, tickInterval * 50L)); + this.PLAYER_SPEEDS_MOVE_EVENT = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); + this.PLAYER_SPEEDS_INTERVAL = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); + this.LAST_GLIDE_POS = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); + } + + public static ElytraHelper getInstance() { + return instance; + } + + @Override + public String name() { + return "elytra-helper"; + } + + @Override + public String category() { + return "elytra"; + } + + @Override + public void enable() { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean shouldEnable() { + Config config = AnarchyExploitFixes.getConfiguration(); + return config.getBoolean("elytra.elytra-speed.Global-Settings.enable", true) + || config.getBoolean("elytra.elytra-speed.At-Spawn.enable", false) + || config.getBoolean("elytra.elytra-speed.Nether-Ceiling.enable", true); + } + + @Override + public void disable() { + HandlerList.unregisterAll(this); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onPlayerJoin(PlayerJoinEvent event) { + if (!doIntervalCheck) return; + + Player player = event.getPlayer(); + player.getScheduler().runAtFixedRate(plugin, watchSpeed -> { + if (player.isGliding()) { + Location currentLocation = player.getLocation(); + Location lastLocation = LAST_GLIDE_POS.getIfPresent(player.getUniqueId()); + if (lastLocation == null) + lastLocation = currentLocation; + PLAYER_SPEEDS_INTERVAL.put(player.getUniqueId(), LocationUtil.getFlatDistance(lastLocation, currentLocation) / checkIntervalTicks); + LAST_GLIDE_POS.put(player.getUniqueId(), currentLocation); + } + }, null, checkIntervalTicks, checkIntervalTicks); + } + + @EventHandler(priority = EventPriority.LOW) + private void onPlayerMove(PlayerMoveEvent event) { + if (event.getPlayer().isGliding()) { + PLAYER_SPEEDS_MOVE_EVENT.put(event.getPlayer().getUniqueId(), LocationUtil.getFlatDistance(event.getFrom(), event.getTo())); + } + } + + private double getFlatDistanceInChunks(Chunk chunk, Location location) { + return FastMath.hypot(chunk.getX() - location.getBlockX() >> 4, chunk.getZ() - location.getBlockZ() >> 4); + } + + @EventHandler(priority = EventPriority.LOW) + private void onChunkLoad(ChunkLoadEvent event) { + for (Player player : event.getWorld().getPlayers()) { + if (this.getFlatDistanceInChunks(event.getChunk(), player.getLocation()) < player.getViewDistance()) { + if (event.isNewChunk()) { + PLAYERS_NEAR_NEW_CHUNKS.add(player.getUniqueId()); + } else { + PLAYERS_NEAR_NEW_CHUNKS.remove(player.getUniqueId()); + } + } + } + } + + public Location getFrom(PlayerMoveEvent event) { + final Location lastGlidePos = LAST_GLIDE_POS.getIfPresent(event.getPlayer().getUniqueId()); + return lastGlidePos != null ? lastGlidePos : event.getFrom(); + } + + public double getBlocksPerTick(PlayerMoveEvent event) { + final Double speedInterval = PLAYER_SPEEDS_INTERVAL.getIfPresent(event.getPlayer().getUniqueId()); + final Double speedMoveEvent = PLAYER_SPEEDS_MOVE_EVENT.getIfPresent(event.getPlayer().getUniqueId()); + + if (speedInterval != null) { + if (speedMoveEvent != null) { + return FastMath.max(speedInterval, speedMoveEvent); + } else { + return speedInterval; + } + } else { + if (speedMoveEvent != null) { + return speedMoveEvent; + } else { + return LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + } + } + } + + public boolean isInNewChunks(UUID playerUniqueId) { + return PLAYERS_NEAR_NEW_CHUNKS.contains(playerUniqueId); + } +} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java index a5e5fa1a7..f1cbc7561 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java @@ -22,7 +22,6 @@ public class ElytraOnCeiling implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private static final double tolerance = 0.02; private final int spawn_Radius; private final double ceiling_SpeedOldChunks, ceiling_SpeedNewChunks, ceiling_BurstSpeedOldChunks, ceiling_BurstSpeedNewChunks, ceiling_BurstOldChunk_TPS, ceiling_BurstNewChunk_TPS, ceiling_DenyElytraTPS; @@ -84,13 +83,14 @@ public void disable() { private void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (!player.isGliding()) return; + if (!event.hasExplicitlyChangedPosition()) return; if (ceiling_shouldCheckPermission && player.hasPermission("anarchyexploitfixes.bypass")) return; Location playerLoc = player.getLocation(); if (!LocationUtil.isNetherCeiling(playerLoc)) return; if (spawn_SettingsEnabled && LocationUtil.getFlatDistanceTo00(playerLoc) <= spawn_Radius) return; if (ceiling_DenyElytra) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -98,8 +98,8 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - if (ceiling_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) <= ceiling_DenyElytraTPS) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (ceiling_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event) <= ceiling_DenyElytraTPS) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -122,14 +122,14 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - double flySpeed = LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + double flySpeed = ElytraHelper.getInstance().getBlocksPerTick(event); - if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) { + if (ElytraHelper.getInstance().isInNewChunks(player.getUniqueId())) { // Speed New Chunks - if (ceiling_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= ceiling_BurstNewChunk_TPS) { + if (ceiling_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event) >= ceiling_BurstNewChunk_TPS) { // Burst Speed New Chunks - if (flySpeed > ceiling_BurstSpeedNewChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > ceiling_BurstSpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -167,8 +167,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed New Chunks - if (flySpeed > ceiling_SpeedNewChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > ceiling_SpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -211,10 +211,10 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Speed Old Chunks - if (ceiling_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= ceiling_BurstOldChunk_TPS) { + if (ceiling_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event) >= ceiling_BurstOldChunk_TPS) { // Burst Speed Old Chunks - if (flySpeed > ceiling_BurstSpeedOldChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > ceiling_BurstSpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); @@ -252,8 +252,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed Old Chunks - if (flySpeed > ceiling_SpeedOldChunks+tolerance) { - if (teleportBack) player.teleportAsync(event.getFrom()); + if (flySpeed > ceiling_SpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleportAsync(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java old mode 100755 new mode 100644 index 121f14e11..d5e5b6649 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java @@ -1,9 +1,12 @@ package me.moomoo.anarchyexploitfixes.modules.elytra; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -13,25 +16,31 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import java.util.HashMap; +import java.time.Duration; import java.util.UUID; public class ElytraPacketFly implements AnarchyExploitFixesModule, Listener { - private final AnarchyExploitFixes plugin; - private final HashMap elytraOpenCounts = new HashMap<>(); - private final int maxElytraOpensPer10s; + private final Cache elytraOpenCounts; + private final int maxElytraOpensPerTime; private final boolean shouldCheckPermission, notify, kickPlayer; public ElytraPacketFly() { shouldEnable(); - this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("elytra.packet-elytra-fly.patch-packet-elytra-fly","Patches the future/rusherhack/kamiblue 2b2t elytra fly exploit"); + config.addComment("elytra.packet-elytra-fly.patch-packet-elytra-fly", + "Patches the future/rusherhack/kamiblue 2b2t elytra fly exploit"); this.shouldCheckPermission = config.getBoolean("elytra.packet-elytra-fly.use-bypass-permission", false); - this.maxElytraOpensPer10s = config.getInt("elytra.packet-elytra-fly.max-elytra-opens-per-10-seconds", 25, "Will only allow players to go about 85km/h on kami blue, and won't even work on rusherhack. Recommended to not go lower as there could be false positives."); - this.notify = config.getBoolean("elytra.packet-elytra-fly.notify-player-to-disable-packetfly", true, "Configure message in lang folder."); - this.kickPlayer = config.getBoolean("elytra.packet-elytra-fly.kick-instead-of-remove-elytra", false, "If enabled, the plugin will not remove elytra from the player, but simply disconnect from the server."); + this.maxElytraOpensPerTime = config.getInt("elytra.packet-elytra-fly.max-elytra-opens-per-time", 25, + "Will only allow players to go about 85km/h."); + this.elytraOpenCounts = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds( + config.getInt("elytra.packet-elytra-fly.time-in-seconds", 10, + "Will only allow players to go about 85km/h.") + )).build(); + this.notify = config.getBoolean("elytra.packet-elytra-fly.notify-player-to-disable-packetfly", true, + "Configure message in lang folder."); + this.kickPlayer = config.getBoolean("elytra.packet-elytra-fly.kick-instead-of-remove-elytra", false, + "If enabled, player will be kicked instead of dropping their elytra."); } @Override @@ -46,12 +55,13 @@ public String category() { @Override public void enable() { + AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); plugin.getServer().getPluginManager().registerEvents(this, plugin); } @Override public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("elytra.packet-elytra-fly.patch-packet-elytra-fly", true); + return AnarchyExploitFixes.getConfiguration().getBoolean("elytra.packet-elytra-fly.patch-packet-elytra-fly", false); } @Override @@ -61,36 +71,38 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onElytraOpen(EntityToggleGlideEvent event) { - if (!(event.getEntity() instanceof Player player)) return; - if (shouldCheckPermission && player.hasPermission("anarchyexploitfixes.bypass")) return; - final UUID playerUniqueID = player.getUniqueId(); - - if (!elytraOpenCounts.containsKey(playerUniqueID)) { - elytraOpenCounts.put(playerUniqueID, 1); - plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin, - decay -> elytraOpenCounts.put(playerUniqueID, elytraOpenCounts.get(playerUniqueID) - 1), 200L); - return; - } + if (event.getEntityType() != EntityType.PLAYER) return; + if (shouldCheckPermission && event.getEntity().hasPermission("anarchyexploitfixes.bypass")) return; - if (elytraOpenCounts.get(playerUniqueID) <= maxElytraOpensPer10s) { - elytraOpenCounts.merge(playerUniqueID, 1, Integer::sum); - plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin, - decay -> elytraOpenCounts.put(playerUniqueID, elytraOpenCounts.get(playerUniqueID) - 1), 200L); + Integer elytraOpens = elytraOpenCounts.getIfPresent(event.getEntity().getUniqueId()); + + if (elytraOpens == null) { + elytraOpenCounts.put(event.getEntity().getUniqueId(), 1); return; } - if (kickPlayer) { - player.getScheduler().run(plugin, kick -> player.kick(AnarchyExploitFixes.getLang(player.locale()).elytra_disablePacketElytraFly), null); - } else { - player.getScheduler().run(plugin, removeElytra -> { - PlayerInventory playerInv = player.getInventory(); - if (MaterialUtil.isElytra(playerInv.getChestplate())) { - ItemStack elytra = playerInv.getChestplate(); - playerInv.setChestplate(null); - player.getWorld().dropItemNaturally(player.getLocation(), elytra); - } - if (notify) player.sendMessage(AnarchyExploitFixes.getLang(player.locale()).elytra_disablePacketElytraFly); - }, null); + elytraOpens++; + + if (elytraOpens > maxElytraOpensPerTime) { + Player player = (Player) event.getEntity(); + if (kickPlayer) { + player.getScheduler().run(AnarchyExploitFixes.getInstance(), + kick -> player.kick(AnarchyExploitFixes.getLang(player.locale()).elytra_disablePacketElytraFly), null); + return; + } + + PlayerInventory playerInv = player.getInventory(); + if (MaterialUtil.isElytra(playerInv.getChestplate())) { + ItemStack elytra = playerInv.getChestplate(); + playerInv.setChestplate(null); + player.getWorld().dropItemNaturally(player.getLocation(), elytra); + } + + if (notify) { + player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).elytra_disablePacketElytraFly); + } } + + elytraOpenCounts.put(event.getEntity().getUniqueId(), elytraOpens); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraTimer.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraTimer.java deleted file mode 100755 index 73b913ba2..000000000 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraTimer.java +++ /dev/null @@ -1,93 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.elytra; - -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.config.Config; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.time.Duration; -import java.util.UUID; - -public class ElytraTimer implements AnarchyExploitFixesModule, Listener { - - private final Cache elytraMoveCounts; - private final int maxMoveEventsPerTime; - private final boolean shouldCheckPermission, notify, kickPlayer; - - public ElytraTimer() { - shouldEnable(); - Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("elytra.timer-elytra-fly.patch-timer-elytra-fly", """ - Attempts to patch aef speed limit bypass using timer.\s - This isn't the best implementation and its recommended to just adjust values in NCP."""); - this.shouldCheckPermission = config.getBoolean("elytra.timer-elytra-fly.use-bypass-permission", false); - this.elytraMoveCounts = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis( - config.getInt("elytra.timer-elytra-fly.time-in-millis", 10000, "10000 Millis = 10 Secs") - )).build(); - this.maxMoveEventsPerTime = config.getInt("elytra.timer-elytra-fly.max-elytra-move-events-per-time", 250, - "Experimental value. Please adjust."); - this.notify = config.getBoolean("elytra.timer-elytra-fly.notify-player-to-disable-timer", true, - "Configure message in lang folder."); - this.kickPlayer = config.getBoolean("elytra.timer-elytra-fly.kick-player", false, - "If enabled, will disconnect player from the server."); - } - - @Override - public String name() { - return "timer-elytra-fly"; - } - - @Override - public String category() { - return "elytra"; - } - - @Override - public void enable() { - AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("elytra.timer-elytra-fly.patch-timer-elytra-fly", false); - } - - @Override - public void disable() { - HandlerList.unregisterAll(this); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onElytraFly(PlayerMoveEvent event) { - Player player = event.getPlayer(); - if (!player.isGliding()) return; - if (shouldCheckPermission && player.hasPermission("anarchyexploitfixes.bypass")) return; - - Integer moveCounts = elytraMoveCounts.getIfPresent(player.getUniqueId()); - - if (moveCounts == null) { - elytraMoveCounts.put(player.getUniqueId(), 1); - return; - } - - moveCounts++; - - if (moveCounts > maxMoveEventsPerTime) { - if (kickPlayer) { - player.getScheduler().run(AnarchyExploitFixes.getInstance(), - kick -> player.kick(AnarchyExploitFixes.getLang(player.locale()).elytra_disable_timer), null); - } else { - event.setCancelled(true); - if (notify) player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).elytra_disable_timer); - } - } - } -} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/NewChunksListener.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/NewChunksListener.java deleted file mode 100755 index 5d5c6d0aa..000000000 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/NewChunksListener.java +++ /dev/null @@ -1,72 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.elytra; - -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.config.Config; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import org.bukkit.Chunk; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.world.ChunkLoadEvent; - -import java.awt.*; - -public class NewChunksListener implements AnarchyExploitFixesModule, Listener { - - private final AnarchyExploitFixes plugin; - - public NewChunksListener() { - this.plugin = AnarchyExploitFixes.getInstance(); - } - - @Override - public String name() { - return null; - } - - @Override - public String category() { - return null; - } - - @Override - public void enable() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public boolean shouldEnable() { - Config config = AnarchyExploitFixes.getConfiguration(); - return ( - config.getBoolean("elytra.elytra-speed.Global-Settings.enable", true) - || config.getBoolean("elytra.elytra-speed.At-Spawn.enable", false) - || config.getBoolean("elytra.elytra-speed.Nether-Ceiling.enable", true) - ); - } - - @Override - public void disable() { - HandlerList.unregisterAll(this); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onChunkLoad(ChunkLoadEvent event) { - Chunk chunk = event.getChunk(); - final Point chunkLoc = new Point(chunk.getX() * 16, chunk.getZ() * 16); - if (event.isNewChunk()) { - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - if (chunkLoc.distance(new Point(onlinePlayer.getLocation().getBlockX(), onlinePlayer.getLocation().getBlockZ())) < 250) { - plugin.NEW_CHUNK_PLAYERS.add(onlinePlayer.getUniqueId()); - } - } - } else { - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - if (chunkLoc.distance(new Point(onlinePlayer.getLocation().getBlockX(), onlinePlayer.getLocation().getBlockZ())) < 250) { - plugin.NEW_CHUNK_PLAYERS.remove(onlinePlayer.getUniqueId()); - } - } - } - } -} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java index b5af3275b..94850cfcf 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java @@ -32,8 +32,7 @@ public class AnarchyExploitFixes extends JavaPlugin { private static boolean foundProtocolLib; public TPSCache tpsCache; - public final HashSet CONNECTION_MSG_TOGGLE = new HashSet<>(); - public final HashSet NEW_CHUNK_PLAYERS = new HashSet<>(); + public final Set CONNECTION_MSG_TOGGLE = new HashSet<>(); @Override public void onEnable() { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java index 2d392b1d9..55f0b1ba8 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -106,12 +106,11 @@ static void reloadModules() { /* Elytra */ + modules.add(new ElytraHelper()); modules.add(new ElytraAtSpawn()); modules.add(new ElytraGlobal()); modules.add(new ElytraOnCeiling()); - modules.add(new NewChunksListener()); modules.add(new ElytraPacketFly()); - modules.add(new ElytraTimer()); /* Illegals */ diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java index 4c84c6d06..0bbd24862 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java @@ -1,6 +1,5 @@ package me.moomoo.anarchyexploitfixes.modules.elytra; -import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XSound; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; @@ -9,7 +8,6 @@ import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -22,13 +20,11 @@ public class ElytraAtSpawn implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private static final double tolerance = 0.02; - private final int spawn_Radius; + private final Sound notifyDing; private final double spawn_SpeedOldChunks, spawn_SpeedNewChunks, spawn_DenyElytraTPS; + private final int spawn_Radius; private final boolean teleportBack, spawn_shouldCheckPermission, spawn_DenyElytra, spawn_DenyOnLowTPS, spawn_AlsoRemoveElytraOnLowTPS, showActionbarMsgs, displayChunkInfo, playNotifSound; - private final Material elytra; - private final Sound notifyDing; public ElytraAtSpawn() { shouldEnable(); @@ -48,7 +44,6 @@ public ElytraAtSpawn() { this.spawn_DenyOnLowTPS = config.getBoolean("elytra.elytra-speed.At-Spawn.deny-elytra-on-low-TPS", true); this.spawn_DenyElytraTPS = config.getDouble("elytra.elytra-speed.At-Spawn.deny-elytra-TPS", 10.0); this.spawn_AlsoRemoveElytraOnLowTPS = config.getBoolean("elytra.elytra-speed.At-Spawn.also-remove-elytra-on-low-TPS", true); - this.elytra = XMaterial.ELYTRA.parseMaterial(); this.notifyDing = XSound.ENTITY_EXPERIENCE_ORB_PICKUP.parseSound(); } @@ -81,7 +76,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (LocationUtil.getFlatDistanceTo00(playerLoc) > spawn_Radius) return; if (spawn_DenyElytra) { - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -93,7 +88,7 @@ private void onPlayerMove(PlayerMoveEvent event) { } if (spawn_DenyOnLowTPS && plugin.tpsCache.getTPS() <= spawn_DenyElytraTPS) { - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -113,13 +108,13 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - double flySpeed = LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + double flySpeed = ElytraHelper.getInstance().getBlocksPerTick(event); - if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) { + if (ElytraHelper.getInstance().isInNewChunks(player.getUniqueId())) { // Speed New Chunks - if (flySpeed > spawn_SpeedNewChunks+tolerance) { + if (flySpeed > spawn_SpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { // too fast - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -157,9 +152,9 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Speed Old Chunks - if (flySpeed > spawn_SpeedOldChunks+tolerance) { + if (flySpeed > spawn_SpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { // too fast - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java index df5b5fd9b..9a6d84be9 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java @@ -1,6 +1,5 @@ package me.moomoo.anarchyexploitfixes.modules.elytra; -import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XSound; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; @@ -9,7 +8,6 @@ import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -22,16 +20,14 @@ public class ElytraGlobal implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private static final double tolerance = 0.02; - private final int spawn_Radius; + private final Sound notifyDing; private final double global_SpeedOldChunks, global_SpeedNewChunks, global_BurstSpeedOldChunks, global_BurstSpeedNewChunks, global_BurstOldChunk_TPS, global_BurstNewChunk_TPS, global_DenyElytraTPS; + private final int spawn_Radius; private final boolean showActionbarMsgs, displayChunkInfo, playNotifSound, teleportBack, global_shouldCheckPermission, spawn_SettingsEnabled, ceiling_SettingsEnabled, global_DenyElytra, global_EnableBursting, global_DenyOnLowTPS, global_AlsoRemoveOnLowTPS; - private final Material elytra; - private final Sound notifyDing; - + public ElytraGlobal() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); @@ -58,7 +54,6 @@ public ElytraGlobal() { this.global_DenyOnLowTPS = config.getBoolean("elytra.elytra-speed.Global-Settings.deny-elytra-on-low-TPS", true); this.global_DenyElytraTPS = config.getDouble("elytra.elytra-speed.Global-Settings.deny-elytra-TPS", 12.0); this.global_AlsoRemoveOnLowTPS = config.getBoolean("elytra.elytra-speed.Global-Settings.also-remove-elytra-on-low-TPS", true); - this.elytra = XMaterial.ELYTRA.parseMaterial(); this.notifyDing = XSound.ENTITY_EXPERIENCE_ORB_PICKUP.parseSound(); } @@ -92,7 +87,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (ceiling_SettingsEnabled && LocationUtil.isNetherCeiling(playerLoc)) return; if (global_DenyElytra) { - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -101,7 +96,7 @@ private void onPlayerMove(PlayerMoveEvent event) { } if (global_DenyOnLowTPS && plugin.tpsCache.getTPS() <= global_DenyElytraTPS) { - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -122,15 +117,15 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - double flySpeed = LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + double flySpeed = ElytraHelper.getInstance().getBlocksPerTick(event); - if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) { + if (ElytraHelper.getInstance().isInNewChunks(player.getUniqueId())) { // Speed New Chunks if (global_EnableBursting && plugin.tpsCache.getTPS() >= global_BurstNewChunk_TPS) { // Burst Speed New Chunks - if (flySpeed > global_BurstSpeedNewChunks+tolerance) { + if (flySpeed > global_BurstSpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { // Too fast - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -165,8 +160,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed New Chunks - if (flySpeed > global_SpeedNewChunks+tolerance) { - if (teleportBack) player.teleport(event.getFrom()); + if (flySpeed > global_SpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -208,8 +203,8 @@ private void onPlayerMove(PlayerMoveEvent event) { // Speed Old Chunks if (global_EnableBursting && plugin.tpsCache.getTPS() >= global_BurstOldChunk_TPS) { // Burst Speed Old Chunks - if (flySpeed > global_BurstSpeedOldChunks+tolerance) { - if (teleportBack) player.teleport(event.getFrom()); + if (flySpeed > global_BurstSpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -244,8 +239,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed Old Chunks - if (flySpeed > global_SpeedOldChunks+tolerance) { - if (teleportBack) player.teleport(event.getFrom()); + if (flySpeed > global_SpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); 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 new file mode 100755 index 000000000..0136bccc7 --- /dev/null +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraHelper.java @@ -0,0 +1,143 @@ +package me.moomoo.anarchyexploitfixes.modules.elytra; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +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; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.world.ChunkLoadEvent; + +import java.time.Duration; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public class ElytraHelper implements AnarchyExploitFixesModule, Listener, Runnable { + private static ElytraHelper instance; + private final AnarchyExploitFixes plugin; + private final Cache PLAYER_SPEEDS_MOVE_EVENT; + private final Cache PLAYER_SPEEDS_INTERVAL; + private final Cache LAST_GLIDE_POS; + private final Set PLAYERS_NEAR_NEW_CHUNKS; + public static final double SPEED_TOLERANCE = 0.02; + private final int checkIntervalTicks; + private final boolean doIntervalCheck; + + public ElytraHelper() { + instance = this; + this.plugin = AnarchyExploitFixes.getInstance(); + this.PLAYERS_NEAR_NEW_CHUNKS = new HashSet<>(plugin.getServer().getOnlinePlayers().size()); + Config config = AnarchyExploitFixes.getConfiguration(); + this.doIntervalCheck = config.getBoolean("elytra.patch-generic-speedhacks.enable", true, + "Patches speed-limit bypass using generic speedhacks (Timer) by additionally checking player position every x ticks"); + final int tickInterval = config.getInt("elytra.patch-generic-speedhacks.check-interval-in-ticks", 10, + "Lower value means more accuracy but also more overhead."); + this.checkIntervalTicks = tickInterval > 0 ? tickInterval : 1; + final Duration cacheTime = Duration.ofMillis(FastMath.max(1000, tickInterval * 50L)); + this.PLAYER_SPEEDS_MOVE_EVENT = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); + this.PLAYER_SPEEDS_INTERVAL = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); + this.LAST_GLIDE_POS = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); + } + + public static ElytraHelper getInstance() { + return instance; + } + + @Override + public String name() { + return "elytra-helper"; + } + + @Override + public String category() { + return "elytra"; + } + + @Override + public void enable() { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + if (doIntervalCheck) plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this, checkIntervalTicks, checkIntervalTicks); + } + + @Override + public boolean shouldEnable() { + Config config = AnarchyExploitFixes.getConfiguration(); + return config.getBoolean("elytra.elytra-speed.Global-Settings.enable", true) + || config.getBoolean("elytra.elytra-speed.At-Spawn.enable", false) + || config.getBoolean("elytra.elytra-speed.Nether-Ceiling.enable", true); + } + + @Override + public void run() { + for (Player player : plugin.getServer().getOnlinePlayers()) { + if (player.isGliding()) { + Location currentLocation = player.getLocation(); + Location lastLocation = LAST_GLIDE_POS.getIfPresent(player.getUniqueId()); + if (lastLocation == null) lastLocation = currentLocation; + PLAYER_SPEEDS_INTERVAL.put(player.getUniqueId(), LocationUtil.getFlatDistance(lastLocation, currentLocation) / checkIntervalTicks); + LAST_GLIDE_POS.put(player.getUniqueId(), currentLocation); + } + } + } + + @EventHandler(priority = EventPriority.LOW) + private void onPlayerMove(PlayerMoveEvent event) { + if (event.getPlayer().isGliding()) { + PLAYER_SPEEDS_MOVE_EVENT.put(event.getPlayer().getUniqueId(), LocationUtil.getFlatDistance(event.getFrom(), event.getTo())); + } + } + + private double getFlatDistanceInChunks(Chunk chunk, Location location) { + return FastMath.hypot(chunk.getX() - location.getBlockX() >> 4, chunk.getZ() - location.getBlockZ() >> 4); + } + + @EventHandler(priority = EventPriority.LOW) + private void onChunkLoad(ChunkLoadEvent event) { + for (Player player : event.getWorld().getPlayers()) { + if (this.getFlatDistanceInChunks(event.getChunk(), player.getLocation()) < player.getViewDistance()) { + if (event.isNewChunk()) { + PLAYERS_NEAR_NEW_CHUNKS.add(player.getUniqueId()); + } else { + PLAYERS_NEAR_NEW_CHUNKS.remove(player.getUniqueId()); + } + } + } + } + + public Location getFrom(PlayerMoveEvent event) { + final Location lastGlidePos = LAST_GLIDE_POS.getIfPresent(event.getPlayer().getUniqueId()); + return lastGlidePos != null ? lastGlidePos : event.getFrom(); + } + + public double getBlocksPerTick(PlayerMoveEvent event) { + final Double speedInterval = PLAYER_SPEEDS_INTERVAL.getIfPresent(event.getPlayer().getUniqueId()); + final Double speedMoveEvent = PLAYER_SPEEDS_MOVE_EVENT.getIfPresent(event.getPlayer().getUniqueId()); + + if (speedInterval != null) { + if (speedMoveEvent != null) { + return FastMath.max(speedInterval, speedMoveEvent); + } else { + return speedInterval; + } + } else { + if (speedMoveEvent != null) { + return speedMoveEvent; + } else { + return LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + } + } + } + + public boolean isInNewChunks(UUID playerUniqueId) { + return PLAYERS_NEAR_NEW_CHUNKS.contains(playerUniqueId); + } +} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java index a22d8a47e..719e92f97 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java @@ -1,6 +1,5 @@ package me.moomoo.anarchyexploitfixes.modules.elytra; -import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XSound; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; @@ -9,7 +8,6 @@ import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -22,14 +20,13 @@ public class ElytraOnCeiling implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private static final double tolerance = 0.02; - private final int spawn_Radius; + private final Sound notifyDing; private final double ceiling_SpeedOldChunks, ceiling_SpeedNewChunks, ceiling_BurstSpeedOldChunks, ceiling_BurstSpeedNewChunks, ceiling_BurstOldChunk_TPS, ceiling_BurstNewChunk_TPS, ceiling_DenyElytraTPS; + private final int spawn_Radius; private final boolean showActionbarMsgs, displayChunkInfo, playNotifSound, teleportBack, ceiling_shouldCheckPermission, spawn_SettingsEnabled, ceiling_DenyElytra, ceiling_EnableBursting, ceiling_DenyOnLowTPS, ceiling_AlsoRemoveOnLowTPS; - private final Material elytra; - private final Sound notifyDing; + public ElytraOnCeiling() { shouldEnable(); @@ -55,7 +52,6 @@ public ElytraOnCeiling() { this.ceiling_DenyOnLowTPS = config.getBoolean("elytra.elytra-speed.Nether-Ceiling.deny-elytra-on-low-TPS", true); this.ceiling_DenyElytraTPS = config.getDouble("elytra.elytra-speed.Nether-Ceiling.deny-elytra-TPS", 12.0); this.ceiling_AlsoRemoveOnLowTPS = config.getBoolean("elytra.elytra-speed.Nether-Ceiling.also-remove-elytra-on-low-TPS", true); - this.elytra = XMaterial.ELYTRA.parseMaterial(); this.notifyDing = XSound.ENTITY_EXPERIENCE_ORB_PICKUP.parseSound(); } @@ -89,7 +85,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (spawn_SettingsEnabled && LocationUtil.getFlatDistanceTo00(playerLoc) <= spawn_Radius) return; if (ceiling_DenyElytra) { - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -98,7 +94,7 @@ private void onPlayerMove(PlayerMoveEvent event) { } if (ceiling_DenyOnLowTPS && plugin.tpsCache.getTPS() <= ceiling_DenyElytraTPS) { - if (teleportBack) player.teleport(event.getFrom()); + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -119,14 +115,14 @@ private void onPlayerMove(PlayerMoveEvent event) { return; } - double flySpeed = LocationUtil.getFlatDistance(event.getFrom(), event.getTo()); + double flySpeed = ElytraHelper.getInstance().getBlocksPerTick(event); - if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) { + if (ElytraHelper.getInstance().isInNewChunks(player.getUniqueId())) { // Speed New Chunks if (ceiling_EnableBursting && plugin.tpsCache.getTPS() >= ceiling_BurstNewChunk_TPS) { // Burst Speed New Chunks - if (flySpeed > ceiling_BurstSpeedNewChunks+tolerance) { - if (teleportBack) player.teleport(event.getFrom()); + if (flySpeed > ceiling_BurstSpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -161,8 +157,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed New Chunks - if (flySpeed > ceiling_SpeedNewChunks+tolerance) { - if (teleportBack) player.teleport(event.getFrom()); + if (flySpeed > ceiling_SpeedNewChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -204,8 +200,8 @@ private void onPlayerMove(PlayerMoveEvent event) { // Speed Old Chunks if (ceiling_EnableBursting && plugin.tpsCache.getTPS() >= ceiling_BurstOldChunk_TPS) { // Burst Speed Old Chunks - if (flySpeed > ceiling_BurstSpeedOldChunks+tolerance) { - if (teleportBack) player.teleport(event.getFrom()); + if (flySpeed > ceiling_BurstSpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); @@ -240,8 +236,8 @@ private void onPlayerMove(PlayerMoveEvent event) { } } else { // Normal Speed Old Chunks - if (flySpeed > ceiling_SpeedOldChunks+tolerance) { - if (teleportBack) player.teleport(event.getFrom()); + if (flySpeed > ceiling_SpeedOldChunks + ElytraHelper.SPEED_TOLERANCE) { + if (teleportBack) player.teleport(ElytraHelper.getInstance().getFrom(event)); else event.setCancelled(true); if (playNotifSound) player.playSound(player.getEyeLocation(), notifyDing, 1.0F, 1.0F); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java index b7785bb55..ca500b1d3 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java @@ -1,11 +1,13 @@ package me.moomoo.anarchyexploitfixes.modules.elytra; -import com.cryptomorin.xseries.XMaterial; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; -import org.bukkit.Material; +import org.apache.commons.math3.util.FastMath; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -14,27 +16,31 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import java.util.HashMap; +import java.time.Duration; import java.util.UUID; public class ElytraPacketFly implements AnarchyExploitFixesModule, Listener { - private final AnarchyExploitFixes plugin; - private final HashMap elytraOpenCounts = new HashMap<>(); - private final int maxElytraOpensPer10s; + private final Cache elytraOpenCounts; + private final int maxElytraOpensPerTime; private final boolean shouldCheckPermission, notify, kickPlayer; - private final Material elytra; public ElytraPacketFly() { shouldEnable(); - this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("elytra.packet-elytra-fly.patch-packet-elytra-fly","Patches the future/rusherhack/kamiblue 2b2t elytra fly exploit"); + config.addComment("elytra.packet-elytra-fly.patch-packet-elytra-fly", + "Patches the future/rusherhack/kamiblue 2b2t elytra fly exploit"); this.shouldCheckPermission = config.getBoolean("elytra.packet-elytra-fly.use-bypass-permission", false); - this.maxElytraOpensPer10s = config.getInt("elytra.packet-elytra-fly.max-elytra-opens-per-10-seconds", 25, "Will only allow players to go about 85km/h on kami blue, and won't even work on rusherhack. Recommended to not go lower as there could be false positives."); - this.notify = config.getBoolean("elytra.packet-elytra-fly.notify-player-to-disable-packetfly", true, "Configure message in lang folder."); - this.kickPlayer = config.getBoolean("elytra.packet-elytra-fly.kick-instead-of-remove-elytra", false, "If enabled, the plugin will not remove elytra from the player, but simply disconnect from the server."); - this.elytra = XMaterial.ELYTRA.parseMaterial(); + this.maxElytraOpensPerTime = config.getInt("elytra.packet-elytra-fly.max-elytra-opens-per-time", 25, + "Will only allow players to go about 85km/h."); + this.elytraOpenCounts = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds( + FastMath.max(config.getInt("elytra.packet-elytra-fly.time-in-seconds", 10, + "Will only allow players to go about 85km/h."), 1) + )).build(); + this.notify = config.getBoolean("elytra.packet-elytra-fly.notify-player-to-disable-packetfly", true, + "Configure message in lang folder."); + this.kickPlayer = config.getBoolean("elytra.packet-elytra-fly.kick-instead-of-remove-elytra", false, + "If enabled, player will be kicked instead of dropping their elytra."); } @Override @@ -55,40 +61,42 @@ public void enable() { @Override public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("elytra.packet-elytra-fly.patch-packet-elytra-fly", true); + return AnarchyExploitFixes.getConfiguration().getBoolean("elytra.packet-elytra-fly.patch-packet-elytra-fly", false); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onElytraOpen(EntityToggleGlideEvent event) { - if (!(event.getEntity() instanceof Player)) return; - Player player = (Player) event.getEntity(); - if (shouldCheckPermission && player.hasPermission("anarchyexploitfixes.bypass")) return; - final UUID playerUniqueID = player.getUniqueId(); - - if (!elytraOpenCounts.containsKey(playerUniqueID)) { - elytraOpenCounts.put(playerUniqueID, 1); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, - () -> elytraOpenCounts.put(playerUniqueID, elytraOpenCounts.get(playerUniqueID) - 1), 200L); - return; - } + if (event.getEntityType() != EntityType.PLAYER) return; + if (shouldCheckPermission && event.getEntity().hasPermission("anarchyexploitfixes.bypass")) return; + + Integer elytraOpens = elytraOpenCounts.getIfPresent(event.getEntity().getUniqueId()); - if (elytraOpenCounts.get(playerUniqueID) <= maxElytraOpensPer10s) { - elytraOpenCounts.merge(playerUniqueID, 1, Integer::sum); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, - () -> elytraOpenCounts.put(playerUniqueID, elytraOpenCounts.get(playerUniqueID) - 1), 200L); + if (elytraOpens == null) { + elytraOpenCounts.put(event.getEntity().getUniqueId(), 1); return; } - if (kickPlayer) { - player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disablePacketElytraFly); - } else { + elytraOpens++; + + if (elytraOpens > maxElytraOpensPerTime) { + Player player = (Player) event.getEntity(); + if (kickPlayer) { + player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disablePacketElytraFly); + return; + } + PlayerInventory playerInv = player.getInventory(); if (MaterialUtil.isElytra(playerInv.getChestplate())) { ItemStack elytra = playerInv.getChestplate(); playerInv.setChestplate(null); player.getWorld().dropItemNaturally(player.getLocation(), elytra); } - if (notify) player.sendMessage(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disablePacketElytraFly); + + if (notify) { + player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disablePacketElytraFly); + } } + + elytraOpenCounts.put(event.getEntity().getUniqueId(), elytraOpens); } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraTimer.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraTimer.java deleted file mode 100755 index bd1bccee7..000000000 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraTimer.java +++ /dev/null @@ -1,86 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.elytra; - -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.config.Config; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.time.Duration; -import java.util.UUID; - -public class ElytraTimer implements AnarchyExploitFixesModule, Listener { - - private final Cache elytraMoveCounts; - private final int maxMoveEventsPerTime; - private final boolean shouldCheckPermission, notify, kickPlayer; - - public ElytraTimer() { - shouldEnable(); - Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("elytra.timer-elytra-fly.patch-timer-elytra-fly", - "Attempts to patch aef speed limit bypass using timer.\n" - + "This isn't the best implementation and its recommended to just adjust values in NCP."); - this.shouldCheckPermission = config.getBoolean("elytra.timer-elytra-fly.use-bypass-permission", false); - this.elytraMoveCounts = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis( - config.getInt("elytra.timer-elytra-fly.time-in-millis", 10000, "10000 Millis = 10 Secs") - )).build(); - this.maxMoveEventsPerTime = config.getInt("elytra.timer-elytra-fly.max-elytra-move-events-per-time", 250, - "Experimental value. Please adjust."); - this.notify = config.getBoolean("elytra.timer-elytra-fly.notify-player-to-disable-timer", true, - "Configure message in lang folder."); - this.kickPlayer = config.getBoolean("elytra.timer-elytra-fly.kick-player", false, - "If enabled, will disconnect player from the server."); - } - - @Override - public String name() { - return "timer-elytra-fly"; - } - - @Override - public String category() { - return "elytra"; - } - - @Override - public void enable() { - AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("elytra.timer-elytra-fly.patch-timer-elytra-fly", false); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onElytraFly(PlayerMoveEvent event) { - Player player = event.getPlayer(); - if (!player.isGliding()) return; - if (shouldCheckPermission && player.hasPermission("anarchyexploitfixes.bypass")) return; - - Integer moveCounts = elytraMoveCounts.getIfPresent(player.getUniqueId()); - - if (moveCounts == null) { - elytraMoveCounts.put(player.getUniqueId(), 1); - return; - } - - moveCounts++; - - if (moveCounts > maxMoveEventsPerTime) { - if (kickPlayer) { - player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disable_timer); - } else { - event.setCancelled(true); - if (notify) player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disable_timer); - } - } - } -} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/NewChunksListener.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/NewChunksListener.java deleted file mode 100755 index aa1bc7475..000000000 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/NewChunksListener.java +++ /dev/null @@ -1,66 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.elytra; - -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.config.Config; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import org.bukkit.Chunk; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.world.ChunkLoadEvent; - -import java.awt.*; - -public class NewChunksListener implements AnarchyExploitFixesModule, Listener { - - private final AnarchyExploitFixes plugin; - - public NewChunksListener() { - this.plugin = AnarchyExploitFixes.getInstance(); - } - - @Override - public String name() { - return null; - } - - @Override - public String category() { - return null; - } - - @Override - public void enable() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public boolean shouldEnable() { - Config config = AnarchyExploitFixes.getConfiguration(); - return ( - config.getBoolean("elytra.elytra-speed.Global-Settings.enable", true) - || config.getBoolean("elytra.elytra-speed.At-Spawn.enable", false) - || config.getBoolean("elytra.elytra-speed.Nether-Ceiling.enable", true) - ); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onChunkLoad(ChunkLoadEvent event) { - Chunk chunk = event.getChunk(); - Point chunkLoc = new Point(chunk.getX() * 16, chunk.getZ() * 16); - if (event.isNewChunk()) { - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - if (chunkLoc.distance(new Point(onlinePlayer.getLocation().getBlockX(), onlinePlayer.getLocation().getBlockZ())) < 250) { - plugin.NEW_CHUNK_PLAYERS.add(onlinePlayer.getUniqueId()); - } - } - } else { - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - if (chunkLoc.distance(new Point(onlinePlayer.getLocation().getBlockX(), onlinePlayer.getLocation().getBlockZ())) < 250) { - plugin.NEW_CHUNK_PLAYERS.remove(onlinePlayer.getUniqueId()); - } - } - } - } -}