Cache entity count every second

This commit is contained in:
Jesse Boyd 2016-08-07 04:00:50 +10:00
parent 1ae694ff5b
commit facd43700d
3 changed files with 14 additions and 5 deletions

View File

@ -22,6 +22,9 @@ public class EntitySpawnListener implements Listener {
return; return;
} }
Plot plot = area.getOwnedPlotAbs(location); Plot plot = area.getOwnedPlotAbs(location);
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
event.setCancelled(true);
}
switch (entity.getType()) { switch (entity.getType()) {
case ENDER_CRYSTAL: case ENDER_CRYSTAL:
if (plot == null) { if (plot == null) {
@ -34,8 +37,5 @@ public class EntitySpawnListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
event.setCancelled(true);
}
} }
} }

View File

@ -1409,15 +1409,20 @@ public class PlayerEvents extends PlotListener implements Listener {
continue; continue;
} }
if (cap == 0) { if (cap == 0) {
return false; return true;
} }
if (mobs == null) { if (mobs == null) {
mobs = plot.countEntities(); mobs = plot.countEntities();
} }
if (mobs[i] >= cap) { if (mobs[i]++ >= cap) {
return true; return true;
} }
} }
if (mobs != null) {
plot.setMeta("EntityCount", mobs);
plot.setMeta("EntityCountTime", System.currentTimeMillis());
}
return false; return false;
} }

View File

@ -425,6 +425,10 @@ public class BukkitChunkManager extends ChunkManager {
@Override @Override
public int[] countEntities(Plot plot) { public int[] countEntities(Plot plot) {
int[] existing = (int[]) plot.getMeta("EntityCount");
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
return existing;
}
PlotArea area = plot.getArea(); PlotArea area = plot.getArea();
World world = BukkitUtil.getWorld(area.worldname); World world = BukkitUtil.getWorld(area.worldname);