From 4c61acf14a0a03793c88e0e2620038716a329833 Mon Sep 17 00:00:00 2001 From: xGinko Date: Sat, 17 Feb 2024 03:13:51 +0100 Subject: [PATCH] revisit a bunch of modules for some improvements --- .../commandwhitelist/CommandWhitelist.java | 20 +++--- .../modules/chunklimits/BlockLimit.java | 31 +++++---- .../chunklimits/CustomEntityLimit.java | 13 ++-- .../modules/chunklimits/DroppedItemLimit.java | 16 ++--- .../modules/chunklimits/ExpBottleLimit.java | 6 +- .../chunklimits/FallingBlockLimit.java | 23 ++++--- .../modules/chunklimits/MinecartLimit.java | 11 ++-- .../chunklimits/NonLivingEntityLimit.java | 23 +++---- .../modules/chunklimits/VehicleLimit.java | 19 ++---- .../modules/chunklimits/VillagerLimit.java | 63 +++++++++--------- .../modules/combat/AnchorAuraDelay.java | 3 +- .../modules/combat/BedAuraDelay.java | 3 +- .../modules/combat/CrystalAuraDelay.java | 3 +- .../combat/CrystalAuraHotbarSwitchDelay.java | 50 +++++++------- .../modules/combat/PistonAuraDelay.java | 2 +- .../dupepreventions/ChestsOnEntities.java | 3 +- .../CloseEntityInventoryOnChunkUnload.java | 3 +- .../dupepreventions/EndPortalDupe.java | 9 +-- .../lagpreventions/FallingBlockStasis.java | 11 ++-- .../lagpreventions/InventoryActionLag.java | 21 +++--- .../modules/lagpreventions/LeverSpam.java | 52 +++++++-------- .../lagpreventions/LiquidUpdateLag.java | 15 ++--- .../lagpreventions/PathfindingLimits.java | 33 +++++----- .../lagpreventions/SnowballExploit.java | 8 ++- .../lagpreventions/TargetDistanceLimit.java | 29 +++++---- .../lowtpsphysics/BlockPhysics.java | 3 +- .../lowtpsphysics/Explosions.java | 3 +- .../lowtpsphysics/Noteblocks.java | 3 +- .../lowtpsphysics/Redstone.java | 3 +- .../modules/patches/WorldChangeCrash.java | 7 +- .../modules/preventions/NetherRoof.java | 4 +- .../anarchyexploitfixes/utils/ChunkUtil.java | 16 ----- .../utils/CommandUtil.java | 6 -- .../utils/LocationUtil.java | 4 ++ .../commandwhitelist/CommandWhitelist.java | 20 +++--- .../modules/chunklimits/BlockLimit.java | 30 +++++---- .../chunklimits/CustomEntityLimit.java | 13 ++-- .../modules/chunklimits/DroppedItemLimit.java | 16 ++--- .../modules/chunklimits/ExpBottleLimit.java | 6 +- .../chunklimits/FallingBlockLimit.java | 15 ++--- .../modules/chunklimits/MinecartLimit.java | 11 ++-- .../chunklimits/NonLivingEntityLimit.java | 23 +++---- .../modules/chunklimits/VehicleLimit.java | 19 ++---- .../modules/chunklimits/VillagerLimit.java | 65 ++++++++++--------- .../modules/combat/AnchorAuraDelay.java | 3 +- .../modules/combat/BedAuraDelay.java | 3 +- .../modules/combat/CrystalAuraDelay.java | 3 +- .../combat/CrystalAuraHotbarSwitchDelay.java | 50 +++++++------- .../modules/combat/PistonAuraDelay.java | 2 +- .../CloseEntityInventoryOnChunkUnload.java | 3 +- .../dupepreventions/EndPortalDupe.java | 9 +-- .../lagpreventions/FallingBlockStasis.java | 20 +++--- .../lagpreventions/InventoryActionLag.java | 18 ++--- .../modules/lagpreventions/LeverSpam.java | 52 +++++++-------- .../lagpreventions/LiquidUpdateLag.java | 30 ++++----- .../lagpreventions/PathfindingLimits.java | 33 +++++----- .../lagpreventions/SnowballExploit.java | 16 ++--- .../lagpreventions/TargetDistanceLimit.java | 30 +++++---- .../lowtpsphysics/BlockPhysics.java | 3 +- .../lowtpsphysics/Explosions.java | 3 +- .../lowtpsphysics/Noteblocks.java | 3 +- .../lowtpsphysics/Redstone.java | 3 +- .../crashexploits/EndGatewayCrash.java | 5 +- .../crashexploits/MultipleEnderdragons.java | 2 +- .../RedstoneOnTrapdoorCrash.java | 32 ++++----- .../crashexploits/WorldChangeCrash.java | 7 +- .../modules/preventions/NetherRoof.java | 3 +- .../anarchyexploitfixes/utils/ChunkUtil.java | 16 ----- .../utils/CommandUtil.java | 6 -- .../utils/LocationUtil.java | 4 ++ 70 files changed, 531 insertions(+), 565 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chat/commandwhitelist/CommandWhitelist.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chat/commandwhitelist/CommandWhitelist.java index bfdc515cb..8c9952143 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chat/commandwhitelist/CommandWhitelist.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chat/commandwhitelist/CommandWhitelist.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Set; import java.util.logging.Level; +import java.util.stream.Collectors; public class CommandWhitelist implements AnarchyExploitFixesModule, Listener { @@ -28,8 +29,7 @@ public class CommandWhitelist implements AnarchyExploitFixesModule, Listener { * Code was mainly only implemented into AEF by xGinko. */ - private final Set allowedCommands = new HashSet<>(); - private final Set bannedSubCommands; + private final Set allowedCommands, bannedSubCommands; private final boolean shouldUseProtocolLib, shouldLog; public CommandWhitelist() { @@ -42,12 +42,14 @@ public CommandWhitelist() { "Will show logs when a command was denied."); this.shouldUseProtocolLib = config.getBoolean("chat.command-whitelist.use-protocollib", false, "Enable only if you have problems with the regular commandwhitelist. Otherwise not recommended to use."); - config.getList("chat.command-whitelist.whitelisted-commands", List.of( - "help", "vote", "kill", "discord", "togglechat", "toggleconnectionmsgs", "toggletells", "togglewhispering", "toggleprivatemsgs", - "ignore", "ignorelist", "ignorehard", "toggledeathmsg", "dmt", "worldstats", "stats", "tps", "msg", "whisper", "w", "m", "t", - "pm", "tell", "r", "reply", "last" - ), "Add all commands you want your players to be able to access (without the '/'). Not case sensitive." - ).forEach(configuredAllowedCmd -> this.allowedCommands.add(configuredAllowedCmd.toLowerCase())); + this.allowedCommands = config.getList("chat.command-whitelist.whitelisted-commands", List.of( + "help", "vote", "kill", "discord", "togglechat", "toggleconnectionmsgs", "toggletells", "togglewhispering", "toggleprivatemsgs", + "ignore", "ignorelist", "ignorehard", "toggledeathmsg", "dmt", "worldstats", "stats", "tps", "msg", "whisper", "w", "m", "t", + "pm", "tell", "r", "reply", "last" + ), "Add all commands you want your players to be able to access (without the '/'). Not case sensitive.") + .stream() + .map(String::toLowerCase) + .collect(Collectors.toSet()); bannedSubCommands = new HashSet<>(config.getList("chat.command-whitelist.blacklisted-subcommands", List.of( "help about", "vote List", "vote Best", "vote Total", "worldstats reload", "stats reload" ))); @@ -123,7 +125,7 @@ private void onCommandPreProcess(PlayerCommandPreprocessEvent event) { @EventHandler(priority = EventPriority.NORMAL) private void onInitialTabCompleteListSend(PlayerCommandSendEvent event) { if (event.getPlayer().hasPermission("anarchyexploitfixes.commandwhitelistbypass")) return; - event.getCommands().removeIf((cmd) -> !allowedCommands.contains(cmd)); + event.getCommands().removeIf(cmd -> !allowedCommands.contains(cmd)); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java index 3fc258228..a6bec21ac 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java @@ -3,14 +3,13 @@ import io.github.thatsmusic99.configurationmaster.api.ConfigSection; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import me.moomoo.anarchyexploitfixes.utils.ChunkUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; +import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockPlaceEvent; import java.util.HashMap; @@ -166,20 +165,28 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onBlockPlace(BlockPlaceEvent event) { final Material placedType = event.getBlock().getType(); - if (!blockLimits.containsKey(placedType)) return; - - if (ChunkUtil.getMaterialCount(event.getBlock().getChunk(), placedType) > blockLimits.get(placedType)) { + if ( + blockLimits.containsKey(placedType) + && exceedsPerChunkLimit(placedType, blockLimits.get(placedType), event.getBlock().getChunk()) + ) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onBlockPlace(BlockCanBuildEvent event) { - final Material placedType = event.getMaterial(); - if (!blockLimits.containsKey(placedType)) return; - - if (ChunkUtil.getMaterialCount(event.getBlock().getChunk(), placedType) > blockLimits.get(placedType)) { - event.setBuildable(false); + private boolean exceedsPerChunkLimit(Material material, int limit, Chunk chunk) { + final int minY = chunk.getWorld().getMinHeight(); + final int maxY = chunk.getWorld().getMaxHeight(); + int count = 0; + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + for (int y = minY; y < maxY; y++) { + if (chunk.getBlock(x, y, z).getType() == material) { + count++; + if (count > limit) return true; + } + } + } } + return false; } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.java index 48c3a931f..1a8474741 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.java @@ -5,6 +5,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -173,9 +174,9 @@ private void onSpawn(EntitySpawnEvent event) { entity.getScheduler().run(plugin, kill -> { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowedPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxAllowedPerChunk); }, null); } } @@ -201,9 +202,9 @@ private void run() { entity.getScheduler().run(plugin, kill -> { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowedPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxAllowedPerChunk); }, null); } } 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 59ed8f198..8f4b4c232 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 @@ -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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.Material; @@ -100,9 +101,8 @@ private void onChunkLoad(ChunkLoadEvent event) { 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); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed dropped item at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxDroppedItemsPerChunk); }, null); } } @@ -120,9 +120,8 @@ private void onItemDrop(ItemSpawnEvent event) { 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); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed dropped item at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxDroppedItemsPerChunk); }, null); } } @@ -144,9 +143,8 @@ private void run() { 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); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed dropped item at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxDroppedItemsPerChunk); }, null); } }); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java index 8a71a25dd..782f04aeb 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -68,9 +69,8 @@ private void onExpBottle(ExpBottleEvent event) { if (expBottleCount > maxExpBottlePerChunk) { entity.getScheduler().run(plugin, kill -> { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed XP-Bottle " - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxExpBottlePerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed XP-Bottle at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxExpBottlePerChunk); }, null); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java index 4a209180d..9e57c4c16 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import me.moomoo.anarchyexploitfixes.utils.models.ExpiringSet; import org.bukkit.Chunk; @@ -34,9 +35,9 @@ public FallingBlockLimit() { this.logIsEnabled = config.getBoolean("chunk-limits.falling-block-limit.log", false); this.maxFallingGravityBlockPerChunk = config.getInt("chunk-limits.falling-block-limit.max-falling-gravitiy-blocks-per-chunk", 60, "Removes any falling block if there is more than x blocks (actively) falling in a chunk."); - final long chunkCheckDelay = config.getInt("chunk-limits.falling-block-limit.chunk-check-delay-in-ticks", 20, """ + final long chunkCheckDelay = Math.max(config.getInt("chunk-limits.falling-block-limit.chunk-check-delay-in-ticks", 20, """ Delay in ticks until the same chunk can be checked again.\s - Prevents overchecking, because a physics event can be called multiple times for the same chunk.""") * 50L; + Prevents overchecking, because a physics event can be called multiple times for the same chunk."""), 1) * 50L; this.checkedChunks = new ExpiringSet<>(Duration.ofMillis(chunkCheckDelay)); } @@ -83,12 +84,11 @@ private void onBlockPhysics(BlockPhysicsEvent event) { } } - if (logIsEnabled && removed_falling) LogUtil.moduleLog(Level.INFO, name(), - "Removed falling blocks at " + event.getSourceBlock().getLocation() - + ", because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk" - ); - checkedChunks.add(chunk); + + if (logIsEnabled && removed_falling) LogUtil.moduleLog(Level.INFO, name(), + "Removed falling blocks at " + LocationUtil.toString(event.getSourceBlock().getLocation()) + + " because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk"); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -110,11 +110,10 @@ private void onChangeBlock(EntityChangeBlockEvent event) { } } - if (logIsEnabled && removed_falling) LogUtil.moduleLog(Level.INFO, name(), - "Removed falling blocks at " + event.getBlock().getLocation() - + ", because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk" - ); - checkedChunks.add(chunk); + + if (logIsEnabled && removed_falling) LogUtil.moduleLog(Level.INFO, name(), + "Removed falling blocks at " + LocationUtil.toString(event.getBlock().getLocation()) + + " because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk"); } } \ No newline at end of file diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java index ee385187b..133a4d049 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java @@ -5,6 +5,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -34,8 +35,8 @@ public MinecartLimit() { "Limit the amount of minecarts to prevent lag."); this.logIsEnabled = config.getBoolean("chunk-limits.minecart-limit.log-removals", false); this.maxMinecartsPerChunk = config.getInt("chunk-limits.minecart-limit.max-minecarts-per-chunk", 25); - this.checkPeriod = config.getInt("chunk-limits.minecart-limit.check-period-in-ticks", 400, - "200 ticks = 10 seconds."); + this.checkPeriod = Math.max(config.getInt("chunk-limits.minecart-limit.check-period-in-ticks", 400, + "200 ticks = 10 seconds."), 1); } @Override @@ -80,8 +81,7 @@ private void onCreate(VehicleCreateEvent event) { entity.getScheduler().run(plugin, kill -> { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed minecart " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxMinecartsPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxMinecartsPerChunk); }, null); } } @@ -103,8 +103,7 @@ private void run() { entity.getScheduler().run(plugin, kill -> { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed minecart " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxMinecartsPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxMinecartsPerChunk); }, null); } }); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.java index 50b76460e..9561aef3c 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -23,7 +24,7 @@ public class NonLivingEntityLimit implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private final Set NON_LIVING_TYPES = new HashSet<>(); + private static final Set NON_LIVING_TYPES = new HashSet<>(); private ScheduledTask scheduledTask; private final long checkPeriod; private final int maxNonLivingEntities; @@ -84,9 +85,9 @@ private void onSpawn(EntitySpawnEvent event) { event.setCancelled(true); entity.getScheduler().run(plugin, kill -> { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxNonLivingEntities); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); }, null); continue; @@ -101,9 +102,9 @@ private void onSpawn(EntitySpawnEvent event) { event.setCancelled(true); entity.getScheduler().run(plugin, kill -> { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxNonLivingEntities); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); }, null); } } @@ -127,8 +128,8 @@ private void run() { entity.getScheduler().run(plugin, kill -> { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " - + entity.getType() + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxNonLivingEntities); + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); }, null); continue; @@ -143,8 +144,8 @@ private void run() { entity.getScheduler().run(plugin, kill -> { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " - + entity.getType() + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxNonLivingEntities); + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); }, null); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java index 1aa339807..a4071215d 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java @@ -6,6 +6,7 @@ import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.EntityUtil; +import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -89,8 +90,7 @@ private void onCreate(VehicleCreateEvent event) { entity.getScheduler().run(plugin, kill -> { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxVehiclesPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); }, null); continue; @@ -104,8 +104,7 @@ private void onCreate(VehicleCreateEvent event) { entity.getScheduler().run(plugin, kill -> { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxVehiclesPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); }, null); } } @@ -128,10 +127,8 @@ private void run() { entity.getScheduler().run(plugin, kill -> { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " - + entity.getType() + " at x:" + entity.getLocation().getX() - + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxVehiclesPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); }, null); continue; @@ -144,10 +141,8 @@ private void run() { entity.getScheduler().run(plugin, kill -> { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " - + entity.getType() + " at x:" + entity.getLocation().getX() - + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxVehiclesPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); }, null); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.java index 4eb45e7b5..397541554 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -18,11 +19,12 @@ import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class VillagerLimit implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private final List removalPriority = new ArrayList<>(); + private final List removalPriority; private ScheduledTask scheduledTask; private final long checkPeriod; private final int maxVillagersPerChunk; @@ -32,23 +34,26 @@ public VillagerLimit() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - this.maxVillagersPerChunk = config.getInt("chunk-limits.entity-limits.villager-limit.max-villagers-per-chunk", 25); + this.maxVillagersPerChunk = Math.max(config.getInt("chunk-limits.entity-limits.villager-limit.max-villagers-per-chunk", 25), 1); this.logIsEnabled = config.getBoolean("chunk-limits.entity-limits.villager-limit.log-removals", false); - this.checkPeriod = config.getInt("chunk-limits.entity-limits.villager-limit.check-period-in-ticks", 600, - "check all chunks every x ticks."); - config.getList("chunk-limits.entity-limits.villager-limit.removal-priority", List.of( - "NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER", - "FLETCHER", "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN" - ), "Professions that are in the top of the list are going to be scheduled for removal first." - ).forEach(configuredProfession -> { - try { - Villager.Profession profession = Villager.Profession.valueOf(configuredProfession); - this.removalPriority.add(profession); - } catch (IllegalArgumentException e) { - LogUtil.moduleLog(Level.WARNING, name(), "Villager profession '"+configuredProfession+"' not recognized. " + - "Make sure you're using the correct profession enums for your Version."); - } - }); + this.checkPeriod = Math.max(config.getInt("chunk-limits.entity-limits.villager-limit.check-period-in-ticks", 600, + "check all chunks every x ticks."), 1); + this.removalPriority = config.getList("chunk-limits.entity-limits.villager-limit.removal-priority", Arrays.asList( + "NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER", "FLETCHER", + "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN"), + "Professions that are in the top of the list are going to be scheduled for removal first.") + .stream() + .map(configuredProfession -> { + try { + return Villager.Profession.valueOf(configuredProfession); + } catch (IllegalArgumentException e) { + LogUtil.moduleLog(Level.WARNING, name(), "Villager profession '"+configuredProfession+"' not recognized. " + + "Make sure youre using the correct profession enums for your Version."); + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } @Override @@ -88,10 +93,10 @@ private void onCreateSpawn(CreatureSpawnEvent event) { private void run() { for (World world : plugin.getServer().getWorlds()) { for (Chunk chunk : world.getLoadedChunks()) { - if (!chunk.isEntitiesLoaded()) continue; - - plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), - checkVillagers -> this.checkVillagersInChunk(chunk)); + if (chunk.isEntitiesLoaded()) { + plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), + checkVillagers -> this.checkVillagersInChunk(chunk)); + } } } } @@ -106,25 +111,23 @@ private void checkVillagersInChunk(Chunk chunk) { } // Check if there are more villagers in that chunk than allowed - int amount_over_the_limit = villagers_in_chunk.size() - maxVillagersPerChunk; + final int amount_over_the_limit = villagers_in_chunk.size() - maxVillagersPerChunk; if (amount_over_the_limit <= 0) return; // Sort villager list by profession priority - villagers_in_chunk.sort(Comparator.comparingInt(this::getProfessionPriority)); + villagers_in_chunk.sort(Comparator.comparingInt(villager -> { + final Villager.Profession profession = villager.getProfession(); + return removalPriority.contains(profession) ? removalPriority.indexOf(profession) : Integer.MAX_VALUE; + })); // Remove prioritized villagers that are too many for (int i = 0; i < amount_over_the_limit; i++) { Villager villager = villagers_in_chunk.get(i); villager.getScheduler().run(plugin, kill -> { villager.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Removing villager of profession type '"+villager.getProfession()+"' at "+villager.getLocation()); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed villager with profession '" + + villager.getProfession() + "' at " + LocationUtil.toString(villager.getLocation())); }, null); } } - - private int getProfessionPriority(Villager villager) { - Villager.Profession profession = villager.getProfession(); - return removalPriority.contains(profession) ? removalPriority.indexOf(profession) : Integer.MAX_VALUE; - } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java index d71726988..b9d5f8278 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java @@ -20,8 +20,7 @@ public class AnchorAuraDelay implements AnarchyExploitFixesModule, Listener { - private final ExpiringSet placeCooldowns; - private final ExpiringSet breakCooldowns; + private final ExpiringSet placeCooldowns, breakCooldowns; private final long placeDelayMillis, breakDelayMillis; private final boolean updateInv; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java index 6bb183c9c..41b849e44 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java @@ -18,8 +18,7 @@ public class BedAuraDelay implements AnarchyExploitFixesModule, Listener { - private final ExpiringSet breakCooldowns; - private final ExpiringSet placeCooldowns; + private final ExpiringSet breakCooldowns, placeCooldowns; private final long breakDelayMillis, placeDelayMillis; public BedAuraDelay() { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java index a38be474f..1ddc3de5f 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java @@ -21,8 +21,7 @@ public class CrystalAuraDelay implements AnarchyExploitFixesModule, Listener { - private final ExpiringSet breakCooldowns; - private final ExpiringSet placeCooldowns; + private final ExpiringSet breakCooldowns, placeCooldowns; private final long breakDelayMillis, placeDelayMillis; private final boolean updateInv; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java index c818031c6..df4cc99f8 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java @@ -17,18 +17,19 @@ import java.time.Duration; import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class CrystalAuraHotbarSwitchDelay implements AnarchyExploitFixesModule, Listener { private final ExpiringSet hotbarItemSwitchCooldowns; - private final Set blacklistedSwitchMaterials = new HashSet<>(); + private final Set blacklistedSwitchMaterials; private final boolean onlyForSpecificMaterials; public CrystalAuraHotbarSwitchDelay() { shouldEnable(); Config config = AnarchyExploitFixes.getConfiguration(); - final long switchAwayFromCrystalsDelayInMillis = config.getInt("combat.crystal-aura.hotbar-switch-delay.delay-in-ticks", 2, - "Delay between switching from an end crystal to other items in hotbar") * 50L; + final long switchAwayFromCrystalsDelayInMillis = Math.max(config.getInt("combat.crystal-aura.hotbar-switch-delay.delay-in-ticks", 2, + "Delay between switching from an end crystal to other items in hotbar"), 1) * 50L; this.hotbarItemSwitchCooldowns = new ExpiringSet<>(Duration.ofMillis(switchAwayFromCrystalsDelayInMillis)); this.onlyForSpecificMaterials = config.getBoolean("combat.crystal-aura.hotbar-switch-delay.only-delay-specific-materials", true, "Only delay when switched to specific materials"); @@ -42,14 +43,18 @@ public CrystalAuraHotbarSwitchDelay() { "PURPLE_BED", "RED_BED", "WHITE_BED", "YELLOW_BED", "CROSSBOW", "NETHERITE_SWORD", "NETHERITE_AXE" ); - for (String configuredMaterial : config.getList("combat.crystal-aura.hotbar-switch-delay.delayed-specific-materials", defaults)) { - try { - Material bannedMaterial = Material.valueOf(configuredMaterial); - blacklistedSwitchMaterials.add(bannedMaterial); - } catch (IllegalArgumentException e) { - LogUtil.materialNotRecognized(Level.WARNING, name(), configuredMaterial); - } - } + this.blacklistedSwitchMaterials = config.getList("combat.crystal-aura.hotbar-switch-delay.delayed-specific-materials", defaults) + .stream() + .map(configuredMaterial -> { + try { + return Material.valueOf(configuredMaterial); + } catch (IllegalArgumentException e) { + LogUtil.materialNotRecognized(Level.WARNING, name(), configuredMaterial); + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toCollection(HashSet::new)); } @Override @@ -81,20 +86,21 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onHotbarSwitch(PlayerItemHeldEvent event) { final UUID playerUniqueId = event.getPlayer().getUniqueId(); - if (hotbarItemSwitchCooldowns.contains(playerUniqueId)) { - final PlayerInventory playerInventory = event.getPlayer().getInventory(); + if (!hotbarItemSwitchCooldowns.contains(playerUniqueId)) { + hotbarItemSwitchCooldowns.add(playerUniqueId); + return; + } - final ItemStack previouslyHeldItem = playerInventory.getItem(event.getPreviousSlot()); - if (previouslyHeldItem == null || previouslyHeldItem.getType() != Material.END_CRYSTAL) return; + final PlayerInventory playerInventory = event.getPlayer().getInventory(); - final ItemStack newHeldItem = playerInventory.getItem(event.getNewSlot()); - if (newHeldItem == null || newHeldItem.getType() == Material.END_CRYSTAL) return; + final ItemStack previouslyHeldItem = playerInventory.getItem(event.getPreviousSlot()); + if (previouslyHeldItem == null || previouslyHeldItem.getType() != Material.END_CRYSTAL) return; - if (onlyForSpecificMaterials && !blacklistedSwitchMaterials.contains(newHeldItem.getType())) return; + final ItemStack newHeldItem = playerInventory.getItem(event.getNewSlot()); + if (newHeldItem == null || newHeldItem.getType() == Material.END_CRYSTAL) return; - event.setCancelled(true); - } else { - hotbarItemSwitchCooldowns.add(playerUniqueId); - } + if (onlyForSpecificMaterials && !blacklistedSwitchMaterials.contains(newHeldItem.getType())) return; + + event.setCancelled(true); } } \ No newline at end of file diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java index 2ccae56d5..d4acc89ee 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java @@ -23,7 +23,7 @@ public PistonAuraDelay() { Config config = AnarchyExploitFixes.getConfiguration(); config.addComment("combat.crystal-aura.piston-aura-delay.enable", "Rate-limits pistons that extend into crystals"); this.pistonsPushingCrystals = new ExpiringSet<>(Duration.ofMillis( - config.getInt("combat.crystal-aura.piston-aura-delay.piston-extend-delay-in-ticks", 40) * 50L)); + Math.max(config.getInt("combat.crystal-aura.piston-aura-delay.piston-extend-delay-in-ticks", 40), 1) * 50L)); } @Override diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/ChestsOnEntities.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/ChestsOnEntities.java index 91a104c92..4fed9eadb 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/ChestsOnEntities.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/ChestsOnEntities.java @@ -16,7 +16,8 @@ public class ChestsOnEntities implements AnarchyExploitFixesModule, Listener { public ChestsOnEntities() { this.plugin = AnarchyExploitFixes.getInstance(); shouldEnable(); - AnarchyExploitFixes.getConfiguration().addComment("dupe-preventions.prevent-chests-on-living-entities", "Prevents a dupe exploit involving donkeys."); + AnarchyExploitFixes.getConfiguration().addComment("dupe-preventions.prevent-chests-on-living-entities", + "Prevents a dupe exploit involving donkeys."); } @Override diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java index f0069a829..3e91b4d24 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java @@ -18,7 +18,8 @@ public class CloseEntityInventoryOnChunkUnload implements AnarchyExploitFixesMod public CloseEntityInventoryOnChunkUnload() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); - AnarchyExploitFixes.getConfiguration().addComment("dupe-preventions.close-entity-inventories-on-chunk-unload", "Closes open inventories of all entities that are in a chunk that will be unloaded."); + AnarchyExploitFixes.getConfiguration().addComment("dupe-preventions.close-entity-inventories-on-chunk-unload", + "Closes open inventories of all entities that are in a chunk that will be unloaded."); } @Override diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java index 97c553cf8..cab8cdc75 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java @@ -49,10 +49,11 @@ public void disable() { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) private void onEntityDamage(EntityDamageEvent event) { - if ( - event.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK - && event.getCause() != EntityDamageEvent.DamageCause.FALL - ) return; + switch (event.getCause()) { + case ENTITY_ATTACK, FALL -> { + return; + } + } if (!(event.getEntity() instanceof LivingEntity livingEntity)) return; if (livingEntity.getWorld().getEnvironment() != World.Environment.THE_END) return; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.java index 81aff56ce..75a9f074b 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.World; import org.bukkit.entity.Entity; @@ -28,8 +29,8 @@ public FallingBlockStasis() { this.logIsEnabled = config.getBoolean("lag-preventions.prevent-falling-block-stasis-exploit.log", false); this.max_alive_time = config.getInt("lag-preventions.prevent-falling-block-stasis-exploit.falling-blocks-max-alive-time-in-ticks", 300, "(20 ticks = 1 second)"); - this.check_period_in_ticks = config.getInt("lag-preventions.prevent-falling-block-stasis-exploit.check-period-in-seconds", 12, - "How frequently we should check for all projectile's alive time") * 20L; + this.check_period_in_ticks = Math.max(config.getInt("lag-preventions.prevent-falling-block-stasis-exploit.check-period-in-seconds", 12, + "How frequently we should check for all projectile's alive time"), 1) * 20L; } @Override @@ -65,9 +66,9 @@ private void run() { entity.getScheduler().run(plugin, killIfOld -> { if (entity.getTicksLived() > max_alive_time) { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed falling block at x:" - + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + " in " + entity.getWorld().getName() + " because it was alive for more than " + max_alive_time + " ticks."); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed falling block at " + + LocationUtil.toString(entity.getLocation()) + + " because it has been alive for " + entity.getTicksLived() + " ticks (max= " + max_alive_time + ")."); } }, null); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.java index cf4fbcdbe..b2a7c41fb 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Location; import org.bukkit.block.Block; @@ -43,9 +44,9 @@ public InventoryActionLag() { this.blockInventoryClicks = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); this.entityInventoryClicks = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); Map defaults = new HashMap<>(); - defaults.put("COLLECT_TO_CURSOR", 5); - defaults.put("MOVE_TO_OTHER_INVENTORY", 5); - defaults.put("HOTBAR_SWAP", 10); + defaults.put("COLLECT_TO_CURSOR", 15); + defaults.put("MOVE_TO_OTHER_INVENTORY", 8); + defaults.put("HOTBAR_SWAP", 30); ConfigSection section = config.getConfigSection("lag-preventions.prevent-inventory-action-lag.click-action-limits", defaults, """ Use correct enums from: https://jd.papermc.io/paper/1.20/org/bukkit/event/inventory/InventoryAction.html.\s Format is: InventoryClickAction: AllowedClicksPerTime"""); @@ -105,11 +106,8 @@ private void onInventoryClick(InventoryClickEvent event) { if (clickActionCounter > clickActionLimits.get(event.getAction())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled spammy inventory click of type "+event.getAction().name()+" at" + - " x:" + block.getLocation().getX() + "," + - " y:" + block.getLocation().getY() + "," + - " z:" + block.getLocation().getZ() + - " in world: " + block.getLocation().getWorld().getName()); + "Cancelled spammy inventory click of type " + event.getAction().name() + " at " + + LocationUtil.toString(block.getLocation())); } recordedClicks.put(event.getAction(), clickActionCounter); @@ -129,11 +127,8 @@ private void onInventoryClick(InventoryClickEvent event) { if (clickActionCounter > clickActionLimits.get(event.getAction())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled spammy inventory click of type "+event.getAction().name()+" at" + - " x:" + entity.getLocation().getX() + "," + - " y:" + entity.getLocation().getY() + "," + - " z:" + entity.getLocation().getZ() + - " in world: " + entity.getLocation().getWorld().getName()); + "Cancelled spammy inventory click of type " + event.getAction().name() + " at " + + LocationUtil.toString(entity.getLocation())); } recordedClicks.put(event.getAction(), clickActionCounter); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java index 9d07a5221..040ea48a9 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java @@ -73,42 +73,38 @@ private void onInteract(PlayerInteractEvent event) { final Location leverLoc = clicked.getLocation(); Integer activationCount = leverLocationCooldowns.getIfPresent(leverLoc); + if (activationCount == null) activationCount = 0; - if (activationCount == null) { - leverLocationCooldowns.put(leverLoc, 1); - } else { - activationCount++; - leverLocationCooldowns.put(leverLoc, activationCount); - if (activationCount > leverUsageLimit) { - event.setCancelled(true); - if (shouldKickPlayer) { - player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); - return; - } - if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); - } + activationCount++; + leverLocationCooldowns.put(leverLoc, activationCount); + + if (activationCount > leverUsageLimit) { + event.setCancelled(true); + if (shouldKickPlayer) { + player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); return; } + if (sendActionBar) { + player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); + } + return; } final UUID playerUniqueId = player.getUniqueId(); Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(playerUniqueId); + if (leverFlickCount == null) leverFlickCount = 0; + + leverFlickCount++; + playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount); - if (leverFlickCount == null) { - playersUsingLeversCooldowns.put(playerUniqueId, 1); - } else { - leverFlickCount++; - playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount); - if (leverFlickCount > leverUsageLimit) { - event.setCancelled(true); - if (shouldKickPlayer) { - player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); - return; - } - if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); - } + if (leverFlickCount > leverUsageLimit) { + event.setCancelled(true); + if (shouldKickPlayer) { + player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); + return; + } + if (sendActionBar) { + player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); } } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java index d1e41a453..3bdb26911 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java @@ -30,10 +30,11 @@ public LiquidUpdateLag() { this.maxLiquidSpreadEventsPerChunk = config.getInt("lag-preventions.prevent-liquid-update-lag.max-liquid-events-in-same-chunk-per-time", 1200, "amount of liquid source blocks * sides it can spread to * block spread length"); this.liquidSpreadEventCountCache = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis( - config.getInt("lag-preventions.prevent-liquid-update-lag.time-in-ticks", 100, - "Record time after first liquid spread. \nWhen this time runs out, the spread counter resets") * 50L + Math.max(config.getInt("lag-preventions.prevent-liquid-update-lag.time-in-ticks", 100, + "Record time after first liquid spread. \nWhen this time runs out, the spread counter resets"), 1) * 50L )).build(); - this.logIsEnabled = config.getBoolean("lag-preventions.prevent-liquid-update-lag.log", false, "very spammy, use for testing only"); + this.logIsEnabled = config.getBoolean("lag-preventions.prevent-liquid-update-lag.log", false, + "Very spammy, use for testing/debugging only"); } @Override @@ -69,11 +70,7 @@ private void onLiquidSpread(BlockFromToEvent event) { final Chunk chunk = sourceBlock.getChunk(); Integer liquidSpreadCount = liquidSpreadEventCountCache.getIfPresent(chunk); - - if (liquidSpreadCount == null) { - liquidSpreadEventCountCache.put(chunk, 1); - return; - } + if (liquidSpreadCount == null) liquidSpreadCount = 0; liquidSpreadCount++; liquidSpreadEventCountCache.put(chunk, liquidSpreadCount); @@ -86,7 +83,7 @@ private void onLiquidSpread(BlockFromToEvent event) { return; } - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), " Recorded " + liquidSpreadCount + + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Recorded " + liquidSpreadCount + " liquid updates in chunk x:" + chunk.getX() + ", z:" + chunk.getZ() + ", world: " + chunk.getWorld().getName()); } } \ No newline at end of file diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java index 3f90d1666..35269b8e4 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java @@ -11,6 +11,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.util.NumberConversions; import java.util.HashMap; import java.util.Map; @@ -19,15 +20,17 @@ public class PathfindingLimits implements AnarchyExploitFixesModule, Listener { private final Map limitedTypes = new HashMap<>(); - private final double globalMaxDistance; private final boolean logIsEnabled, globalDistanceEnabled, perTypeDistanceEnabled; + private final double globalMaxDistanceSquared; public PathfindingLimits() { shouldEnable(); Config config = AnarchyExploitFixes.getConfiguration(); - this.logIsEnabled = config.getBoolean("lag-preventions.pathfinding-limits.log", false); + this.logIsEnabled = config.getBoolean("lag-preventions.pathfinding-limits.log", false, + "Only meant for debug."); this.globalDistanceEnabled = config.getBoolean("lag-preventions.pathfinding-limits.global-limit.enable", false); - this.globalMaxDistance = config.getDouble("lag-preventions.pathfinding-limits.global-limit.max-target-distance", 20.0, "The max distance no mob pathfinding should exceed.\nYou want this to be higher than your highest max distance for a specific mob."); + this.globalMaxDistanceSquared = NumberConversions.square(config.getDouble("lag-preventions.pathfinding-limits.global-limit.max-target-distance", 20.0, + "The max distance no mob pathfinding should exceed.\nYou want this to be higher than your highest max distance for a specific mob.")); this.perTypeDistanceEnabled = config.getBoolean("lag-preventions.pathfinding-limits.custom-limits.enable", true); Map defaults = new HashMap<>(); defaults.put("ZOMBIE", 6.0); @@ -39,9 +42,9 @@ public PathfindingLimits() { ConfigSection section = config.getConfigSection("lag-preventions.pathfinding-limits.custom-limits.entities", defaults); for (String configuredEntity : section.getKeys(false)) { try { - Double maxDistance = Double.valueOf(section.getString(configuredEntity)); + Double maxDistanceSquared = NumberConversions.square(Double.valueOf(section.getString(configuredEntity))); EntityType limitedEntity = EntityType.valueOf(configuredEntity); - this.limitedTypes.put(limitedEntity, maxDistance); + this.limitedTypes.put(limitedEntity, maxDistanceSquared); } catch (NumberFormatException e) { LogUtil.doubleNotRecognized(Level.WARNING, name(), configuredEntity); } catch (IllegalArgumentException e) { @@ -78,28 +81,26 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPathfind(EntityPathfindEvent event) { - final double targetDistance = event.getEntity().getLocation().distance(event.getLoc()); + final double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(event.getLoc()); if (globalDistanceEnabled) { - if (targetDistance > globalMaxDistance) { + if (targetDistanceSquared > globalMaxDistanceSquared) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled pathfinding for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because target is further than the global limit. Distance: "+targetDistance - ); + "Cancelled pathfinding for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because the target is further than the global limit. Distance: " + Math.sqrt(targetDistanceSquared)); return; } } if (perTypeDistanceEnabled) { - if (limitedTypes.containsKey(event.getEntityType()) && targetDistance > limitedTypes.get( event.getEntityType())) { + if (limitedTypes.containsKey(event.getEntityType()) && targetDistanceSquared > limitedTypes.get(event.getEntityType())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled pathfinding for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because target further than its configured limit. Distance: "+targetDistance - ); + "Cancelled pathfinding for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because the target is further than its configured limit. Distance: " + Math.sqrt(targetDistanceSquared)); } } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java index f6717bf0a..9e67fb988 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java @@ -5,7 +5,7 @@ import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import org.bukkit.World; -import org.bukkit.entity.*; +import org.bukkit.entity.Projectile; public class SnowballExploit implements AnarchyExploitFixesModule { @@ -19,8 +19,10 @@ public SnowballExploit() { this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); config.addComment("lag-preventions.prevent-snowball-exploit.enable", "Patches a lag exploit."); - this.max_alive_time = config.getInt("lag-preventions.prevent-snowball-exploit.projectiles-max-alive-time-in-ticks", 300, "(20 ticks = 1 second) Will not touch Ender Pearls"); - this.check_period_in_ticks = config.getInt("lag-preventions.prevent-snowball-exploit.check-period-in-seconds", 20, "How frequently we should check for all projectile's alive time") * 20L; + this.max_alive_time = config.getInt("lag-preventions.prevent-snowball-exploit.projectiles-max-alive-time-in-ticks", 300, + "(20 ticks = 1 second) Will not touch Ender Pearls"); + this.check_period_in_ticks = config.getInt("lag-preventions.prevent-snowball-exploit.check-period-in-seconds", 20, + "How frequently we should check for all projectile's alive time") * 20L; } @Override diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java index 8d27a9bdc..e16b193b1 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java @@ -12,6 +12,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.util.NumberConversions; import java.util.HashMap; import java.util.Map; @@ -20,7 +21,7 @@ public class TargetDistanceLimit implements AnarchyExploitFixesModule, Listener { private final Map limitedTypes = new HashMap<>(); - private final double globalMaxDistance; + private final double globalMaxDistanceSquared; private final boolean logIsEnabled, globalDistanceEnabled, perTypeDistanceEnabled; public TargetDistanceLimit() { @@ -28,9 +29,9 @@ public TargetDistanceLimit() { Config config = AnarchyExploitFixes.getConfiguration(); this.logIsEnabled = config.getBoolean("lag-preventions.target-distance-limits.log", false); this.globalDistanceEnabled = config.getBoolean("lag-preventions.target-distance-limits.global-limit.enable", false); - this.globalMaxDistance = config.getDouble("lag-preventions.target-distance-limits.global-limit.max-target-distance", 20.0, """ + this.globalMaxDistanceSquared = NumberConversions.square(config.getDouble("lag-preventions.target-distance-limits.global-limit.max-target-distance", 20.0, """ The max distance no target should exceed.\s - You want this to be higher than your highest max distance for a specific mob."""); + You want this to be higher than your highest max distance for a specific mob.""")); this.perTypeDistanceEnabled = config.getBoolean("lag-preventions.target-distance-limits.custom-limits.enable", true); Map defaults = new HashMap<>(); defaults.put("ZOMBIE", 6.0); @@ -42,9 +43,9 @@ public TargetDistanceLimit() { ConfigSection section = config.getConfigSection("lag-preventions.target-distance-limits.custom-limits.entities", defaults); for (String configuredEntity : section.getKeys(false)) { try { - Double maxDistance = Double.valueOf(section.getString(configuredEntity)); + Double maxDistanceSquared = NumberConversions.square(Double.parseDouble(section.getString(configuredEntity))); EntityType limitedEntity = EntityType.valueOf(configuredEntity); - this.limitedTypes.put(limitedEntity, maxDistance); + this.limitedTypes.put(limitedEntity, maxDistanceSquared); } catch (NumberFormatException e) { LogUtil.doubleNotRecognized(Level.WARNING, name(), configuredEntity); } catch (IllegalArgumentException e) { @@ -84,29 +85,29 @@ private void onTargetAcquire(EntityTargetEvent event) { Entity targetEntity = event.getTarget(); if (targetEntity == null) return; - final double targetDistance = event.getEntity().getLocation().distance(targetEntity.getLocation()); + final double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(targetEntity.getLocation()); if (globalDistanceEnabled) { - if (targetDistance > globalMaxDistance) { + if (targetDistanceSquared > globalMaxDistanceSquared) { event.setCancelled(true); event.setTarget(null); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled target acquire for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because target is further than the global limit. Distance: "+targetDistance + "Cancelled target acquire for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because target is further than the global limit. Distance: " + Math.sqrt(targetDistanceSquared) ); return; } } if (perTypeDistanceEnabled) { - if (limitedTypes.containsKey(event.getEntityType()) && targetDistance > limitedTypes.get(event.getEntityType())) { + if (limitedTypes.containsKey(event.getEntityType()) && targetDistanceSquared > limitedTypes.get(event.getEntityType())) { event.setCancelled(true); event.setTarget(null); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled target acquire for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because target further than its configured limit. Distance: "+targetDistance + "Cancelled target acquire for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because target further than its configured limit. Distance: " + Math.sqrt(targetDistanceSquared) ); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java index ed93b4f9e..42b2cf42f 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java @@ -20,7 +20,8 @@ public class BlockPhysics implements AnarchyExploitFixesModule, Listener { public BlockPhysics() { shouldEnable(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.block-physics.enable", "Stop block physics (like falling blocks) when the TPS gets below a certain value."); + config.addComment("lag-preventions.disable-physics-during-low-tps.block-physics.enable", + "Stop block physics (like falling blocks) when the TPS gets below a certain value."); this.disablePhysicsTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.block-physics.disable-TPS", 16.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.block-physics.log", false); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java index 4ecc3ea0c..7e8544801 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java @@ -23,7 +23,8 @@ public class Explosions implements AnarchyExploitFixesModule, Listener { public Explosions() { shouldEnable(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.explosions.enable", "Disable explosions during low tps to combat lag."); + config.addComment("lag-preventions.disable-physics-during-low-tps.explosions.enable", + "Disable explosions during low tps to combat lag."); this.disableExplosionsTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.explosions.disable-TPS", 14.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.explosions.log", false); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java index 5fdebfad7..da9803bf6 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java @@ -21,7 +21,8 @@ public class Noteblocks implements AnarchyExploitFixesModule, Listener { public Noteblocks() { shouldEnable(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.noteblocks.enable", "Some lag machines use noteblocks to work around redstone limitations."); + config.addComment("lag-preventions.disable-physics-during-low-tps.noteblocks.enable", + "Some lag machines use noteblocks to work around redstone limitations."); this.disableNoteblockTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.noteblocks.disable-TPS", 16.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.noteblocks.log", false); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java index bf5685bc1..fc1b3eea0 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java @@ -23,7 +23,8 @@ public class Redstone implements AnarchyExploitFixesModule, Listener { public Redstone() { shouldEnable(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.redstone.enable", "Disable redstone during low TPS to prevent some lag machines."); + config.addComment("lag-preventions.disable-physics-during-low-tps.redstone.enable", + "Disable redstone during low TPS to prevent some lag machines."); this.disableRedstoneTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.redstone.disable-TPS", 16.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.redstone.log", false); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java index 18427e3a3..d1ff85c8f 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import me.moomoo.anarchyexploitfixes.utils.models.ExpiringSet; import org.bukkit.event.EventHandler; @@ -65,11 +66,7 @@ private void onTeleport(EntityTeleportEvent event) { if (recentWorldChangers.contains(event.getEntity().getUniqueId())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Cancelled too fast world teleport of entity: " + - event.getEntityType().name() + " at " + - "x: "+event.getEntity().getLocation().getX() + ", " + - "y: "+event.getEntity().getLocation().getY() + ", " + - "z: "+event.getEntity().getLocation().getZ() + ", " + - "world: "+event.getEntity().getLocation().getWorld().getName()); + event.getEntityType().name() + " at " + LocationUtil.toString(event.getFrom())); } else { recentWorldChangers.add(event.getEntity().getUniqueId()); } 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 22af7197a..4becc3dea 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 @@ -21,11 +21,9 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleMoveEvent; -import java.util.Set; - public class NetherRoof implements AnarchyExploitFixesModule, Listener { - private static final Iterable CARDINAL_FACES = Set.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST); + private static final BlockFace[] CARDINAL_FACES = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; private final AnarchyExploitFixes plugin; private final boolean safe_teleport_enabled; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java index 2cab04246..94e26f8f8 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java @@ -5,22 +5,6 @@ public class ChunkUtil { - public static int getMaterialCount(Chunk chunk, Material material) { - final int minY = chunk.getWorld().getMinHeight(); - final int maxY = chunk.getWorld().getMaxHeight(); - int count = 0; - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - for (int y = minY; y < maxY; y++) { - if (chunk.getBlock(x, y, z).getType() == material) { - count++; - } - } - } - } - return count; - } - public static void createBedrockLayer(Chunk chunk, final int y) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java index d7cf32c24..2c2b8398d 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java @@ -1,7 +1,5 @@ package me.moomoo.anarchyexploitfixes.utils; -import java.util.Arrays; - public class CommandUtil { /* @@ -29,8 +27,4 @@ public static String cutLastArgument(String cmd) { cmdBuilder.append(cmdSplit[i]).append(" "); return cmdBuilder.toString(); } - - public static String mergeArgs(String[] args, int start) { - return String.join(" ", Arrays.copyOfRange(args, start, args.length)); - } } 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 c0f60c565..01aa12156 100644 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java @@ -7,6 +7,10 @@ public class LocationUtil { + public static String toString(Location location) { + return "[" + location.getWorld().getName() + "] x=" + location.getBlockX() + ", y=" + location.getBlockY() + ", z=" + location.getBlockZ(); + } + 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/chat/commandwhitelist/CommandWhitelist.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chat/commandwhitelist/CommandWhitelist.java index 9d20e6f51..7df24761b 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chat/commandwhitelist/CommandWhitelist.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chat/commandwhitelist/CommandWhitelist.java @@ -14,6 +14,7 @@ import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; import static me.moomoo.anarchyexploitfixes.utils.CommandUtil.*; @@ -24,8 +25,7 @@ public class CommandWhitelist implements AnarchyExploitFixesModule, Listener { * Code was mainly only implemented into AEF by xGinko. */ - private final Set allowedCommands = new HashSet<>(); - private final Set bannedSubCommands; + private final Set allowedCommands, bannedSubCommands; private final boolean shouldUseProtocolLib, shouldLog; public CommandWhitelist() { @@ -40,14 +40,14 @@ public CommandWhitelist() { this.shouldUseProtocolLib = config.getBoolean("chat.command-whitelist.use-protocollib", true, "Without this enabled, tabcomplete filters will not work properly."); // Whitelisted Commands - List configuredAllowedCommands = config.getList("chat.command-whitelist.whitelisted-commands", Arrays.asList( - "help", "vote", "kill", "discord", "togglechat", "toggleconnectionmsgs", "toggletells", "togglewhispering", "toggleprivatemsgs", - "ignore", "ignorelist", "ignorehard", "toggledeathmsg", "dmt", "worldstats", "stats", "tps", "msg", "whisper", "w", "m", "t", - "pm", "tell", "r", "reply", "last" - ), "Add all commands you want your players to be able to access (without the '/'). Not case sensitive."); - for (String configuredAllowedCmd : configuredAllowedCommands) { - this.allowedCommands.add(configuredAllowedCmd.toLowerCase()); - } + this.allowedCommands = config.getList("chat.command-whitelist.whitelisted-commands", List.of( + "help", "vote", "kill", "discord", "togglechat", "toggleconnectionmsgs", "toggletells", "togglewhispering", "toggleprivatemsgs", + "ignore", "ignorelist", "ignorehard", "toggledeathmsg", "dmt", "worldstats", "stats", "tps", "msg", "whisper", "w", "m", "t", + "pm", "tell", "r", "reply", "last" + ), "Add all commands you want your players to be able to access (without the '/'). Not case sensitive.") + .stream() + .map(String::toLowerCase) + .collect(Collectors.toSet()); // Blacklisted Subcommands this.bannedSubCommands = new HashSet<>(config.getList("chat.command-whitelist.blacklisted-subcommands", Arrays.asList( "help about", "vote List", "vote Best", "vote Total", "worldstats reload", "stats reload" diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java index fa62a0114..970b1d3e4 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/BlockLimit.java @@ -5,11 +5,11 @@ import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.ChunkUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; +import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockPlaceEvent; import java.util.HashMap; @@ -180,20 +180,28 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onBlockPlace(BlockPlaceEvent event) { final Material placedType = event.getBlock().getType(); - if (!blockLimits.containsKey(placedType)) return; - - if (ChunkUtil.getMaterialCount(event.getBlock().getChunk(), placedType) > blockLimits.get(placedType)) { + if ( + blockLimits.containsKey(placedType) + && exceedsPerChunkLimit(placedType, blockLimits.get(placedType), event.getBlock().getChunk()) + ) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onBlockPlace(BlockCanBuildEvent event) { - final Material placedType = event.getMaterial(); - if (!blockLimits.containsKey(placedType)) return; - - if (ChunkUtil.getMaterialCount(event.getBlock().getChunk(), placedType) > blockLimits.get(placedType)) { - event.setBuildable(false); + private boolean exceedsPerChunkLimit(Material material, int limit, Chunk chunk) { + final int minY = ChunkUtil.guessMinWorldHeight(chunk.getWorld()); + final int maxY = chunk.getWorld().getMaxHeight(); + int count = 0; + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + for (int y = minY; y < maxY; y++) { + if (chunk.getBlock(x, y, z).getType() == material) { + count++; + if (count > limit) return true; + } + } + } } + return false; } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.java index dfd9904da..dc4037bff 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/CustomEntityLimit.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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -158,9 +159,9 @@ private void onSpawn(EntitySpawnEvent event) { if (entityCount <= maxAllowedPerChunk) continue; entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowedPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxAllowedPerChunk); } } @@ -183,9 +184,9 @@ public void run() { if (entityCount <= maxAllowedPerChunk) continue; entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowedPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxAllowedPerChunk); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java index 2cc6cb4fb..c47e7c4a4 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/DroppedItemLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.Material; @@ -99,9 +100,8 @@ private void onItemDrop(ItemSpawnEvent event) { if (usingWhitelist && whitelistedItems.contains(((Item) entity).getItemStack().getType())) continue; 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); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed dropped item at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxDroppedItemsPerChunk); } } @@ -119,9 +119,8 @@ private void onChunkLoad(ChunkLoadEvent event) { if (usingWhitelist && whitelistedItems.contains(((Item) entity).getItemStack().getType())) continue; 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); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed dropped item at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxDroppedItemsPerChunk); } } @@ -141,9 +140,8 @@ public void run() { if (usingWhitelist && whitelistedItems.contains(((Item) entity).getItemStack().getType())) continue; 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); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed dropped item at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxDroppedItemsPerChunk); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java index a9bd648fa..de23e92a8 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/ExpBottleLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -60,9 +61,8 @@ private void onExpBottle(ExpBottleEvent event) { if (expBottleCount > maxExpBottlePerChunk) { entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed XP-Bottle " - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxExpBottlePerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed XP-Bottle at " + + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxExpBottlePerChunk); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java index d359fd729..4828cb6e8 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/FallingBlockLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import me.moomoo.anarchyexploitfixes.utils.models.ExpiringSet; import org.bukkit.Chunk; @@ -31,9 +32,9 @@ public FallingBlockLimit() { this.logIsEnabled = config.getBoolean("chunk-limits.falling-block-limit.log", false); this.maxFallingGravityBlockPerChunk = config.getInt("chunk-limits.falling-block-limit.max-falling-gravitiy-blocks-per-chunk", 60, "Removes any falling block if there is more than x blocks (actively) falling in a chunk."); - final long chunkCheckDelay = config.getInt("chunk-limits.falling-block-limit.chunk-check-delay-in-ticks", 20, + final long chunkCheckDelay = Math.max(config.getInt("chunk-limits.falling-block-limit.chunk-check-delay-in-ticks", 20, "Delay in ticks until the same chunk can be checked again.\n" + - "Prevents overchecking because a physics event can be called multiple times for the same chunk.") * 50L; + "Prevents overchecking because a physics event can be called multiple times for the same chunk."), 1) * 50L; this.checkedChunks = new ExpiringSet<>(Duration.ofMillis(chunkCheckDelay)); } @@ -79,9 +80,8 @@ private void onBlockPhysics(BlockPhysicsEvent event) { checkedChunks.add(chunk); if (logIsEnabled && removed_falling) LogUtil.moduleLog(Level.INFO, name(), - "Removed falling blocks at " + event.getSourceBlock().getLocation() - + ", because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk" - ); + "Removed falling blocks at " + LocationUtil.toString(event.getSourceBlock().getLocation()) + + " because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk"); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -106,8 +106,7 @@ private void onChangeBlock(EntityChangeBlockEvent event) { checkedChunks.add(chunk); if (logIsEnabled && removed_falling) LogUtil.moduleLog(Level.INFO, name(), - "Removed falling blocks at " + event.getBlock().getLocation() - + ", because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk" - ); + "Removed falling blocks at " + LocationUtil.toString(event.getBlock().getLocation()) + + " because reached limit of " + maxFallingGravityBlockPerChunk + " falling gravity blocks per chunk"); } } \ No newline at end of file diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java index 49a336f52..ae3227eb8 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java @@ -4,6 +4,7 @@ import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.EntityUtil; +import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -31,8 +32,8 @@ public MinecartLimit() { "Limit the amount of minecarts to prevent lag."); this.logIsEnabled = config.getBoolean("chunk-limits.minecart-limit.log-removals", false); this.maxMinecartsPerChunk = config.getInt("chunk-limits.minecart-limit.max-minecarts-per-chunk", 25); - this.checkPeriod = config.getInt("chunk-limits.minecart-limit.check-period-in-ticks", 400, - "200 ticks = 10 seconds."); + this.checkPeriod = Math.max(config.getInt("chunk-limits.minecart-limit.check-period-in-ticks", 400, + "200 ticks = 10 seconds."), 1); } @Override @@ -70,8 +71,7 @@ private void onCreate(VehicleCreateEvent event) { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed minecart " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxMinecartsPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxMinecartsPerChunk); } } @@ -91,8 +91,7 @@ public void run() { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed minecart " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxMinecartsPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxMinecartsPerChunk); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.java index 80549051b..9b57c6096 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/NonLivingEntityLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -21,7 +22,7 @@ public class NonLivingEntityLimit implements AnarchyExploitFixesModule, Listener, Runnable { private final AnarchyExploitFixes plugin; - private final Set NON_LIVING_TYPES = new HashSet<>(); + private static final Set NON_LIVING_TYPES = new HashSet<>(); private final long checkPeriod; private final int maxNonLivingEntities; private final boolean logIsEnabled; @@ -74,9 +75,9 @@ private void onSpawn(EntitySpawnEvent event) { entity.remove(); event.setCancelled(true); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxNonLivingEntities); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); continue; } @@ -89,9 +90,9 @@ private void onSpawn(EntitySpawnEvent event) { entity.remove(); event.setCancelled(true); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxNonLivingEntities); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); } } } @@ -113,8 +114,8 @@ public void run() { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " - + entity.getType() + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxNonLivingEntities); + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); continue; } @@ -127,8 +128,8 @@ public void run() { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed non-living entity " - + entity.getType() + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxNonLivingEntities); + + entity.getType() + " at " + LocationUtil.toString(entity.getLocation()) + + " because reached limit of " + maxNonLivingEntities); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java index b90302468..f02d503bc 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -79,8 +80,7 @@ private void onCreate(VehicleCreateEvent event) { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxVehiclesPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); continue; } @@ -92,8 +92,7 @@ private void onCreate(VehicleCreateEvent event) { entity.remove(); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() - + " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() - + " z:" + entity.getLocation().getZ() + ", because reached limit of " + maxVehiclesPerChunk); + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); } } } @@ -114,10 +113,8 @@ public void run() { if (vehicleCount <= maxVehiclesPerChunk) continue; entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " - + entity.getType() + " at x:" + entity.getLocation().getX() - + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxVehiclesPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); continue; } @@ -128,10 +125,8 @@ public void run() { if (vehicleCount <= maxVehiclesPerChunk) continue; entity.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " - + entity.getType() + " at x:" + entity.getLocation().getX() - + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ() - + ", because reached limit of " + maxVehiclesPerChunk); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed vehicle " + entity.getType() + + " at " + LocationUtil.toString(entity.getLocation()) + " because reached limit of " + maxVehiclesPerChunk); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.java index 366817370..466104caa 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VillagerLimit.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -14,16 +15,14 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class VillagerLimit implements AnarchyExploitFixesModule, Runnable, Listener { private final AnarchyExploitFixes plugin; - private final List removalPriority = new ArrayList<>(); + private final List removalPriority; private final long checkPeriod; private final int maxVillagersPerChunk; private final boolean logIsEnabled; @@ -32,23 +31,26 @@ public VillagerLimit() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - this.maxVillagersPerChunk = config.getInt("chunk-limits.entity-limits.villager-limit.max-villagers-per-chunk", 25); + this.maxVillagersPerChunk = Math.max(config.getInt("chunk-limits.entity-limits.villager-limit.max-villagers-per-chunk", 25), 1); this.logIsEnabled = config.getBoolean("chunk-limits.entity-limits.villager-limit.log-removals", false); - this.checkPeriod = config.getInt("chunk-limits.entity-limits.villager-limit.check-period-in-ticks", 600, - "check all chunks every x ticks."); - config.getList("chunk-limits.entity-limits.villager-limit.removal-priority", Arrays.asList( - "NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER", - "FLETCHER", "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN" - ), "Professions that are in the top of the list are going to be scheduled for removal first." - ).forEach(configuredProfession -> { - try { - Villager.Profession profession = Villager.Profession.valueOf(configuredProfession); - this.removalPriority.add(profession); - } catch (IllegalArgumentException e) { - LogUtil.moduleLog(Level.WARNING, name(), "Villager profession '"+configuredProfession+"' not recognized. " + - "Make sure youre using the correct profession enums for your Version."); - } - }); + this.checkPeriod = Math.max(config.getInt("chunk-limits.entity-limits.villager-limit.check-period-in-ticks", 600, + "check all chunks every x ticks."), 1); + this.removalPriority = config.getList("chunk-limits.entity-limits.villager-limit.removal-priority", Arrays.asList( + "NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER", "FLETCHER", + "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN"), + "Professions that are in the top of the list are going to be scheduled for removal first.") + .stream() + .map(configuredProfession -> { + try { + return Villager.Profession.valueOf(configuredProfession); + } catch (IllegalArgumentException e) { + LogUtil.moduleLog(Level.WARNING, name(), "Villager profession '"+configuredProfession+"' not recognized. " + + "Make sure youre using the correct profession enums for your Version."); + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } @Override @@ -84,8 +86,9 @@ private void onCreateSpawn(CreatureSpawnEvent event) { public void run() { for (World world : plugin.getServer().getWorlds()) { for (Chunk chunk : world.getLoadedChunks()) { - if (!chunk.isLoaded()) continue; - this.checkVillagersInChunk(chunk); + if (chunk.isLoaded()) { + this.checkVillagersInChunk(chunk); + } } } } @@ -100,23 +103,21 @@ private void checkVillagersInChunk(Chunk chunk) { } // Check if there are more villagers in that chunk than allowed - int amount_over_the_limit = villagers_in_chunk.size() - maxVillagersPerChunk; + final int amount_over_the_limit = villagers_in_chunk.size() - maxVillagersPerChunk; if (amount_over_the_limit <= 0) return; // Sort villager list by profession priority - villagers_in_chunk.sort(Comparator.comparingInt(this::getProfessionPriority)); + villagers_in_chunk.sort(Comparator.comparingInt(villager -> { + final Villager.Profession profession = villager.getProfession(); + return removalPriority.contains(profession) ? removalPriority.indexOf(profession) : Integer.MAX_VALUE; + })); // Remove prioritized villagers that are too many for (int i = 0; i < amount_over_the_limit; i++) { Villager villager = villagers_in_chunk.get(i); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Removing villager of profession type '"+villager.getProfession()+"' at "+villager.getLocation()); villager.remove(); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed villager with profession '" + + villager.getProfession() + "' at " + LocationUtil.toString(villager.getLocation())); } } - - private int getProfessionPriority(Villager villager) { - Villager.Profession profession = villager.getProfession(); - return removalPriority.contains(profession) ? removalPriority.indexOf(profession) : Integer.MAX_VALUE; - } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java index 2f6dda890..22f61f641 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/AnchorAuraDelay.java @@ -21,8 +21,7 @@ public class AnchorAuraDelay implements AnarchyExploitFixesModule, Listener { - private final ExpiringSet placeCooldowns; - private final ExpiringSet breakCooldowns; + private final ExpiringSet placeCooldowns, breakCooldowns; private final Material RESPAWN_ANCHOR, GLOWSTONE; private final long placeDelayMillis, breakDelayMillis; private final boolean updateInv; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java index b1f66ec51..1f7f5ac71 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/BedAuraDelay.java @@ -24,8 +24,7 @@ public class BedAuraDelay implements AnarchyExploitFixesModule, Listener { - private final ExpiringSet breakCooldowns; - private final ExpiringSet placeCooldowns; + private final ExpiringSet breakCooldowns, placeCooldowns; private final Set beds; private final long breakDelayMillis, placeDelayMillis; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java index a210c6bee..18e60c0cc 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraDelay.java @@ -21,8 +21,7 @@ public class CrystalAuraDelay implements AnarchyExploitFixesModule, Listener { - private final ExpiringSet breakCooldowns; - private final ExpiringSet placeCooldowns; + private final ExpiringSet breakCooldowns, placeCooldowns; private final Material END_CRYSTAL; private final long breakDelayMillis, placeDelayMillis; private final boolean updateInv; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java index 87dd558e2..5299d31e1 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/CrystalAuraHotbarSwitchDelay.java @@ -17,11 +17,12 @@ import java.time.Duration; import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class CrystalAuraHotbarSwitchDelay implements AnarchyExploitFixesModule, Listener { private final ExpiringSet hotbarItemSwitchCooldowns; - private final Set blacklistedSwitchMaterials = new HashSet<>(); + private final Set blacklistedSwitchMaterials; private final Material END_CRYSTAL; private final boolean onlyForSpecificMaterials; @@ -29,8 +30,8 @@ public CrystalAuraHotbarSwitchDelay() { shouldEnable(); this.END_CRYSTAL = XMaterial.END_CRYSTAL.parseMaterial(); Config config = AnarchyExploitFixes.getConfiguration(); - final long switchAwayFromCrystalsDelayInMillis = config.getInt("combat.crystal-aura.hotbar-switch-delay.delay-in-ticks", 2, - "Delay between switching from an end crystal to other items in hotbar") * 50L; + final long switchAwayFromCrystalsDelayInMillis = Math.max(config.getInt("combat.crystal-aura.hotbar-switch-delay.delay-in-ticks", 2, + "Delay between switching from an end crystal to other items in hotbar"), 1) * 50L; this.hotbarItemSwitchCooldowns = new ExpiringSet<>(Duration.ofMillis(switchAwayFromCrystalsDelayInMillis)); this.onlyForSpecificMaterials = config.getBoolean("combat.crystal-aura.hotbar-switch-delay.only-delay-specific-materials", true, "Only delay when switched to specific materials"); @@ -53,14 +54,18 @@ public CrystalAuraHotbarSwitchDelay() { "STONE_SWORD", "STONE_AXE", "WOOD_SWORD", "WOOD_AXE" ); } - for (String configuredMaterial : config.getList("combat.crystal-aura.hotbar-switch-delay.delayed-specific-materials", defaults)) { - try { - Material bannedMaterial = Material.valueOf(configuredMaterial); - blacklistedSwitchMaterials.add(bannedMaterial); - } catch (IllegalArgumentException e) { - LogUtil.materialNotRecognized(Level.WARNING, name(), configuredMaterial); - } - } + this.blacklistedSwitchMaterials = config.getList("combat.crystal-aura.hotbar-switch-delay.delayed-specific-materials", defaults) + .stream() + .map(configuredMaterial -> { + try { + return Material.valueOf(configuredMaterial); + } catch (IllegalArgumentException e) { + LogUtil.materialNotRecognized(Level.WARNING, name(), configuredMaterial); + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toCollection(HashSet::new)); } @Override @@ -87,20 +92,21 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onHotbarSwitch(PlayerItemHeldEvent event) { final UUID playerUniqueId = event.getPlayer().getUniqueId(); - if (hotbarItemSwitchCooldowns.contains(playerUniqueId)) { - final PlayerInventory playerInventory = event.getPlayer().getInventory(); + if (!hotbarItemSwitchCooldowns.contains(playerUniqueId)) { + hotbarItemSwitchCooldowns.add(playerUniqueId); + return; + } - final ItemStack previouslyHeldItem = playerInventory.getItem(event.getPreviousSlot()); - if (previouslyHeldItem == null || previouslyHeldItem.getType() != END_CRYSTAL) return; + final PlayerInventory playerInventory = event.getPlayer().getInventory(); - final ItemStack newHeldItem = playerInventory.getItem(event.getNewSlot()); - if (newHeldItem == null || newHeldItem.getType() == END_CRYSTAL) return; + final ItemStack previouslyHeldItem = playerInventory.getItem(event.getPreviousSlot()); + if (previouslyHeldItem == null || previouslyHeldItem.getType() != END_CRYSTAL) return; - if (onlyForSpecificMaterials && !blacklistedSwitchMaterials.contains(newHeldItem.getType())) return; + final ItemStack newHeldItem = playerInventory.getItem(event.getNewSlot()); + if (newHeldItem == null || newHeldItem.getType() == END_CRYSTAL) return; - event.setCancelled(true); - } else { - hotbarItemSwitchCooldowns.add(playerUniqueId); - } + if (onlyForSpecificMaterials && !blacklistedSwitchMaterials.contains(newHeldItem.getType())) return; + + event.setCancelled(true); } } \ No newline at end of file diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java index d60eeefdb..7dd069d73 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/PistonAuraDelay.java @@ -22,7 +22,7 @@ public PistonAuraDelay() { Config config = AnarchyExploitFixes.getConfiguration(); config.addComment("combat.crystal-aura.piston-aura-delay.enable", "Rate-limits pistons that extend into crystals"); this.pistonsPushingCrystals = new ExpiringSet<>(Duration.ofMillis( - config.getInt("combat.crystal-aura.piston-aura-delay.piston-extend-delay-in-ticks", 40) * 50L)); + Math.max(config.getInt("combat.crystal-aura.piston-aura-delay.piston-extend-delay-in-ticks", 40), 1) * 50L)); } @Override diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java index 683e3a957..848f2ec3d 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/CloseEntityInventoryOnChunkUnload.java @@ -14,7 +14,8 @@ public class CloseEntityInventoryOnChunkUnload implements AnarchyExploitFixesMod public CloseEntityInventoryOnChunkUnload() { shouldEnable(); - AnarchyExploitFixes.getConfiguration().addComment("dupe-preventions.close-entity-inventories-on-chunk-unload", "Closes open inventories of all entities that are in a chunk that will be unloaded."); + AnarchyExploitFixes.getConfiguration().addComment("dupe-preventions.close-entity-inventories-on-chunk-unload", + "Closes open inventories of all entities that are in a chunk that will be unloaded."); } @Override diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java index 1680d9b6c..16202502d 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/dupepreventions/EndPortalDupe.java @@ -42,10 +42,11 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) private void onEntityDamage(EntityDamageEvent event) { - if ( - event.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK - && event.getCause() != EntityDamageEvent.DamageCause.FALL - ) return; + switch (event.getCause()) { + case ENTITY_ATTACK: + case FALL: + return; + } Entity entity = event.getEntity(); if (entity.getWorld().getEnvironment() != World.Environment.THE_END) return; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.java index 840c370aa..320cc0629 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/FallingBlockStasis.java @@ -3,9 +3,11 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LocationUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.World; -import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import java.util.logging.Level; @@ -25,8 +27,8 @@ public FallingBlockStasis() { this.logIsEnabled = config.getBoolean("lag-preventions.prevent-falling-block-stasis-exploit.log", false); this.max_alive_time = config.getInt("lag-preventions.prevent-falling-block-stasis-exploit.falling-blocks-max-alive-time-in-ticks", 300, "(20 ticks = 1 second)"); - this.check_period_in_ticks = config.getInt("lag-preventions.prevent-falling-block-stasis-exploit.check-period-in-seconds", 120, - "How frequently we should check for all projectile's alive time") * 20L; + this.check_period_in_ticks = Math.max(config.getInt("lag-preventions.prevent-falling-block-stasis-exploit.check-period-in-seconds", 120, + "How frequently we should check for all projectile's alive time"), 1) * 20L; } @Override @@ -52,12 +54,12 @@ public boolean shouldEnable() { @Override public void run() { for (World world : plugin.getServer().getWorlds()) { - for (FallingBlock fallingBlock : world.getEntitiesByClass(FallingBlock.class)) { - if (fallingBlock.getTicksLived() > max_alive_time) { - fallingBlock.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed falling block at x:" - + fallingBlock.getLocation().getX() + " y:" + fallingBlock.getLocation().getY() + " z:" + fallingBlock.getLocation().getZ() - + " in "+fallingBlock.getWorld().getName()+" because it was alive for more than " + max_alive_time + " ticks."); + for (Entity entity : world.getEntities()) { + if (entity.getType() == EntityType.FALLING_BLOCK && entity.getTicksLived() > max_alive_time) { + entity.remove(); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removed falling block at " + + LocationUtil.toString(entity.getLocation()) + + " because it has been alive for " + entity.getTicksLived() + " ticks (max= " + max_alive_time + ")."); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.java index f05ddec22..d08f99c04 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/InventoryActionLag.java @@ -42,9 +42,9 @@ public InventoryActionLag() { this.blockInventoryClicks = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); this.entityInventoryClicks = Caffeine.newBuilder().expireAfterWrite(cacheTime).build(); Map defaults = new HashMap<>(); - defaults.put("COLLECT_TO_CURSOR", 5); - defaults.put("MOVE_TO_OTHER_INVENTORY", 5); - defaults.put("HOTBAR_SWAP", 10); + defaults.put("COLLECT_TO_CURSOR", 15); + defaults.put("MOVE_TO_OTHER_INVENTORY", 8); + defaults.put("HOTBAR_SWAP", 30); ConfigSection section = config.getConfigSection("lag-preventions.prevent-inventory-action-lag.click-action-limits", defaults, "Use correct enums from: https://jd.papermc.io/paper/1.12/org/bukkit/event/inventory/InventoryAction.html.\n" + "Format is: InventoryClickAction: AllowedClicksPerTime"); @@ -101,9 +101,9 @@ private void onInventoryClick(InventoryClickEvent event) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Cancelled spammy inventory click of type "+event.getAction().name()+" at" + - " x:" + block.getLocation().getX() + "," + - " y:" + block.getLocation().getY() + "," + - " z:" + block.getLocation().getZ() + + " x:" + block.getLocation().getBlockX() + "," + + " y:" + block.getLocation().getBlockY() + "," + + " z:" + block.getLocation().getBlockZ() + " in world: " + block.getLocation().getWorld().getName()); } @@ -126,9 +126,9 @@ private void onInventoryClick(InventoryClickEvent event) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Cancelled spammy inventory click of type "+event.getAction().name()+" at" + - " x:" + entity.getLocation().getX() + "," + - " y:" + entity.getLocation().getY() + "," + - " z:" + entity.getLocation().getZ() + + " x:" + entity.getLocation().getBlockX() + "," + + " y:" + entity.getLocation().getBlockY() + "," + + " z:" + entity.getLocation().getBlockZ() + " in world: " + entity.getLocation().getWorld().getName()); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java index b3fce3840..76ff96b92 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LeverSpam.java @@ -71,42 +71,38 @@ private void onInteract(PlayerInteractEvent event) { final Location leverLoc = clicked.getLocation(); Integer activationCount = leverLocationCooldowns.getIfPresent(leverLoc); + if (activationCount == null) activationCount = 0; - if (activationCount == null) { - leverLocationCooldowns.put(leverLoc, 1); - } else { - activationCount++; - leverLocationCooldowns.put(leverLoc, activationCount); - if (activationCount > leverUsageLimit) { - event.setCancelled(true); - if (shouldKickPlayer) { - player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); - return; - } - if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); - } + activationCount++; + leverLocationCooldowns.put(leverLoc, activationCount); + + if (activationCount > leverUsageLimit) { + event.setCancelled(true); + if (shouldKickPlayer) { + player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); return; } + if (sendActionBar) { + player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); + } + return; } final UUID playerUniqueId = player.getUniqueId(); Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(playerUniqueId); + if (leverFlickCount == null) leverFlickCount = 0; + + leverFlickCount++; + playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount); - if (leverFlickCount == null) { - playersUsingLeversCooldowns.put(playerUniqueId, 1); - } else { - leverFlickCount++; - playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount); - if (leverFlickCount > leverUsageLimit) { - event.setCancelled(true); - if (shouldKickPlayer) { - player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); - return; - } - if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); - } + if (leverFlickCount > leverUsageLimit) { + event.setCancelled(true); + if (shouldKickPlayer) { + player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); + return; + } + if (sendActionBar) { + player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java index 195178012..13e377eeb 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/LiquidUpdateLag.java @@ -32,11 +32,11 @@ public LiquidUpdateLag() { this.maxLiquidSpreadEventsPerChunk = config.getInt("lag-preventions.prevent-liquid-update-lag.max-liquid-events-in-same-chunk-per-time", 1200, "Amount of liquid source blocks * sides it can spread to * block spread length"); this.liquidSpreadEventCountCache = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis( - config.getInt("lag-preventions.prevent-liquid-update-lag.time-in-ticks", 100, - "Record time after first liquid spread. \nWhen this time runs out, the spread counter resets") * 50L + Math.max(config.getInt("lag-preventions.prevent-liquid-update-lag.time-in-ticks", 100, + "Record time after first liquid spread. \nWhen this time runs out, the spread counter resets"), 1) * 50L )).build(); this.logIsEnabled = config.getBoolean("lag-preventions.prevent-liquid-update-lag.log", false, - "very spammy, use for testing only"); + "Very spammy, use for testing/debugging only"); } @Override @@ -67,22 +67,20 @@ private void onLiquidSpread(BlockFromToEvent event) { final Chunk chunk = sourceBlock.getChunk(); Integer liquidSpreadCount = liquidSpreadEventCountCache.getIfPresent(chunk); + if (liquidSpreadCount == null) liquidSpreadCount = 0; - if (liquidSpreadCount == null) { - liquidSpreadEventCountCache.put(chunk, 1); - } else { - liquidSpreadCount++; - liquidSpreadEventCountCache.put(chunk, liquidSpreadCount); - if (liquidSpreadCount > maxLiquidSpreadEventsPerChunk) { - event.setCancelled(true); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled liquid events for chunk x:" + chunk.getX() + ", z:" + chunk.getZ() + - "in world: " + chunk.getWorld().getName()); - return; - } + liquidSpreadCount++; + liquidSpreadEventCountCache.put(chunk, liquidSpreadCount); + + if (liquidSpreadCount > maxLiquidSpreadEventsPerChunk) { + event.setCancelled(true); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), + "Cancelled liquid events for chunk x:" + chunk.getX() + ", z:" + chunk.getZ() + + "in world: " + chunk.getWorld().getName()); + return; } - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), " Recorded " + liquidSpreadCount + + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Recorded " + liquidSpreadCount + " liquid updates in chunk x:" + chunk.getX() + ", z:" + chunk.getZ() + ", world: " + chunk.getWorld().getName()); } } \ No newline at end of file diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java index 31a96d858..2950095b7 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PathfindingLimits.java @@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.util.NumberConversions; import java.util.HashMap; import java.util.Map; @@ -19,14 +20,16 @@ public class PathfindingLimits implements AnarchyExploitFixesModule, Listener { private final Map limitedTypes = new HashMap<>(); private final boolean logIsEnabled, globalDistanceEnabled, perTypeDistanceEnabled; - private final double globalMaxDistance; + private final double globalMaxDistanceSquared; public PathfindingLimits() { shouldEnable(); Config config = AnarchyExploitFixes.getConfiguration(); - this.logIsEnabled = config.getBoolean("lag-preventions.pathfinding-limits.log", false, "Only meant for debug."); + this.logIsEnabled = config.getBoolean("lag-preventions.pathfinding-limits.log", false, + "Only meant for debug."); this.globalDistanceEnabled = config.getBoolean("lag-preventions.pathfinding-limits.global-limit.enable", false); - this.globalMaxDistance = config.getDouble("lag-preventions.pathfinding-limits.global-limit.max-target-distance", 20.0, "The max distance no mob pathfinding should exceed.\nYou want this to be higher than your highest max distance for a specific mob."); + this.globalMaxDistanceSquared = NumberConversions.square(config.getDouble("lag-preventions.pathfinding-limits.global-limit.max-target-distance", 20.0, + "The max distance no mob pathfinding should exceed.\nYou want this to be higher than your highest max distance for a specific mob.")); this.perTypeDistanceEnabled = config.getBoolean("lag-preventions.pathfinding-limits.custom-limits.enable", true); Map defaults = new HashMap<>(); defaults.put("ZOMBIE", 6.0); @@ -38,9 +41,9 @@ public PathfindingLimits() { ConfigSection section = config.getConfigSection("lag-preventions.pathfinding-limits.custom-limits.entities", defaults); for (String configuredEntity : section.getKeys(false)) { try { - Double maxDistance = Double.valueOf(section.getString(configuredEntity)); + Double maxDistanceSquared = NumberConversions.square(Double.valueOf(section.getString(configuredEntity))); EntityType limitedEntity = EntityType.valueOf(configuredEntity); - this.limitedTypes.put(limitedEntity, maxDistance); + this.limitedTypes.put(limitedEntity, maxDistanceSquared); } catch (NumberFormatException e) { LogUtil.doubleNotRecognized(Level.WARNING, name(), configuredEntity); } catch (IllegalArgumentException e) { @@ -72,28 +75,26 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPathfind(EntityPathfindEvent event) { - final double targetDistance = event.getEntity().getLocation().distance(event.getLoc()); + final double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(event.getLoc()); if (globalDistanceEnabled) { - if (targetDistance > globalMaxDistance) { + if (targetDistanceSquared > globalMaxDistanceSquared) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled pathfinding for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because the target is further than the global limit. Distance: "+targetDistance - ); + "Cancelled pathfinding for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because the target is further than the global limit. Distance: " + Math.sqrt(targetDistanceSquared)); return; } } if (perTypeDistanceEnabled) { - if (limitedTypes.containsKey(event.getEntityType()) && targetDistance > limitedTypes.get(event.getEntityType())) { + if (limitedTypes.containsKey(event.getEntityType()) && targetDistanceSquared > limitedTypes.get(event.getEntityType())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled pathfinding for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because the target is further than its configured limit. Distance: "+targetDistance - ); + "Cancelled pathfinding for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because the target is further than its configured limit. Distance: " + Math.sqrt(targetDistanceSquared)); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java index da2b50ee3..dcac5db52 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/SnowballExploit.java @@ -4,7 +4,7 @@ import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import org.bukkit.World; -import org.bukkit.entity.*; +import org.bukkit.entity.Projectile; public class SnowballExploit implements AnarchyExploitFixesModule, Runnable { @@ -48,13 +48,13 @@ public boolean shouldEnable() { public void run() { for (World world : plugin.getServer().getWorlds()) { for (Projectile projectile : world.getEntitiesByClass(Projectile.class)) { - final EntityType projectileType = projectile.getType(); - if ( - projectileType == EntityType.ENDER_PEARL - || projectileType == EntityType.WITHER_SKULL - || projectileType == EntityType.FISHING_HOOK - || projectileType == EntityType.ENDER_SIGNAL - ) continue; + switch (projectile.getType()) { + case ENDER_PEARL: + case WITHER_SKULL: + case FISHING_HOOK: + case ENDER_SIGNAL: + continue; + } if (projectile.getTicksLived() > max_alive_time) { projectile.remove(); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java index 8bd07e7d5..202e88e89 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/TargetDistanceLimit.java @@ -11,6 +11,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.util.NumberConversions; import java.util.HashMap; import java.util.Map; @@ -19,7 +20,7 @@ public class TargetDistanceLimit implements AnarchyExploitFixesModule, Listener { private final Map limitedTypes = new HashMap<>(); - private final double globalMaxDistance; + private final double globalMaxDistanceSquared; private final boolean logIsEnabled, globalDistanceEnabled, perTypeDistanceEnabled; public TargetDistanceLimit() { @@ -27,8 +28,9 @@ public TargetDistanceLimit() { Config config = AnarchyExploitFixes.getConfiguration(); this.logIsEnabled = config.getBoolean("lag-preventions.target-distance-limits.log", false); this.globalDistanceEnabled = config.getBoolean("lag-preventions.target-distance-limits.global-limit.enable", false); - this.globalMaxDistance = config.getDouble("lag-preventions.target-distance-limits.global-limit.max-target-distance", 20.0, - "The max distance no target should exceed.\nYou want this to be higher than your highest max distance for a specific mob."); + this.globalMaxDistanceSquared = NumberConversions.square(config.getDouble("lag-preventions.target-distance-limits.global-limit.max-target-distance", 20.0, + "The max distance no target should exceed.\n" + + "You want this to be higher than your highest max distance for a specific mob.")); this.perTypeDistanceEnabled = config.getBoolean("lag-preventions.target-distance-limits.custom-limits.enable", true); Map defaults = new HashMap<>(); defaults.put("ZOMBIE", 6.0); @@ -40,9 +42,9 @@ public TargetDistanceLimit() { ConfigSection section = config.getConfigSection("lag-preventions.target-distance-limits.custom-limits.entities", defaults); for (String configuredEntity : section.getKeys(false)) { try { - Double maxDistance = Double.valueOf(section.getString(configuredEntity)); + Double maxDistanceSquared = NumberConversions.square(Double.parseDouble(section.getString(configuredEntity))); EntityType limitedEntity = EntityType.valueOf(configuredEntity); - this.limitedTypes.put(limitedEntity, maxDistance); + this.limitedTypes.put(limitedEntity, maxDistanceSquared); } catch (NumberFormatException e) { LogUtil.doubleNotRecognized(Level.WARNING, name(), configuredEntity); } catch (IllegalArgumentException e) { @@ -77,29 +79,29 @@ private void onTargetAcquire(EntityTargetEvent event) { Entity targetEntity = event.getTarget(); if (targetEntity == null) return; - final double targetDistance = event.getEntity().getLocation().distance(targetEntity.getLocation()); + final double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(targetEntity.getLocation()); if (globalDistanceEnabled) { - if (targetDistance > globalMaxDistance) { + if (targetDistanceSquared > globalMaxDistanceSquared) { event.setCancelled(true); event.setTarget(null); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled target acquire for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because target is further than the global limit. Distance: "+targetDistance + "Cancelled target acquire for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because target is further than the global limit. Distance: " + Math.sqrt(targetDistanceSquared) ); return; } } if (perTypeDistanceEnabled) { - if (limitedTypes.containsKey(event.getEntityType()) && targetDistance > limitedTypes.get(event.getEntityType())) { + if (limitedTypes.containsKey(event.getEntityType()) && targetDistanceSquared > limitedTypes.get(event.getEntityType())) { event.setCancelled(true); event.setTarget(null); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Cancelled target acquire for entity "+event.getEntityType()+" at " - +event.getEntity().getLocation().toBlockLocation() - +" because target further than its configured limit. Distance: "+targetDistance + "Cancelled target acquire for entity " + event.getEntityType() + " at " + + event.getEntity().getLocation().toBlockLocation() + + " because target further than its configured limit. Distance: " + Math.sqrt(targetDistanceSquared) ); } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java index 348845935..dd2e14087 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/BlockPhysics.java @@ -21,7 +21,8 @@ public BlockPhysics() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.block-physics.enable", "Stop block physics (like falling blocks) when the TPS gets below a certain value."); + config.addComment("lag-preventions.disable-physics-during-low-tps.block-physics.enable", + "Stop block physics (like falling blocks) when the TPS gets below a certain value."); this.disablePhysicsTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.block-physics.disable-TPS", 16.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.block-physics.log", false); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java index 055d600f2..840b5c611 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Explosions.java @@ -24,7 +24,8 @@ public Explosions() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.explosions.enable", "Disable explosions during low tps to combat lag."); + config.addComment("lag-preventions.disable-physics-during-low-tps.explosions.enable", + "Disable explosions during low tps to combat lag."); this.disableExplosionsTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.explosions.disable-TPS", 14.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.explosions.log", false); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java index 8702ea558..d74642e46 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Noteblocks.java @@ -22,7 +22,8 @@ public Noteblocks() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.noteblocks.enable", "Some lag machines use noteblocks to work around redstone limitations."); + config.addComment("lag-preventions.disable-physics-during-low-tps.noteblocks.enable", + "Some lag machines use noteblocks to work around redstone limitations."); this.disableNoteblockTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.noteblocks.disable-TPS", 16.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.noteblocks.log", false); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java index 5f2719b4b..d7ce49f74 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/lowtpsphysics/Redstone.java @@ -24,7 +24,8 @@ public Redstone() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("lag-preventions.disable-physics-during-low-tps.redstone.enable", "Disable redstone during low TPS to prevent some lag machines."); + config.addComment("lag-preventions.disable-physics-during-low-tps.redstone.enable", + "Disable redstone during low TPS to prevent some lag machines."); this.disableRedstoneTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.redstone.disable-TPS", 16.0); this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.redstone.log", false); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/EndGatewayCrash.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/EndGatewayCrash.java index de9f43532..0a25111b7 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/EndGatewayCrash.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/EndGatewayCrash.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.World; import org.bukkit.event.EventHandler; @@ -50,8 +51,8 @@ private void onEntityTeleportEvent(EntityTeleportEvent event) { if (event.getEntity().getWorld().getEnvironment() == World.Environment.THE_END && !event.getEntity().isEmpty()) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), - "Prevented "+event.getEntity().getName()+" from going through Gateway at: "+event.getEntity().getLocation() - ); + "Prevented "+event.getEntity().getName()+" from going through Gateway at: " + + LocationUtil.toString(event.getFrom())); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/MultipleEnderdragons.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/MultipleEnderdragons.java index 35314146b..b4b290926 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/MultipleEnderdragons.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/MultipleEnderdragons.java @@ -44,7 +44,7 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) private void onEntityTeleportEvent(EntityTeleportEvent event) { - if (event.getEntity().getWorld().getEnvironment() == World.Environment.THE_END && event.getEntity().getType() == EntityType.ENDER_DRAGON) { + if (event.getEntity().getWorld().getEnvironment() == World.Environment.THE_END && event.getEntityType() == EntityType.ENDER_DRAGON) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(),"Prevented Enderdragon from teleporting."); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/RedstoneOnTrapdoorCrash.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/RedstoneOnTrapdoorCrash.java index 3f8ee1e32..bc0171959 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/RedstoneOnTrapdoorCrash.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/RedstoneOnTrapdoorCrash.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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; @@ -37,7 +38,7 @@ public RedstoneOnTrapdoorCrash() { this.logIsEnabled = config.getBoolean("patches.crash-exploits.prevent-redstone-on-trapdoor-crash.log", true); this.trapdoorActivationLimit = config.getInt("patches.crash-exploits.prevent-redstone-on-trapdoor-crash.max-trapdoor-activations-by-redstone-per-time", 10); this.trapdoorActivationCache = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis( - config.getInt("patches.crash-exploits.prevent-redstone-on-trapdoor-crash.time-in-ticks", 30, "1 sec = 20 ticks") * 50L + Math.max(config.getInt("patches.crash-exploits.prevent-redstone-on-trapdoor-crash.time-in-ticks", 30, "1 sec = 20 ticks"), 1) * 50L )).build(); } @@ -69,21 +70,15 @@ private void onRedstonePowerTrapdoor(BlockRedstoneEvent event) { final Location trapdoorLoc = block.getLocation(); Integer activationCount = trapdoorActivationCache.getIfPresent(trapdoorLoc); + if (activationCount == null) activationCount = 0; - if (activationCount == null) { - // Trapdoor has not been cached yet - trapdoorActivationCache.put(trapdoorLoc, 1); - } else { - activationCount++; - trapdoorActivationCache.put(trapdoorLoc, activationCount); - if (activationCount > trapdoorActivationLimit) { - block.setType(AIR); - if (logIsEnabled) LogUtil.moduleLog(Level.WARNING, name(), "Prevented possible trapdoor crash at " + - "x: "+trapdoorLoc.getX() + ", " + - "y: "+trapdoorLoc.getY() + ", " + - "z: "+trapdoorLoc.getZ() + ", " + - "world: "+trapdoorLoc.getWorld().getName()); - } + activationCount++; + trapdoorActivationCache.put(trapdoorLoc, activationCount); + + if (activationCount > trapdoorActivationLimit) { + block.setType(AIR); + if (logIsEnabled) LogUtil.moduleLog(Level.WARNING, name(), "Prevented potential trapdoor crash at " + + LocationUtil.toString(trapdoorLoc)); } } @@ -95,11 +90,8 @@ private void onBlockPlace(BlockPlaceEvent event) { if (MaterialUtil.TRAPDOORS.contains(block.getRelative(BlockFace.DOWN).getType())) { event.setCancelled(true); - if (logIsEnabled) LogUtil.moduleLog(Level.WARNING, name(), "Prevented possible trapdoor crash at " + - "x: "+block.getLocation().getX() + ", " + - "y: "+block.getLocation().getY() + ", " + - "z: "+block.getLocation().getZ() + ", " + - "world: "+block.getLocation().getWorld().getName()); + if (logIsEnabled) LogUtil.moduleLog(Level.WARNING, name(), "Prevented potential trapdoor crash at " + + LocationUtil.toString(block.getLocation())); } } } \ No newline at end of file diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java index 682b15b7b..c46961936 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java @@ -3,6 +3,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 me.moomoo.anarchyexploitfixes.utils.LogUtil; import me.moomoo.anarchyexploitfixes.utils.models.ExpiringSet; import org.bukkit.event.EventHandler; @@ -59,11 +60,7 @@ private void onTeleport(EntityTeleportEvent event) { if (recentWorldChangers.contains(event.getEntity().getUniqueId())) { event.setCancelled(true); if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Cancelled too fast world teleport of entity: " + - event.getEntityType().name() + " at " + - "x: "+event.getEntity().getLocation().getX() + ", " + - "y: "+event.getEntity().getLocation().getY() + ", " + - "z: "+event.getEntity().getLocation().getZ() + ", " + - "world: "+event.getEntity().getLocation().getWorld().getName()); + event.getEntityType().name() + " at " + LocationUtil.toString(event.getFrom())); } else { recentWorldChangers.add(event.getEntity().getUniqueId()); } 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 60b712fd3..b4b3a59a2 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 @@ -1,7 +1,6 @@ package me.moomoo.anarchyexploitfixes.modules.preventions; import com.cryptomorin.xseries.XMaterial; -import com.google.common.collect.Sets; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; @@ -24,7 +23,7 @@ public class NetherRoof implements AnarchyExploitFixesModule, Listener { - private static final Iterable CARDINAL_FACES = Sets.newHashSet(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST); + private static final BlockFace[] CARDINAL_FACES = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; private final Material AIR, NETHER_PORTAL, NETHERRACK; private final boolean safe_teleport_enabled; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java index a551992f5..aa5a72a68 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/ChunkUtil.java @@ -7,22 +7,6 @@ public class ChunkUtil { - public static int getMaterialCount(Chunk chunk, Material material) { - final int minY = guessMinWorldHeight(chunk.getWorld()); - final int maxY = chunk.getWorld().getMaxHeight(); - int count = 0; - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - for (int y = minY; y < maxY; y++) { - if (chunk.getBlock(x, y, z).getType() == material) { - count++; - } - } - } - } - return count; - } - public static void createBedrockLayer(Chunk chunk, int y) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java index d7cf32c24..2c2b8398d 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/CommandUtil.java @@ -1,7 +1,5 @@ package me.moomoo.anarchyexploitfixes.utils; -import java.util.Arrays; - public class CommandUtil { /* @@ -29,8 +27,4 @@ public static String cutLastArgument(String cmd) { cmdBuilder.append(cmdSplit[i]).append(" "); return cmdBuilder.toString(); } - - public static String mergeArgs(String[] args, int start) { - return String.join(" ", Arrays.copyOfRange(args, start, args.length)); - } } 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 77ae410a7..b8366bab2 100644 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/LocationUtil.java @@ -7,6 +7,10 @@ public class LocationUtil { + public static String toString(Location location) { + return "[" + location.getWorld().getName() + "] x=" + location.getBlockX() + ", y=" + location.getBlockY() + ", z=" + location.getBlockZ(); + } + public static boolean isNetherCeiling(Location location) { return location.getWorld().getEnvironment() == World.Environment.NETHER && location.getY() > AnarchyExploitFixes.getConfiguration().nether_ceiling_max_y;