diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 96e8ddad1..23fd8937b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -42,6 +42,7 @@ import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.uuid.UUIDHandler; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockCategories; @@ -669,6 +670,12 @@ public class BukkitUtil extends WorldUtil { return this.tileEntityTypes; } + @Override + public int getTileEntityCount(String world, BlockVector2 chunk) { + return Bukkit.getWorld(world).getChunkAt(chunk.getBlockX(), chunk.getBlockZ()) + .getTileEntities().length; + } + private static void ensureLoaded(final String world, final int x, final int z, final Consumer chunkConsumer) { PaperLib.getChunkAtAsync(getWorld(world), x >> 4, z >> 4, true) diff --git a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java index ca7eb60e5..0df6c3a3c 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java +++ b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java @@ -46,6 +46,8 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; import java.util.Set; public class ProcessedWEExtent extends AbstractDelegateExtent { @@ -53,12 +55,11 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { private final Set mask; private final String world; private final int max; - int BScount = 0; int Ecount = 0; - boolean BSblocked = false; boolean Eblocked = false; private int count; private Extent parent; + private Map tileEntityCount = new HashMap<>(); public ProcessedWEExtent(String world, Set mask, int max, Extent child, Extent parent) { @@ -93,13 +94,15 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { final boolean isTile = WorldUtil.IMP.getTileEntityTypes().contains(block.getBlockType()); if (isTile) { - if (this.BSblocked) { + final Integer[] tileEntityCount = this.tileEntityCount.computeIfAbsent(getChunkKey(location), + key -> new Integer[] {WorldUtil.IMP.getTileEntityCount(world, + BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4))}); + if (tileEntityCount[0] >= Settings.Chunk_Processor.MAX_TILES) { return false; - } - if (++this.BScount >= Settings.Chunk_Processor.MAX_TILES) { - this.BSblocked = true; + } else { + tileEntityCount[0]++; PlotSquared.debug(Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getX() + "," - + location.getZ()); + + location.getZ()); } } if (WEManager.maskContains(this.mask, location.getX(), location.getY(), location.getZ())) { @@ -145,4 +148,10 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { return WEManager.maskContains(this.mask, position.getX(), position.getZ()) && super .setBiome(position, biome); } + + + private static long getChunkKey(final BlockVector3 location) { + return (long) (location.getBlockX() >> 4) & 4294967295L | ((long) (location.getBlockZ() >> 4) & 4294967295L) << 32; + } + } diff --git a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java index 940e908eb..683f59db1 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java @@ -220,4 +220,6 @@ public abstract class WorldUtil { public abstract Collection getTileEntityTypes(); + public abstract int getTileEntityCount(String world, BlockVector2 chunk); + }