mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 06:36:44 +01:00
Cache entity count every second
This commit is contained in:
parent
1ae694ff5b
commit
facd43700d
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user