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 dd0d62c1c..48c3a931f 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 @@ -171,10 +171,12 @@ private void onSpawn(EntitySpawnEvent event) { entityCount++; if (entityCount <= maxAllowedPerChunk) continue; - entity.getScheduler().run(plugin, kill -> entity.remove(), null); - 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); + 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); + }, 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 04c27d4cc..1aa339807 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 @@ -25,7 +25,7 @@ public class VehicleLimit implements AnarchyExploitFixesModule, Listener { private final AnarchyExploitFixes plugin; - private final Set VEHICLE_TYPES; + private final Set VEHICLE_TYPE_CACHE; private ScheduledTask scheduledTask; private final long checkPeriod; private final int maxVehiclesPerChunk; @@ -34,11 +34,11 @@ public class VehicleLimit implements AnarchyExploitFixesModule, Listener { public VehicleLimit() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); - this.VEHICLE_TYPES = new HashSet<>(); // Used to cache entity types of vehicles for faster operations + this.VEHICLE_TYPE_CACHE = new HashSet<>(); // Used to cache entity types of vehicles for faster operations // Prefill with known types; - this.VEHICLE_TYPES.addAll(EntityUtil.BOATS); - this.VEHICLE_TYPES.addAll(EntityTags.HORSES.getValues()); - this.VEHICLE_TYPES.addAll(EntityTags.MINECARTS.getValues()); + this.VEHICLE_TYPE_CACHE.addAll(EntityUtil.BOATS); + this.VEHICLE_TYPE_CACHE.addAll(EntityTags.HORSES.getValues()); + this.VEHICLE_TYPE_CACHE.addAll(EntityTags.MINECARTS.getValues()); Config config = AnarchyExploitFixes.getConfiguration(); config.addComment("chunk-limits.vehicle-limit.enable", "Limit the amount of vehicles to prevent some lag machines involving boats and a dispenser."); @@ -82,7 +82,7 @@ private void onCreate(VehicleCreateEvent event) { for (Entity entity : event.getVehicle().getChunk().getEntities()) { final EntityType type = entity.getType(); - if (VEHICLE_TYPES.contains(type)) { + if (VEHICLE_TYPE_CACHE.contains(type)) { vehicleCount++; if (vehicleCount <= maxVehiclesPerChunk) continue; @@ -97,7 +97,7 @@ private void onCreate(VehicleCreateEvent event) { } if (entity instanceof Vehicle) { - VEHICLE_TYPES.add(type); // Add type of vehicle to HashSet for faster operation in the future + VEHICLE_TYPE_CACHE.add(type); // Add type of vehicle to HashSet for faster operation in the future vehicleCount++; if (vehicleCount <= maxVehiclesPerChunk) continue; @@ -115,15 +115,14 @@ private void run() { for (World world : plugin.getServer().getWorlds()) { for (Chunk chunk : world.getLoadedChunks()) { plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> { - Chunk.LoadLevel level = chunk.getLoadLevel(); - if (!level.equals(Chunk.LoadLevel.ENTITY_TICKING) && !level.equals(Chunk.LoadLevel.TICKING)) return; + if (!chunk.isEntitiesLoaded()) return; int vehicleCount = 0; for (Entity entity : chunk.getEntities()) { final EntityType type = entity.getType(); - if (VEHICLE_TYPES.contains(type)) { + if (VEHICLE_TYPE_CACHE.contains(type)) { vehicleCount++; if (vehicleCount <= maxVehiclesPerChunk) continue; @@ -139,7 +138,7 @@ private void run() { } if (entity instanceof Vehicle) { - VEHICLE_TYPES.add(type); // Add type of vehicle to HashSet for faster operation in the future + VEHICLE_TYPE_CACHE.add(type); // Add type of vehicle to HashSet for faster operation in the future vehicleCount++; if (vehicleCount <= maxVehiclesPerChunk) continue; 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 03cf7448f..4eb45e7b5 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 @@ -115,9 +115,11 @@ private void checkVillagersInChunk(Chunk chunk) { // 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(), + villager.getScheduler().run(plugin, kill -> { + villager.remove(); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Removing villager of profession type '"+villager.getProfession()+"' at "+villager.getLocation()); - villager.getScheduler().run(plugin, kill -> villager.remove(), null); + }, null); } } 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 cc3fc9ae7..0792686d5 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 @@ -27,7 +27,7 @@ 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, + 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; } @@ -59,14 +59,14 @@ public void disable() { private void run() { for (World world : plugin.getServer().getWorlds()) { for (FallingBlock fallingBlock : world.getEntitiesByClass(FallingBlock.class)) { - if (fallingBlock.getTicksLived() > max_alive_time) { - fallingBlock.getScheduler().run(plugin, kill -> { + fallingBlock.getScheduler().run(plugin, killIfOld -> { + 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."); - }, null); - } + + " in " + fallingBlock.getWorld().getName() + " because it was alive for more than " + max_alive_time + " ticks."); + } + }, null); } } } 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 f071d9601..d1e41a453 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 @@ -72,16 +72,18 @@ private void onLiquidSpread(BlockFromToEvent event) { 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; - } + 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 + diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PreventFloodingMachines.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PreventFloodingMachines.java index 5ad12685c..f2de358b0 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PreventFloodingMachines.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/lagpreventions/PreventFloodingMachines.java @@ -49,10 +49,7 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) private void onPistonExtend(BlockPistonExtendEvent event) { for (Block block : event.getBlocks()) { - if ( - block.getBlockData() instanceof Waterlogged waterlogged - && waterlogged.isWaterlogged() - ) { + if (block.getBlockData() instanceof Waterlogged waterlogged && waterlogged.isWaterlogged()) { if (shouldDeleteWaterlogged) block.setType(Material.AIR); event.setCancelled(true); return; 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 47dbe5824..f6717bf0a 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 @@ -51,17 +51,17 @@ public void disable() { private 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; - - if (projectile.getTicksLived() > max_alive_time) { - projectile.getScheduler().run(plugin, removeOld -> projectile.remove(), null); + switch (projectile.getType()) { + case ENDER_PEARL, WITHER_SKULL, FISHING_HOOK, ENDER_SIGNAL -> { + continue; + } } + + projectile.getScheduler().run(plugin, removeIfOld -> { + if (projectile.getTicksLived() > max_alive_time) { + projectile.remove(); + } + }, null); } } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveAllSkullsPeriodically.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveAllSkullsPeriodically.java index 57a5aa628..cc89a3ae0 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveAllSkullsPeriodically.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveAllSkullsPeriodically.java @@ -50,7 +50,7 @@ public void disable() { private void run() { for (World world : plugin.getServer().getWorlds()) { for (WitherSkull witherSkull : world.getEntitiesByClass(WitherSkull.class)) { - witherSkull.getScheduler().run(plugin, remove -> witherSkull.remove(), null); + witherSkull.getScheduler().run(plugin, kill -> witherSkull.remove(), null); } } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveSkullsAfterXTicks.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveSkullsAfterXTicks.java index 98afd8373..7cd998af1 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveSkullsAfterXTicks.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/withers/RemoveSkullsAfterXTicks.java @@ -57,9 +57,11 @@ public void disable() { private void run() { for (World world : plugin.getServer().getWorlds()) { for (WitherSkull witherSkull : world.getEntitiesByClass(WitherSkull.class)) { - if (witherSkull.getTicksLived() > maxAgeInTicks) { - witherSkull.getScheduler().run(plugin, kill -> witherSkull.remove(), null); - } + witherSkull.getScheduler().run(plugin, killIfOld -> { + if (witherSkull.getTicksLived() > maxAgeInTicks) { + witherSkull.remove(); + } + }, null); } } }