mirror of
https://github.com/kaboomserver/extras.git
synced 2024-12-03 20:51:06 -05:00
TNT optimization test
This commit is contained in:
parent
fa4868908b
commit
7546fa0e1e
1 changed files with 41 additions and 22 deletions
|
@ -18,8 +18,8 @@ import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||||
|
@ -69,22 +69,40 @@ public final class EntitySpawn implements Listener {
|
||||||
EntitySpawnEvent's event cancel
|
EntitySpawnEvent's event cancel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final int chunkEntityCount =
|
switch (entityType) {
|
||||||
!isAddToWorldEvent ? chunk.getEntities().length + 1
|
case ENDER_DRAGON:
|
||||||
: chunk.getEntities().length;
|
final int worldDragonCount =
|
||||||
final int chunkEntityCountLimit = 30;
|
!isAddToWorldEvent ? world.getEntitiesByClass(EnderDragon.class).size() + 1
|
||||||
|
: world.getEntitiesByClass(EnderDragon.class).size();
|
||||||
|
final int worldDragonCountLimit = 24;
|
||||||
|
|
||||||
final int worldDragonCount =
|
if (worldDragonCount >= worldDragonCountLimit) {
|
||||||
!isAddToWorldEvent ? world.getEntitiesByClass(EnderDragon.class).size() + 1
|
return true;
|
||||||
: world.getEntitiesByClass(EnderDragon.class).size();
|
}
|
||||||
final int worldDragonCountLimit = 24;
|
|
||||||
|
|
||||||
if ((!EntityType.PLAYER.equals(entityType)
|
break;
|
||||||
&& chunkEntityCount >= chunkEntityCountLimit)
|
case PRIMED_TNT:
|
||||||
|
final int worldTntCount =
|
||||||
|
!isAddToWorldEvent ? world.getEntitiesByClass(TNTPrimed.class).size() + 1
|
||||||
|
: world.getEntitiesByClass(TNTPrimed.class).size();
|
||||||
|
final int worldTntCountLimit = 100;
|
||||||
|
|
||||||
|| (EntityType.ENDER_DRAGON.equals(entityType)
|
if (worldTntCount >= worldTntCountLimit) {
|
||||||
&& worldDragonCount >= worldDragonCountLimit)) {
|
return true;
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!EntityType.PLAYER.equals(entityType)) {
|
||||||
|
final int chunkEntityCount =
|
||||||
|
!isAddToWorldEvent ? chunk.getEntities().length + 1
|
||||||
|
: chunk.getEntities().length;
|
||||||
|
final int chunkEntityCountLimit = 30;
|
||||||
|
if (chunkEntityCount >= chunkEntityCountLimit) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +233,7 @@ public final class EntitySpawn implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityExplode(final EntityExplodeEvent event) {
|
void onExplosionPrime(final ExplosionPrimeEvent event) {
|
||||||
if (EntityType.MINECART_TNT.equals(event.getEntityType())
|
if (EntityType.MINECART_TNT.equals(event.getEntityType())
|
||||||
&& event.getEntity().getWorld().getEntitiesByClass(ExplosiveMinecart.class).size() > 80) {
|
&& event.getEntity().getWorld().getEntitiesByClass(ExplosiveMinecart.class).size() > 80) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -233,10 +251,9 @@ public final class EntitySpawn implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Entity entity = event.getEntity();
|
final EntityType entityType = event.getEntityType();
|
||||||
final EntityType entityType = entity.getType();
|
final Chunk chunk = event.getLocation().getChunk();
|
||||||
final Chunk chunk = entity.getChunk();
|
final World world = event.getLocation().getWorld();
|
||||||
final World world = entity.getWorld();
|
|
||||||
final boolean isAddToWorldEvent = false;
|
final boolean isAddToWorldEvent = false;
|
||||||
|
|
||||||
if (isEntityLimitReached(entityType, chunk, world, isAddToWorldEvent)) {
|
if (isEntityLimitReached(entityType, chunk, world, isAddToWorldEvent)) {
|
||||||
|
@ -244,6 +261,8 @@ public final class EntitySpawn implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Entity entity = event.getEntity();
|
||||||
|
|
||||||
applyEntityChanges(entity);
|
applyEntityChanges(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,9 +278,9 @@ public final class EntitySpawn implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final EntityType entityType = lightning.getType();
|
final EntityType entityType = EntityType.LIGHTNING;
|
||||||
final Chunk chunk = lightning.getChunk();
|
final Chunk chunk = lightning.getChunk();
|
||||||
final World world = lightning.getWorld();
|
final World world = event.getWorld();
|
||||||
final boolean isAddToWorldEvent = false;
|
final boolean isAddToWorldEvent = false;
|
||||||
|
|
||||||
if (isEntityLimitReached(entityType, chunk, world, isAddToWorldEvent)) {
|
if (isEntityLimitReached(entityType, chunk, world, isAddToWorldEvent)) {
|
||||||
|
@ -306,7 +325,7 @@ public final class EntitySpawn implements Listener {
|
||||||
case EXPLOSION:
|
case EXPLOSION:
|
||||||
case FIRE:
|
case FIRE:
|
||||||
case REDSTONE:
|
case REDSTONE:
|
||||||
if (event.getBlock().getWorld().getEntitiesByClass(TNTPrimed.class).size() > 120) {
|
if (event.getBlock().getWorld().getEntitiesByClass(TNTPrimed.class).size() > 100) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue