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;
}
Plot plot = area.getOwnedPlotAbs(location);
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
event.setCancelled(true);
}
switch (entity.getType()) {
case ENDER_CRYSTAL:
if (plot == null) {
@ -34,8 +37,5 @@ public class EntitySpawnListener implements Listener {
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;
}
if (cap == 0) {
return false;
return true;
}
if (mobs == null) {
mobs = plot.countEntities();
}
if (mobs[i] >= cap) {
if (mobs[i]++ >= cap) {
return true;
}
}
if (mobs != null) {
plot.setMeta("EntityCount", mobs);
plot.setMeta("EntityCountTime", System.currentTimeMillis());
}
return false;
}

View File

@ -425,6 +425,10 @@ public class BukkitChunkManager extends ChunkManager {
@Override
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();
World world = BukkitUtil.getWorld(area.worldname);