mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-10-31 17:43:44 +01:00 
			
		
		
		
	Cache entity count every second
This commit is contained in:
		| @@ -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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jesse Boyd
					Jesse Boyd