mirror of
https://github.com/kaboomserver/extras.git
synced 2025-02-11 11:40:19 +00:00
Clean up an abomination of code
This commit is contained in:
parent
0410492f76
commit
b4d43d474f
2 changed files with 205 additions and 287 deletions
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||||
|
@ -23,6 +24,7 @@ public class Main extends JavaPlugin {
|
||||||
static HashSet<Material> nonSolidSingularBlockList = new HashSet<>();
|
static HashSet<Material> nonSolidSingularBlockList = new HashSet<>();
|
||||||
static HashSet<Material> nonSolidWallMountedBlockList = new HashSet<>();
|
static HashSet<Material> nonSolidWallMountedBlockList = new HashSet<>();
|
||||||
static HashSet<Material> nonSolidWaterBlockList = new HashSet<>();
|
static HashSet<Material> nonSolidWaterBlockList = new HashSet<>();
|
||||||
|
static HashSet<SpawnReason> spawnReasonList = new HashSet<>();
|
||||||
|
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
/* Fill lists */
|
/* Fill lists */
|
||||||
|
@ -650,6 +652,15 @@ public class Main extends JavaPlugin {
|
||||||
this.nonSolidBlockList.addAll(nonSolidDoubleBlockList);
|
this.nonSolidBlockList.addAll(nonSolidDoubleBlockList);
|
||||||
this.nonSolidBlockList.addAll(nonSolidSingularBlockList);
|
this.nonSolidBlockList.addAll(nonSolidSingularBlockList);
|
||||||
this.nonSolidBlockList.addAll(nonSolidWallMountedBlockList);
|
this.nonSolidBlockList.addAll(nonSolidWallMountedBlockList);
|
||||||
|
|
||||||
|
Collections.addAll(
|
||||||
|
spawnReasonList,
|
||||||
|
SpawnReason.CUSTOM,
|
||||||
|
SpawnReason.DEFAULT,
|
||||||
|
SpawnReason.DISPENSE_EGG,
|
||||||
|
SpawnReason.SPAWNER,
|
||||||
|
SpawnReason.SPAWNER_EGG
|
||||||
|
);
|
||||||
|
|
||||||
saveResource("config.yml", false);
|
saveResource("config.yml", false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package pw.kaboom.extras;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@ import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
|
||||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||||
|
@ -50,10 +50,91 @@ import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
||||||
import org.bukkit.block.banner.Pattern;
|
import org.bukkit.block.banner.Pattern;
|
||||||
|
|
||||||
class EntitySpawn implements Listener {
|
class EntitySpawn implements Listener {
|
||||||
@EventHandler
|
private boolean checkDragonWorldLimit(World world) {
|
||||||
void onAreaEffectCloudApply(AreaEffectCloudApplyEvent event) {
|
final int dragonCount = world.getEntitiesByClass(EnderDragon.class).size();
|
||||||
final AreaEffectCloud cloud = event.getEntity();
|
|
||||||
|
if (dragonCount > 25) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkEntityChunkLimit(Location location) {
|
||||||
|
if (location.isChunkLoaded()) {
|
||||||
|
final int count = location.getChunk().getEntities().length;
|
||||||
|
|
||||||
|
if (count > 50) {
|
||||||
|
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 checkIllegalArmor(LivingEntity mob) {
|
||||||
|
try {
|
||||||
|
for (ItemStack item : mob.getEquipment().getArmorContents()) {
|
||||||
|
if (checkIllegalBanner(item)) {
|
||||||
|
mob.getEquipment().setArmorContents(
|
||||||
|
new ItemStack[] {null, null, null, null}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception exception) {
|
||||||
|
mob.getEquipment().setArmorContents(
|
||||||
|
new ItemStack[] {null, null, null, null}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ItemStack item = mob.getEquipment().getItemInMainHand();
|
||||||
|
|
||||||
|
if (checkIllegalBanner(item)) {
|
||||||
|
mob.getEquipment().setItemInMainHand(null);
|
||||||
|
}
|
||||||
|
} catch (Exception exception) {
|
||||||
|
mob.getEquipment().setItemInMainHand(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ItemStack item = mob.getEquipment().getItemInOffHand();
|
||||||
|
|
||||||
|
if (checkIllegalBanner(item)) {
|
||||||
|
mob.getEquipment().setItemInOffHand(null);
|
||||||
|
}
|
||||||
|
} catch (Exception exception) {
|
||||||
|
mob.getEquipment().setItemInOffHand(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIllegalBanner(ItemStack item) {
|
||||||
|
if (item != null &&
|
||||||
|
item.hasItemMeta()) {
|
||||||
|
if (item.getItemMeta() instanceof BannerMeta) {
|
||||||
|
final BannerMeta banner = (BannerMeta) item.getItemMeta();
|
||||||
|
|
||||||
|
for (Pattern pattern : banner.getPatterns()) {
|
||||||
|
if (pattern.getColor() == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void limitAreaEffectCloudRadius(AreaEffectCloud cloud) {
|
||||||
if (cloud.getRadius() > 40) {
|
if (cloud.getRadius() > 40) {
|
||||||
cloud.setRadius(40);
|
cloud.setRadius(40);
|
||||||
}
|
}
|
||||||
|
@ -66,16 +147,50 @@ class EntitySpawn implements Listener {
|
||||||
cloud.setRadiusPerTick(0);
|
cloud.setRadiusPerTick(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void limitFollowAttribute(LivingEntity mob) {
|
||||||
|
final AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
|
||||||
|
|
||||||
|
if (followAttribute != null &&
|
||||||
|
followAttribute.getBaseValue() > 40) {
|
||||||
|
followAttribute.setBaseValue(40);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void limitSlimeSize(Slime slime) {
|
||||||
|
if (slime.getSize() > 50) {
|
||||||
|
slime.setSize(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void limitSpawner(CreatureSpawner spawner) {
|
||||||
|
if (spawner.getSpawnedType() == EntityType.FALLING_BLOCK) {
|
||||||
|
if (spawner.getDelay() > 100) {
|
||||||
|
spawner.setMaxSpawnDelay(100);
|
||||||
|
spawner.setDelay(100);
|
||||||
|
spawner.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spawner.getSpawnCount() > 200) {
|
||||||
|
spawner.setSpawnCount(200);
|
||||||
|
spawner.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spawner.getSpawnRange() > 50) {
|
||||||
|
spawner.setSpawnRange(50);
|
||||||
|
spawner.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
void onAreaEffectCloudApply(AreaEffectCloudApplyEvent event) {
|
||||||
|
limitAreaEffectCloudRadius(event.getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockDispense(BlockDispenseEvent event) {
|
void onBlockDispense(BlockDispenseEvent event) {
|
||||||
try {
|
try {
|
||||||
/*BlockStateMeta stateMeta = (BlockStateMeta) event.getItem().getItemMeta();
|
|
||||||
|
|
||||||
/*if (stateMeta.getBlockState() instanceof ShulkerBox) {
|
|
||||||
ShulkerBox shulkerBox = (ShulkerBox) stateMeta.getBlockState();
|
|
||||||
}
|
|
||||||
stateMeta.getBlockState();*/
|
|
||||||
event.getBlock().getState();
|
event.getBlock().getState();
|
||||||
event.getItem().getItemMeta();
|
event.getItem().getItemMeta();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
|
@ -85,111 +200,38 @@ class EntitySpawn implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onCreatureSpawn(CreatureSpawnEvent event) {
|
void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||||
if (event.getSpawnReason() == SpawnReason.CUSTOM ||
|
final LivingEntity mob = event.getEntity();
|
||||||
event.getSpawnReason() == SpawnReason.DEFAULT ||
|
|
||||||
event.getSpawnReason() == SpawnReason.DISPENSE_EGG ||
|
|
||||||
event.getSpawnReason() == SpawnReason.SPAWNER ||
|
|
||||||
event.getSpawnReason() == SpawnReason.SPAWNER_EGG) {
|
|
||||||
final LivingEntity mob = event.getEntity();
|
|
||||||
final AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
|
|
||||||
|
|
||||||
if (followAttribute != null &&
|
if (Main.spawnReasonList.contains(event.getSpawnReason())) {
|
||||||
followAttribute.getBaseValue() > 40) {
|
limitFollowAttribute(mob);
|
||||||
followAttribute.setBaseValue(40);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getEntityType() == EntityType.ARMOR_STAND ||
|
switch (event.getEntityType()) {
|
||||||
event.getEntityType() == EntityType.DROWNED ||
|
case ARMOR_STAND:
|
||||||
event.getEntityType() == EntityType.GIANT ||
|
case DROWNED:
|
||||||
event.getEntityType() == EntityType.HUSK ||
|
case GIANT:
|
||||||
event.getEntityType() == EntityType.PIG_ZOMBIE ||
|
case HUSK:
|
||||||
event.getEntityType() == EntityType.PLAYER ||
|
case PIG_ZOMBIE:
|
||||||
event.getEntityType() == EntityType.SKELETON ||
|
case PLAYER:
|
||||||
event.getEntityType() == EntityType.STRAY ||
|
case SKELETON:
|
||||||
event.getEntityType() == EntityType.WITHER_SKELETON ||
|
case STRAY:
|
||||||
event.getEntityType() == EntityType.ZOMBIE ||
|
case WITHER_SKELETON:
|
||||||
event.getEntityType() == EntityType.ZOMBIE_VILLAGER) {
|
case ZOMBIE:
|
||||||
final LivingEntity mob = (LivingEntity) event.getEntity();
|
case ZOMBIE_VILLAGER:
|
||||||
|
checkIllegalArmor(mob);
|
||||||
|
break;
|
||||||
|
case ENDER_DRAGON:
|
||||||
|
final World world = event.getLocation().getWorld();
|
||||||
|
|
||||||
try {
|
if (checkDragonWorldLimit(world)) {
|
||||||
for (ItemStack item : mob.getEquipment().getArmorContents()) {
|
event.setCancelled(true);
|
||||||
if (item != null &&
|
|
||||||
item.hasItemMeta()) {
|
|
||||||
if (item.getItemMeta() instanceof BannerMeta) {
|
|
||||||
final BannerMeta banner = (BannerMeta) item.getItemMeta();
|
|
||||||
|
|
||||||
for (Pattern pattern : banner.getPatterns()) {
|
|
||||||
if (pattern.getColor() == null) {
|
|
||||||
mob.getEquipment().setArmorContents(
|
|
||||||
new ItemStack[] {null, null, null, null}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
break;
|
||||||
mob.getEquipment().setArmorContents(
|
case MAGMA_CUBE:
|
||||||
new ItemStack[] {null, null, null, null}
|
case SLIME:
|
||||||
);
|
final Slime slime = (Slime) mob;
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
limitSlimeSize(slime);
|
||||||
ItemStack item = mob.getEquipment().getItemInMainHand();
|
|
||||||
|
|
||||||
if (item != null &&
|
|
||||||
item.hasItemMeta()) {
|
|
||||||
if (item.getItemMeta() instanceof BannerMeta) {
|
|
||||||
final BannerMeta banner = (BannerMeta) item.getItemMeta();
|
|
||||||
|
|
||||||
for (Pattern pattern : banner.getPatterns()) {
|
|
||||||
if (pattern.getColor() == null) {
|
|
||||||
mob.getEquipment().setItemInMainHand(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
|
||||||
mob.getEquipment().setItemInMainHand(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ItemStack item = mob.getEquipment().getItemInMainHand();
|
|
||||||
|
|
||||||
if (item != null &&
|
|
||||||
item.hasItemMeta()) {
|
|
||||||
if (mob.getEquipment().getItemInOffHand().getItemMeta() instanceof BannerMeta) {
|
|
||||||
final BannerMeta banner = (BannerMeta) mob.getEquipment().getItemInOffHand().getItemMeta();
|
|
||||||
|
|
||||||
for (Pattern pattern : banner.getPatterns()) {
|
|
||||||
if (pattern.getColor() == null) {
|
|
||||||
mob.getEquipment().setItemInOffHand(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
|
||||||
mob.getEquipment().setItemInOffHand(null);
|
|
||||||
}
|
|
||||||
} else if (event.getEntityType() == EntityType.ENDER_DRAGON) {
|
|
||||||
final int dragonCount = event.getLocation().getWorld().getEntitiesByClass(EnderDragon.class).size();
|
|
||||||
|
|
||||||
if (dragonCount > 25) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
} else if (event.getEntityType() == EntityType.MAGMA_CUBE) {
|
|
||||||
final MagmaCube magmacube = (MagmaCube) event.getEntity();
|
|
||||||
|
|
||||||
if (magmacube.getSize() > 50) {
|
|
||||||
magmacube.setSize(50);
|
|
||||||
}
|
|
||||||
} else if (event.getEntityType() == EntityType.SLIME) {
|
|
||||||
final Slime slime = (Slime) event.getEntity();
|
|
||||||
|
|
||||||
if (slime.getSize() > 50) {
|
|
||||||
slime.setSize(50);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,146 +239,51 @@ class EntitySpawn implements Listener {
|
||||||
void onEntityAddToWorld(EntityAddToWorldEvent event) {
|
void onEntityAddToWorld(EntityAddToWorldEvent event) {
|
||||||
if (event.getEntityType() != EntityType.PLAYER) {
|
if (event.getEntityType() != EntityType.PLAYER) {
|
||||||
final World world = event.getEntity().getWorld();
|
final World world = event.getEntity().getWorld();
|
||||||
|
final Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (world.getEntities().size() > 1024) {
|
if (!checkEntityWorldLimitRemove(world)) {
|
||||||
for (Entity entity : world.getEntities()) {
|
if (checkEntityChunkLimit(entity.getLocation())) {
|
||||||
if (entity.getType() != EntityType.PLAYER) {
|
|
||||||
entity.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getEntity().getLocation().isGenerated() &&
|
|
||||||
event.getEntity().getLocation().isChunkLoaded()) {
|
|
||||||
final Entity entity = event.getEntity();
|
|
||||||
final int count = entity.getLocation().getChunk().getEntities().length;
|
|
||||||
|
|
||||||
if (count > 50) {
|
|
||||||
entity.remove();
|
entity.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getEntityType() == EntityType.ARMOR_STAND ||
|
|
||||||
event.getEntityType() == EntityType.DROWNED ||
|
|
||||||
event.getEntityType() == EntityType.GIANT ||
|
|
||||||
event.getEntityType() == EntityType.HUSK ||
|
|
||||||
event.getEntityType() == EntityType.PIG_ZOMBIE ||
|
|
||||||
event.getEntityType() == EntityType.PLAYER ||
|
|
||||||
event.getEntityType() == EntityType.SKELETON ||
|
|
||||||
event.getEntityType() == EntityType.STRAY ||
|
|
||||||
event.getEntityType() == EntityType.WITHER_SKELETON ||
|
|
||||||
event.getEntityType() == EntityType.ZOMBIE ||
|
|
||||||
event.getEntityType() == EntityType.ZOMBIE_VILLAGER) {
|
|
||||||
final LivingEntity mob = (LivingEntity) event.getEntity();
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (ItemStack item : mob.getEquipment().getArmorContents()) {
|
|
||||||
if (item != null &&
|
|
||||||
item.hasItemMeta()) {
|
|
||||||
if (item.getItemMeta() instanceof BannerMeta) {
|
|
||||||
final BannerMeta banner = (BannerMeta) item.getItemMeta();
|
|
||||||
|
|
||||||
for (Pattern pattern : banner.getPatterns()) {
|
switch (event.getEntityType()) {
|
||||||
if (pattern.getColor() == null) {
|
case ARMOR_STAND:
|
||||||
mob.getEquipment().setArmorContents(
|
case DROWNED:
|
||||||
new ItemStack[] {null, null, null, null}
|
case GIANT:
|
||||||
);
|
case HUSK:
|
||||||
}
|
case PIG_ZOMBIE:
|
||||||
}
|
case PLAYER:
|
||||||
}
|
case SKELETON:
|
||||||
|
case STRAY:
|
||||||
|
case WITHER_SKELETON:
|
||||||
|
case ZOMBIE:
|
||||||
|
case ZOMBIE_VILLAGER:
|
||||||
|
final LivingEntity mob = (LivingEntity) entity;
|
||||||
|
|
||||||
|
checkIllegalArmor(mob);
|
||||||
|
break;
|
||||||
|
case AREA_EFFECT_CLOUD:
|
||||||
|
final AreaEffectCloud cloud = (AreaEffectCloud) entity;
|
||||||
|
|
||||||
|
limitAreaEffectCloudRadius(cloud);
|
||||||
|
break;
|
||||||
|
case PRIMED_TNT:
|
||||||
|
if (world.getEntitiesByClass(TNTPrimed.class).size() > 180) {
|
||||||
|
for (Entity tnt : world.getEntitiesByClass(TNTPrimed.class)) {
|
||||||
|
tnt.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
|
||||||
mob.getEquipment().setArmorContents(
|
|
||||||
new ItemStack[] {null, null, null, null}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ItemStack item = mob.getEquipment().getItemInMainHand();
|
|
||||||
|
|
||||||
if (item != null &&
|
|
||||||
item.hasItemMeta()) {
|
|
||||||
if (item.getItemMeta() instanceof BannerMeta) {
|
|
||||||
final BannerMeta banner = (BannerMeta) item.getItemMeta();
|
|
||||||
|
|
||||||
for (Pattern pattern : banner.getPatterns()) {
|
|
||||||
if (pattern.getColor() == null) {
|
|
||||||
mob.getEquipment().setItemInMainHand(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
|
||||||
mob.getEquipment().setItemInMainHand(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ItemStack item = mob.getEquipment().getItemInMainHand();
|
|
||||||
|
|
||||||
if (item != null &&
|
|
||||||
item.hasItemMeta()) {
|
|
||||||
if (mob.getEquipment().getItemInOffHand().getItemMeta() instanceof BannerMeta) {
|
|
||||||
final BannerMeta banner = (BannerMeta) mob.getEquipment().getItemInOffHand().getItemMeta();
|
|
||||||
|
|
||||||
for (Pattern pattern : banner.getPatterns()) {
|
|
||||||
if (pattern.getColor() == null) {
|
|
||||||
mob.getEquipment().setItemInOffHand(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
|
||||||
mob.getEquipment().setItemInOffHand(null);
|
|
||||||
}
|
|
||||||
} else if (event.getEntityType() == EntityType.AREA_EFFECT_CLOUD) {
|
|
||||||
final AreaEffectCloud cloud = (AreaEffectCloud) event.getEntity();
|
|
||||||
|
|
||||||
if (cloud.getRadius() > 40) {
|
|
||||||
cloud.setRadius(40);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cloud.getRadiusOnUse() > 0.01f) {
|
|
||||||
cloud.setRadiusOnUse(0.1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cloud.getRadiusPerTick() > 0) {
|
|
||||||
cloud.setRadiusPerTick(0);
|
|
||||||
}
|
|
||||||
} else if (event.getEntityType() == EntityType.PRIMED_TNT) {
|
|
||||||
if (world.getEntitiesByClass(TNTPrimed.class).size() > 180) {
|
|
||||||
for (Entity entity : world.getEntitiesByClass(TNTPrimed.class)) {
|
|
||||||
entity.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntitySpawn(EntitySpawnEvent event) {
|
void onEntitySpawn(EntitySpawnEvent event) {
|
||||||
if (event.getEntityType() != EntityType.PLAYER) {
|
if (event.getEntityType() != EntityType.PLAYER &&
|
||||||
final World world = event.getLocation().getWorld();
|
checkEntityChunkLimit(event.getLocation())) {
|
||||||
|
event.setCancelled(true);
|
||||||
if (world.getEntities().size() > 1024) {
|
|
||||||
for (Entity entity : world.getEntities()) {
|
|
||||||
if (entity.getType() != EntityType.PLAYER) {
|
|
||||||
entity.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getLocation().isGenerated() &&
|
|
||||||
event.getLocation().isChunkLoaded()) {
|
|
||||||
final int entityCount = event.getLocation().getChunk().getEntities().length;
|
|
||||||
|
|
||||||
if (entityCount > 50) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,44 +293,17 @@ class EntitySpawn implements Listener {
|
||||||
event.getEntity().getItemStack().getItemMeta();
|
event.getEntity().getItemStack().getItemMeta();
|
||||||
} catch (Exception | StackOverflowError exception) {
|
} catch (Exception | StackOverflowError exception) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
/*System.out.println("better work");
|
|
||||||
event.getEntity().setPickupDelay(99999);
|
|
||||||
event.getEntity().setItemStack(new ItemStack(Material.TORCH));*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPreCreatureSpawn(PreCreatureSpawnEvent event) {
|
void onPreCreatureSpawn(PreCreatureSpawnEvent event) {
|
||||||
if (event.getType() != EntityType.PLAYER) {
|
if ((event.getType() != EntityType.PLAYER &&
|
||||||
final World world = event.getSpawnLocation().getWorld();
|
checkEntityChunkLimit(event.getSpawnLocation())) ||
|
||||||
|
|
||||||
if (world.getEntities().size() > 1024) {
|
(event.getType() == EntityType.ENDER_DRAGON &&
|
||||||
for (Entity entity : world.getEntities()) {
|
checkDragonWorldLimit(event.getSpawnLocation().getWorld()))) {
|
||||||
if (entity.getType() != EntityType.PLAYER) {
|
event.setCancelled(true);
|
||||||
entity.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getSpawnLocation().isGenerated() &&
|
|
||||||
event.getSpawnLocation().isChunkLoaded()) {
|
|
||||||
final int entityCount = event.getSpawnLocation().getChunk().getEntities().length;
|
|
||||||
|
|
||||||
if (entityCount > 50) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getType() == EntityType.ENDER_DRAGON) {
|
|
||||||
final int dragonCount = event.getSpawnLocation().getWorld().getEntitiesByClass(EnderDragon.class).size();
|
|
||||||
|
|
||||||
if (dragonCount > 25) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,26 +312,12 @@ class EntitySpawn implements Listener {
|
||||||
try {
|
try {
|
||||||
final CreatureSpawner spawner = (CreatureSpawner) event.getSpawnerLocation().getBlock().getState();
|
final CreatureSpawner spawner = (CreatureSpawner) event.getSpawnerLocation().getBlock().getState();
|
||||||
|
|
||||||
if (event.getType() == EntityType.MINECART_MOB_SPAWNER) {
|
if (spawner.getSpawnedType() == EntityType.MINECART_MOB_SPAWNER) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
} else if (event.getType() == EntityType.FALLING_BLOCK) {
|
|
||||||
if (spawner.getDelay() > 100) {
|
|
||||||
spawner.setMaxSpawnDelay(100);
|
|
||||||
spawner.setDelay(100);
|
|
||||||
spawner.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spawner.getSpawnCount() > 200) {
|
|
||||||
spawner.setSpawnCount(200);
|
|
||||||
spawner.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spawner.getSpawnRange() > 50) {
|
|
||||||
spawner.setSpawnRange(50);
|
|
||||||
spawner.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
limitSpawner(spawner);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -431,9 +337,10 @@ class EntitySpawn implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onTNTPrime(TNTPrimeEvent event) {
|
void onTNTPrime(TNTPrimeEvent event) {
|
||||||
final double tps = Bukkit.getTPS()[0];
|
final double tps = Bukkit.getTPS()[0];
|
||||||
|
final int tntCount = event.getBlock().getWorld().getEntitiesByClass(TNTPrimed.class).size();
|
||||||
|
|
||||||
if (tps < 10 ||
|
if (tps < 10 ||
|
||||||
event.getBlock().getWorld().getEntitiesByClass(TNTPrimed.class).size() > 140) {
|
tntCount > 140) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue