Search in sources :

Example 1 with Witch

use of org.bukkit.entity.Witch in project MagicPlugin by elBukkit.

the class CompatibilityUtils method magicDamage.

public static void magicDamage(Damageable target, double amount, Entity source) {
    try {
        if (target == null || target.isDead())
            return;
        if (class_EntityLiving_damageEntityMethod == null || object_magicSource == null || class_DamageSource_getMagicSourceMethod == null) {
            damage(target, amount, source);
            return;
        }
        // Might need to config-drive this, or just go back to defaulting to normal damage
        if (!USE_MAGIC_DAMAGE || target instanceof Witch || target instanceof Enderman || target instanceof ArmorStand || !(target instanceof LivingEntity)) {
            damage(target, amount, source);
            return;
        }
        Object targetHandle = getHandle(target);
        if (targetHandle == null)
            return;
        isDamaging = true;
        Object sourceHandle = getHandle(source);
        // Bukkit won't allow magic damage from anything but a potion..
        if (sourceHandle != null && source instanceof LivingEntity) {
            ThrownPotion potion = potionReference == null ? null : potionReference.get();
            Location location = target.getLocation();
            if (potion == null) {
                potion = (ThrownPotion) location.getWorld().spawnEntity(location, EntityType.SPLASH_POTION);
                potion.remove();
                potionReference = new WeakReference<>(potion);
            }
            potion.teleport(location);
            potion.setShooter((LivingEntity) source);
            Object potionHandle = getHandle(potion);
            Object damageSource = class_DamageSource_getMagicSourceMethod.invoke(null, potionHandle, sourceHandle);
            // of various non-living entity pieces.
            if (class_EntityDamageSource_setThornsMethod != null) {
                class_EntityDamageSource_setThornsMethod.invoke(damageSource);
            }
            class_EntityLiving_damageEntityMethod.invoke(targetHandle, damageSource, (float) amount);
        } else {
            class_EntityLiving_damageEntityMethod.invoke(targetHandle, object_magicSource, (float) amount);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    isDamaging = false;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) Enderman(org.bukkit.entity.Enderman) ThrownPotion(org.bukkit.entity.ThrownPotion) Witch(org.bukkit.entity.Witch) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) Location(org.bukkit.Location)

Example 2 with Witch

use of org.bukkit.entity.Witch in project Glowstone by GlowstoneMC.

the class GlowVillager method damage.

@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
    if (!DamageCause.LIGHTNING.equals(cause)) {
        super.damage(amount, source, cause);
        return;
    }
    Witch witch = world.spawn(this.location, Witch.class);
    witch.damage(amount, source, cause);
    witch.setFireTicks(this.getFireTicks());
    remove();
}
Also used : Witch(org.bukkit.entity.Witch)

Aggregations

Witch (org.bukkit.entity.Witch)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Location (org.bukkit.Location)1 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)1 ArmorStand (org.bukkit.entity.ArmorStand)1 ComplexLivingEntity (org.bukkit.entity.ComplexLivingEntity)1 Enderman (org.bukkit.entity.Enderman)1 LivingEntity (org.bukkit.entity.LivingEntity)1 ThrownPotion (org.bukkit.entity.ThrownPotion)1