mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Entity tracking and invalid world detection
This commit is contained in:
parent
12f024664a
commit
1f8702f072
@ -136,8 +136,10 @@ public class PlotSquared {
|
||||
|
||||
public static Set<Plot> getPlots() {
|
||||
final ArrayList<Plot> newplots = new ArrayList<>();
|
||||
for (final HashMap<PlotId, Plot> world : plots.values()) {
|
||||
newplots.addAll(world.values());
|
||||
for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||
if (isPlotWorld(entry.getKey())) {
|
||||
newplots.addAll(entry.getValue().values());
|
||||
}
|
||||
}
|
||||
return new LinkedHashSet<>(newplots);
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ public abstract class ChunkManager {
|
||||
return new ChunkLoc(x, z);
|
||||
}
|
||||
|
||||
public abstract int countEntities(Plot plot);
|
||||
|
||||
public abstract boolean loadChunk(String world, ChunkLoc loc);
|
||||
|
||||
public abstract boolean unloadChunk(String world, ChunkLoc loc);
|
||||
|
@ -865,4 +865,76 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
clearAllEntities(MainUtil.getPlot(worldname, pos2));
|
||||
// FIXME swap plots
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countEntities(Plot plot) {
|
||||
int count = 0;
|
||||
World world = BukkitUtil.getWorld(plot.world);
|
||||
|
||||
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
int bx = bot.getX() >> 4;
|
||||
int bz = bot.getZ() >> 4;
|
||||
|
||||
int tx = top.getX() >> 4;
|
||||
int tz = top.getZ() >> 4;
|
||||
|
||||
int size = (tx-bx) << 4;
|
||||
|
||||
HashSet<Chunk> chunks = new HashSet<>();
|
||||
for (int X = bx; X <= tx; X++) {
|
||||
for (int Z = bz; Z <= tz; Z++) {
|
||||
chunks.add(world.getChunkAt(X,Z));
|
||||
}
|
||||
}
|
||||
|
||||
boolean doWhole = false;
|
||||
List<Entity> entities = null;
|
||||
if (size > 200) {
|
||||
entities = world.getEntities();
|
||||
if (entities.size() < 16 + (size * size / 64)) {
|
||||
doWhole = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doWhole) {
|
||||
for (final Entity entity : entities) {
|
||||
org.bukkit.Location loc = entity.getLocation();
|
||||
Chunk chunk = loc.getChunk();
|
||||
if (chunks.contains(chunk)) {
|
||||
int X = chunk.getX();
|
||||
int Z = chunk.getX();
|
||||
if (X > bx && X < tx && Z > bz && Z < tz) {
|
||||
count++;
|
||||
}
|
||||
else {
|
||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(loc));
|
||||
if (plot.id.equals(id)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (Chunk chunk : chunks) {
|
||||
int X = chunk.getX();
|
||||
int Z = chunk.getX();
|
||||
Entity[] ents = chunk.getEntities();
|
||||
if (X == bx || X == tx || Z == bz || Z == tz) {
|
||||
for (final Entity entity : ents) {
|
||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity));
|
||||
if (plot.id.equals(id)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
count += ents.length;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user