use of org.bukkit.entity.Damageable in project EliteMobs by MagmaGuy.
the class MobScanner method levelCap.
public boolean levelCap(Entity entity1, Entity entity2) {
Damageable damageable1 = (Damageable) entity1;
Damageable damageable2 = (Damageable) entity2;
if (damageable1.hasMetadata(MetadataHandler.ELITE_MOB_MD) && damageable1.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() >= ConfigValues.defaultConfig.getInt("Aggressive mob stacking cap")) {
return false;
} else if (damageable2.hasMetadata(MetadataHandler.ELITE_MOB_MD) && damageable2.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() >= ConfigValues.defaultConfig.getInt("Aggressive mob stacking cap")) {
return false;
}
return true;
}
use of org.bukkit.entity.Damageable in project EliteMobs by MagmaGuy.
the class MobScanner method scanMobs.
public void scanMobs(int passiveStackAmount) {
for (World world : worldList) {
Iterator<LivingEntity> iterator = world.getLivingEntities().iterator();
while (iterator.hasNext()) {
Entity entity = iterator.next();
if (ValidAgressiveMobFilter.ValidAgressiveMobFilter(entity)) {
//scan for naturally/command/plugin spawned EliteMobs
if (entity.hasMetadata(MetadataHandler.ELITE_MOB_MD) && entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() != 1 && ((Damageable) entity).getMaxHealth() == DefaultMaxHealthGuesser.defaultMaxHealthGuesser(entity)) {
HealthHandler.naturalAgressiveHealthHandler(entity, entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt());
customAggressiveName(entity);
PowerHandler.powerHandler(entity);
ArmorHandler.ArmorHandler(entity);
}
//scan for stacked EliteMobs
if (ConfigValues.defaultConfig.getBoolean("Allow aggressive EliteMobs") && ConfigValues.defaultConfig.getBoolean("Aggressive mob stacking") && !entity.hasMetadata(MetadataHandler.FORBIDDEN_MD)) {
if (!(entity.hasMetadata(MetadataHandler.ELITE_MOB_MD) && entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() >= ConfigValues.defaultConfig.getInt("Aggressive mob stacking cap")) && !entity.hasMetadata(MetadataHandler.FORBIDDEN_MD)) {
scanValidAggressiveLivingEntity(entity);
}
if (entity.hasMetadata(MetadataHandler.ELITE_MOB_MD)) {
PowerHandler.powerHandler(entity);
ArmorHandler.ArmorHandler(entity);
}
}
}
//scan for passive mobs
if (ConfigValues.defaultConfig.getBoolean("Allow Passive EliteMobs")) {
//scan for passive mobs that might have lost their metadata
if (ValidPassiveMobFilter.ValidPassiveMobFilter(entity) && ((LivingEntity) entity).getMaxHealth() != DefaultMaxHealthGuesser.defaultMaxHealthGuesser(entity) && ((LivingEntity) entity).getMaxHealth() == DefaultMaxHealthGuesser.defaultMaxHealthGuesser(entity) * ConfigValues.defaultConfig.getInt("Passive EliteMob stack amount")) {
customPassiveName(entity, plugin);
}
//scan for new passive supermobs
if (ValidPassiveMobFilter.ValidPassiveMobFilter(entity) && !entity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
scanValidPassiveLivingEntity(entity);
}
//spawn chicken eggs, really wish there were an event for this
ChickenHandler.superEggs(entity, passiveStackAmount);
}
//scan for iron golems with missing metadata
if (!entity.hasMetadata(MetadataHandler.ELITE_MOB_MD) && entity instanceof IronGolem && ((IronGolem) entity).getMaxHealth() != DefaultMaxHealthGuesser.defaultMaxHealthGuesser(entity)) {
entity.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, ScalingFormula.reversePowerFormula(((IronGolem) entity).getMaxHealth(), DefaultMaxHealthGuesser.defaultMaxHealthGuesser(entity))));
customAggressiveName(entity);
}
}
}
}
use of org.bukkit.entity.Damageable in project EliteMobs by MagmaGuy.
the class HealthHandler method naturalAgressiveHealthHandler.
public static void naturalAgressiveHealthHandler(Entity entity, int eliteMobLevel) {
Damageable damageable = (Damageable) entity;
double defaultMaxHealth = DefaultMaxHealthGuesser.defaultMaxHealthGuesser(entity);
int newEliteMobLevel = eliteMobLevel;
if (entity.hasMetadata(MetadataHandler.DOUBLE_DAMAGE_MD)) {
newEliteMobLevel = (int) Math.floor(newEliteMobLevel / 2);
if (newEliteMobLevel < 1) {
newEliteMobLevel = 1;
}
}
if (entity.hasMetadata(MetadataHandler.DOUBLE_HEALTH_MD)) {
newEliteMobLevel = (int) Math.floor(newEliteMobLevel * 2);
}
damageable.setMaxHealth(ScalingFormula.PowerFormula(defaultMaxHealth, newEliteMobLevel));
damageable.setHealth(damageable.getMaxHealth());
}
use of org.bukkit.entity.Damageable in project MagicPlugin by elBukkit.
the class KillAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
if (!(entity instanceof Damageable)) {
return SpellResult.NO_TARGET;
}
Damageable targetEntity = (Damageable) entity;
if (targetEntity.isDead()) {
return SpellResult.NO_TARGET;
}
// Overkill to bypass protection
context.registerModified(targetEntity);
targetEntity.damage(targetEntity.getMaxHealth() * 100);
return SpellResult.CAST;
}
use of org.bukkit.entity.Damageable in project MagicPlugin by elBukkit.
the class RideEntityAction method crash.
protected boolean crash(CastContext context) {
context.sendMessageKey("crash");
context.playEffects("crash");
Entity mountedEntity = context.getEntity();
if (crashDamage > 0) {
double damage = maxSpeed > 0 ? crashDamage * speed / maxSpeed : crashDamage;
if (mountedEntity.isValid() && mountedEntity instanceof Damageable) {
CompatibilityUtils.damage((Damageable) mountedEntity, damage, mount);
}
}
if (crashVehicleDamage > 0) {
double damage = maxSpeed > 0 ? crashVehicleDamage * speed / maxSpeed : crashVehicleDamage;
if (mount != null && mount.isValid() && mount instanceof Damageable) {
CompatibilityUtils.damage((Damageable) mount, damage, mountedEntity);
}
}
boolean dismount = (speed >= crashDismountSpeed);
if (dismount) {
if (crashVelocity > 0 && maxSpeed > 0) {
mount.eject();
Vector crashDirection = direction.clone();
if (crashVelocityYOffset > 0) {
crashDirection.setY(crashDirection.getY() + crashVelocityYOffset).normalize();
}
Vector velocity = crashDirection.multiply(crashVelocity * speed / maxSpeed);
SafetyUtils.setVelocity(mountedEntity, velocity);
}
if (crashEffects != null && mountedEntity != null && crashEffects.size() > 0 && mountedEntity instanceof LivingEntity) {
CompatibilityUtils.applyPotionEffects((LivingEntity) mountedEntity, crashEffects);
}
warningEffectsApplied = false;
}
speed = 0;
return dismount;
}
Aggregations