mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Make the tile entity limit in ProcessedWEExtent apply per chunk rather than per edit
This commit is contained in:
parent
8c0f7b207e
commit
e6a9daf31a
@ -42,6 +42,7 @@ import com.plotsquared.core.util.task.TaskManager;
|
|||||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||||
@ -669,6 +670,12 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return this.tileEntityTypes;
|
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,
|
private static void ensureLoaded(final String world, final int x, final int z,
|
||||||
final Consumer<Chunk> chunkConsumer) {
|
final Consumer<Chunk> chunkConsumer) {
|
||||||
PaperLib.getChunkAtAsync(getWorld(world), x >> 4, z >> 4, true)
|
PaperLib.getChunkAtAsync(getWorld(world), x >> 4, z >> 4, true)
|
||||||
|
@ -46,6 +46,8 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ProcessedWEExtent extends AbstractDelegateExtent {
|
public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||||
@ -53,12 +55,11 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
|||||||
private final Set<CuboidRegion> mask;
|
private final Set<CuboidRegion> mask;
|
||||||
private final String world;
|
private final String world;
|
||||||
private final int max;
|
private final int max;
|
||||||
int BScount = 0;
|
|
||||||
int Ecount = 0;
|
int Ecount = 0;
|
||||||
boolean BSblocked = false;
|
|
||||||
boolean Eblocked = false;
|
boolean Eblocked = false;
|
||||||
private int count;
|
private int count;
|
||||||
private Extent parent;
|
private Extent parent;
|
||||||
|
private Map<Long, Integer[]> tileEntityCount = new HashMap<>();
|
||||||
|
|
||||||
public ProcessedWEExtent(String world, Set<CuboidRegion> mask, int max, Extent child,
|
public ProcessedWEExtent(String world, Set<CuboidRegion> mask, int max, Extent child,
|
||||||
Extent parent) {
|
Extent parent) {
|
||||||
@ -93,13 +94,15 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
|||||||
|
|
||||||
final boolean isTile = WorldUtil.IMP.getTileEntityTypes().contains(block.getBlockType());
|
final boolean isTile = WorldUtil.IMP.getTileEntityTypes().contains(block.getBlockType());
|
||||||
if (isTile) {
|
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;
|
return false;
|
||||||
}
|
} else {
|
||||||
if (++this.BScount >= Settings.Chunk_Processor.MAX_TILES) {
|
tileEntityCount[0]++;
|
||||||
this.BSblocked = true;
|
|
||||||
PlotSquared.debug(Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getX() + ","
|
PlotSquared.debug(Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getX() + ","
|
||||||
+ location.getZ());
|
+ location.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (WEManager.maskContains(this.mask, location.getX(), location.getY(), 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
|
return WEManager.maskContains(this.mask, position.getX(), position.getZ()) && super
|
||||||
.setBiome(position, biome);
|
.setBiome(position, biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static long getChunkKey(final BlockVector3 location) {
|
||||||
|
return (long) (location.getBlockX() >> 4) & 4294967295L | ((long) (location.getBlockZ() >> 4) & 4294967295L) << 32;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -220,4 +220,6 @@ public abstract class WorldUtil {
|
|||||||
|
|
||||||
public abstract Collection<BlockType> getTileEntityTypes();
|
public abstract Collection<BlockType> getTileEntityTypes();
|
||||||
|
|
||||||
|
public abstract int getTileEntityCount(String world, BlockVector2 chunk);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user