Make the tile entity limit in ProcessedWEExtent apply per chunk rather than per edit

This commit is contained in:
Alexander Söderberg
2020-05-13 14:54:54 +02:00
parent 8c0f7b207e
commit e6a9daf31a
3 changed files with 25 additions and 7 deletions

View File

@ -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<CuboidRegion> 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<Long, Integer[]> tileEntityCount = new HashMap<>();
public ProcessedWEExtent(String world, Set<CuboidRegion> 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;
}
}

View File

@ -220,4 +220,6 @@ public abstract class WorldUtil {
public abstract Collection<BlockType> getTileEntityTypes();
public abstract int getTileEntityCount(String world, BlockVector2 chunk);
}