mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-27 09:55:36 -05:00
Check if chunks are loaded
This commit is contained in:
parent
5186696d1c
commit
aadc92ce7a
1 changed files with 23 additions and 12 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue