Search in sources :

Example 1 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent in project MagicPlugin by elBukkit.

the class CompatibilityUtils method damage.

public static void damage(Damageable target, double amount, Entity source) {
    if (target == null || target.isDead())
        return;
    while (target instanceof ComplexEntityPart) {
        target = ((ComplexEntityPart) target).getParent();
    }
    if (USE_MAGIC_DAMAGE && target.getType() == EntityType.ENDER_DRAGON) {
        magicDamage(target, amount, source);
        return;
    }
    isDamaging = true;
    try {
        if (target instanceof ArmorStand) {
            double newHealth = Math.max(0, target.getHealth() - amount);
            if (newHealth <= 0) {
                EntityDeathEvent deathEvent = new EntityDeathEvent((ArmorStand) target, new ArrayList<ItemStack>());
                Bukkit.getPluginManager().callEvent(deathEvent);
                target.remove();
            } else {
                target.setHealth(newHealth);
            }
        } else {
            target.damage(amount, source);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    isDamaging = false;
}
Also used : ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) ArmorStand(org.bukkit.entity.ArmorStand) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ItemStack(org.bukkit.inventory.ItemStack) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException)

Example 2 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.

the class GolemBuster method damageEntity.

@Override
public boolean damageEntity(DamageSource damagesource, float f) {
    if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.IRON_GOLEM) {
        this.die();
        this.die();
        org.bukkit.inventory.ItemStack[] itemStack = new org.bukkit.inventory.ItemStack[] { new org.bukkit.inventory.ItemStack(org.bukkit.Material.ROTTEN_FLESH) };
        Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
        IronGolem golem = (IronGolem) damagesource.getEntity().getBukkitEntity();
        // golem.getWorld().createExplosion(golem.getLocation(), 4);
        org.bukkit.entity.Entity primed = golem.getWorld().spawnEntity(golem.getLocation(), EntityType.PRIMED_TNT);
        return true;
    } else {
        super.damageEntity(damagesource, f);
        return false;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IronGolem(org.bukkit.entity.IronGolem) EntityIronGolem(net.minecraft.server.v1_12_R1.EntityIronGolem)

Example 3 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.

the class PlayerBuster method damageEntity.

@Override
public boolean damageEntity(DamageSource damagesource, float f) {
    if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.PLAYER) {
        ItemStack[] itemStack = new ItemStack[] { new ItemStack(Material.ROTTEN_FLESH) };
        Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
        Player player = (Player) damagesource.getEntity().getBukkitEntity();
        getBukkitEntity().getWorld().spawnEntity(getBukkitEntity().getLocation(), EntityType.PRIMED_TNT);
        this.die();
        return true;
    } else {
        super.damageEntity(damagesource, f);
        return false;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PathfinderGoalLookAtPlayer(net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.

the class PlayerBuster method damageEntity.

@Override
public boolean damageEntity(DamageSource damagesource, float f) {
    if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.PLAYER) {
        ItemStack[] itemStack = new ItemStack[] { new ItemStack(Material.ROTTEN_FLESH) };
        Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
        getBukkitEntity().getWorld().spawnEntity(getBukkitEntity().getLocation(), EntityType.PRIMED_TNT);
        this.die();
        return true;
    } else {
        super.damageEntity(damagesource, f);
        return false;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with EntityDeathEvent

use of org.bukkit.event.entity.EntityDeathEvent in project Village_Defense by Plajer.

the class GolemBuster method damageEntity.

@Override
public boolean damageEntity(DamageSource damagesource, float f) {
    if (damagesource != null && damagesource.getEntity() != null && damagesource.getEntity().getBukkitEntity().getType() == EntityType.IRON_GOLEM) {
        this.die();
        this.die();
        org.bukkit.inventory.ItemStack[] itemStack = new org.bukkit.inventory.ItemStack[] { new org.bukkit.inventory.ItemStack(org.bukkit.Material.ROTTEN_FLESH) };
        Bukkit.getServer().getPluginManager().callEvent(new EntityDeathEvent((LivingEntity) this.getBukkitEntity(), Arrays.asList(itemStack), expToDrop));
        IronGolem golem = (IronGolem) damagesource.getEntity().getBukkitEntity();
        // golem.getWorld().createExplosion(golem.getLocation(), 4);
        org.bukkit.entity.Entity primed = golem.getWorld().spawnEntity(golem.getLocation(), EntityType.PRIMED_TNT);
        return true;
    } else {
        super.damageEntity(damagesource, f);
        return false;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IronGolem(org.bukkit.entity.IronGolem) EntityIronGolem(net.minecraft.server.v1_11_R1.EntityIronGolem)

Aggregations

EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)10 LivingEntity (org.bukkit.entity.LivingEntity)8 ItemStack (org.bukkit.inventory.ItemStack)7 IronGolem (org.bukkit.entity.IronGolem)4 Player (org.bukkit.entity.Player)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 GlowSlime (net.glowstone.entity.monster.GlowSlime)1 GlowExperienceOrb (net.glowstone.entity.objects.GlowExperienceOrb)1 LootData (net.glowstone.util.loot.LootData)1 EntityIronGolem (net.minecraft.server.v1_11_R1.EntityIronGolem)1 PathfinderGoalLookAtPlayer (net.minecraft.server.v1_11_R1.PathfinderGoalLookAtPlayer)1 EntityIronGolem (net.minecraft.server.v1_12_R1.EntityIronGolem)1 PathfinderGoalLookAtPlayer (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer)1 EntityIronGolem (net.minecraft.server.v1_8_R3.EntityIronGolem)1 EntityIronGolem (net.minecraft.server.v1_9_R1.EntityIronGolem)1 PathfinderGoalLookAtPlayer (net.minecraft.server.v1_9_R1.PathfinderGoalLookAtPlayer)1 Location (org.bukkit.Location)1 Sound (org.bukkit.Sound)1