Check if chunks are loaded

This commit is contained in:
mathias 2019-08-01 17:58:50 +03:00
parent 5186696d1c
commit aadc92ce7a

View file

@ -111,6 +111,8 @@ class EntitySpawn implements Listener {
@EventHandler
void onEntityAddToWorld(EntityAddToWorldEvent event) {
if (event.getEntityType() != EntityType.PLAYER) {
if (event.getEntity().getLocation().isGenerated() == true &&
event.getEntity().getLocation().isChunkLoaded() == true) {
final Entity entity = event.getEntity();
final int count = entity.getLocation().getChunk().getEntities().length;
@ -119,10 +121,13 @@ class EntitySpawn implements Listener {
}
}
}
}
@EventHandler
void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() != EntityType.PLAYER) {
if (event.getLocation().isGenerated() == true &&
event.getLocation().isChunkLoaded() == true) {
final int entityCount = event.getLocation().getChunk().getEntities().length;
if (entityCount > 50) {
@ -130,6 +135,7 @@ class EntitySpawn implements Listener {
}
}
}
}
@EventHandler
void onItemSpawn(ItemSpawnEvent event) {
@ -143,12 +149,17 @@ class EntitySpawn implements Listener {
@EventHandler
void onPreCreatureSpawn(PreCreatureSpawnEvent event) {
if (event.getType() != EntityType.PLAYER) {
if (event.getSpawnLocation().isGenerated() == true &&
event.getSpawnLocation().isChunkLoaded() == true) {
final int entityCount = event.getSpawnLocation().getChunk().getEntities().length;
if (entityCount > 50) {
event.setCancelled(true);
return;
} else if (event.getType() == EntityType.ENDER_DRAGON) {
}
}
if (event.getType() == EntityType.ENDER_DRAGON) {
final int dragonCount = event.getSpawnLocation().getWorld().getEntitiesByClass(EnderDragon.class).size();
if (dragonCount > 25) {