/** * Damages an entity with as cause another entity * * @param entity to be damaged * @param damager that damages * @param damage to deal */ public static void damageBy( org.bukkit.entity.Entity entity, org.bukkit.entity.Entity damager, double damage) { DamageSource source; if (damager instanceof Player) { source = DamageSource.playerAttack(CommonNMS.getNative((Player) damager)); } else if (damager instanceof LivingEntity) { source = DamageSource.mobAttack(CommonNMS.getNative((LivingEntity) damager)); } else { source = DamageSource.GENERIC; } CommonNMS.getNative(entity).damageEntity(source, (float) damage); }
public static void attack(EntityLiving handle, Entity target) { AttributeInstance attackDamage = handle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE); float f = (float) (attackDamage == null ? 1 : attackDamage.getValue()); int i = 0; if (target instanceof EntityLiving) { f += EnchantmentManager.a(handle.bA(), ((EntityLiving) target).getMonsterType()); i += EnchantmentManager.a(handle); } boolean flag = target.damageEntity(DamageSource.mobAttack(handle), f); if (!flag) return; if (i > 0) { target.g( -Math.sin(handle.yaw * Math.PI / 180.0F) * i * 0.5F, 0.1D, Math.cos(handle.yaw * Math.PI / 180.0F) * i * 0.5F); handle.motX *= 0.6D; handle.motZ *= 0.6D; } int fireAspectLevel = EnchantmentManager.getFireAspectEnchantmentLevel(handle); if (fireAspectLevel > 0) { target.setOnFire(fireAspectLevel * 4); } }
/** * Damages an entity * * @param entity to be damagedd * @param cause of the damage * @param damage to deal */ public static void damage(org.bukkit.entity.Entity entity, DamageCause cause, double damage) { DamageSource source; if (cause == DamageCause.BLOCK_EXPLOSION) { Location loc = entity.getLocation(); World worldhandle = CommonNMS.getNative(loc.getWorld()); Explosion ex = new Explosion( worldhandle, null, loc.getX(), loc.getY(), loc.getZ(), (float) 4.0, true, true); source = DamageSource.explosion(ex); } else if (cause == DamageCause.CONTACT) { source = DamageSource.CACTUS; } else if (cause == DamageCause.DROWNING) { source = DamageSource.DROWN; } else if (cause == DamageCause.FALL) { source = DamageSource.FALL; } else if (cause == DamageCause.FALLING_BLOCK) { source = DamageSource.FALLING_BLOCK; } else if (cause == DamageCause.FIRE) { source = DamageSource.FIRE; } else if (cause == DamageCause.LAVA) { source = DamageSource.LAVA; } else if (cause == DamageCause.MAGIC) { source = DamageSource.MAGIC; } else if (cause == DamageCause.VOID) { source = DamageSource.OUT_OF_WORLD; } else if (cause == DamageCause.STARVATION) { source = DamageSource.STARVE; } else if (cause == DamageCause.SUFFOCATION) { source = DamageSource.STUCK; } else if (cause == DamageCause.WITHER) { source = DamageSource.WITHER; } else { source = DamageSource.GENERIC; } CommonNMS.getNative(entity).damageEntity(source, (float) damage); }
/** * Damages an entity with the reason of an explosion * * @param entity to be demaged * @param damage of the damage * @param explosion wich has damaged the player */ public static void damage_explode( org.bukkit.entity.Entity entity, double damage, Explosion explosion) { CommonNMS.getNative(entity).damageEntity(DamageSource.explosion(explosion), (float) damage); }