mirror of
https://github.com/kaboomserver/extras.git
synced 2025-08-04 11:36:28 +00:00
Minor restructure
This commit is contained in:
parent
91b3b8c92d
commit
4fe8d0ee8d
1 changed files with 47 additions and 54 deletions
|
@ -40,10 +40,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.block.TNTPrimeEvent;
|
import com.destroystokyo.paper.event.block.TNTPrimeEvent;
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
|
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
|
||||||
|
@ -83,15 +79,6 @@ class EntitySpawn implements Listener {
|
||||||
|
|
||||||
limitAreaEffectCloudRadius(cloud);
|
limitAreaEffectCloudRadius(cloud);
|
||||||
break;
|
break;
|
||||||
case PRIMED_TNT:
|
|
||||||
final int tntCount = world.getEntitiesByClass(TNTPrimed.class).size();
|
|
||||||
|
|
||||||
if (tntCount > 180) {
|
|
||||||
for (Entity tnt : world.getEntitiesByClass(TNTPrimed.class)) {
|
|
||||||
tnt.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MAGMA_CUBE:
|
case MAGMA_CUBE:
|
||||||
case SLIME:
|
case SLIME:
|
||||||
final Slime slime = (Slime) entity;
|
final Slime slime = (Slime) entity;
|
||||||
|
@ -117,35 +104,6 @@ class EntitySpawn implements Listener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEntityLimitReached(Location location, int count, int countLimit, boolean isAddToWorldEvent) {
|
|
||||||
/*
|
|
||||||
Add 1 if EntitySpawnEvent triggered the method, due to the entity count being
|
|
||||||
one larger in EntityAddToWorldEvent compared to EntitySpawnEvent
|
|
||||||
This prevents EntityAddToWorldEvent from triggering an entity removal before
|
|
||||||
EntitySpawnEvent's event cancel
|
|
||||||
*/
|
|
||||||
if (!isAddToWorldEvent) {
|
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count >= countLimit) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkEntityWorldLimitRemove(World world) {
|
|
||||||
if (world.getEntities().size() > 1024) {
|
|
||||||
for (Entity entity : world.getEntities()) {
|
|
||||||
if (entity.getType() != EntityType.PLAYER) {
|
|
||||||
entity.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkIllegalEquipment(LivingEntity mob) {
|
private void checkIllegalEquipment(LivingEntity mob) {
|
||||||
try {
|
try {
|
||||||
for (ItemStack item : mob.getEquipment().getArmorContents()) {
|
for (ItemStack item : mob.getEquipment().getArmorContents()) {
|
||||||
|
@ -198,6 +156,43 @@ class EntitySpawn implements Listener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkShouldRemoveEntities(World world) {
|
||||||
|
final int entityCount = world.getEntities().size();
|
||||||
|
final int tntCount = world.getEntitiesByClass(TNTPrimed.class).size();
|
||||||
|
|
||||||
|
if (entityCount > 1024) {
|
||||||
|
for (Entity entity : world.getEntities()) {
|
||||||
|
if (entity.getType() != EntityType.PLAYER) {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (tntCount > 180) {
|
||||||
|
for (Entity tnt : world.getEntitiesByClass(TNTPrimed.class)) {
|
||||||
|
tnt.remove();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEntityLimitReached(Location location, int count, int countLimit, boolean isAddToWorldEvent) {
|
||||||
|
/*
|
||||||
|
Add 1 if EntitySpawnEvent triggered the method, due to the entity count being
|
||||||
|
one larger in EntityAddToWorldEvent compared to EntitySpawnEvent
|
||||||
|
This prevents EntityAddToWorldEvent from triggering an entity removal before
|
||||||
|
EntitySpawnEvent's event cancel
|
||||||
|
*/
|
||||||
|
if (!isAddToWorldEvent) {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count >= countLimit) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void limitAreaEffectCloudRadius(AreaEffectCloud cloud) {
|
private void limitAreaEffectCloudRadius(AreaEffectCloud cloud) {
|
||||||
if (cloud.getRadius() > 40) {
|
if (cloud.getRadius() > 40) {
|
||||||
cloud.setRadius(40);
|
cloud.setRadius(40);
|
||||||
|
@ -264,21 +259,19 @@ class EntitySpawn implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityAddToWorld(EntityAddToWorldEvent event) {
|
void onEntityAddToWorld(EntityAddToWorldEvent event) {
|
||||||
final World world = event.getEntity().getWorld();
|
|
||||||
final Entity entity = event.getEntity();
|
final Entity entity = event.getEntity();
|
||||||
|
final World world = entity.getWorld();
|
||||||
if (!checkEntityWorldLimitRemove(world)) {
|
final EntityType entityType = entity.getType();
|
||||||
final EntityType entityType = entity.getType();
|
final Location location = entity.getLocation();
|
||||||
final Location location = entity.getLocation();
|
final boolean isAddToWorldEvent = true;
|
||||||
final boolean isAddToWorldEvent = true;
|
|
||||||
|
if (checkEntityLimits(entityType, location, isAddToWorldEvent)) {
|
||||||
if (checkEntityLimits(entityType, location, isAddToWorldEvent)) {
|
entity.remove();
|
||||||
entity.remove();
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyEntityChanges(entity);
|
applyEntityChanges(entity);
|
||||||
|
checkShouldRemoveEntities(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue