Search in sources :

Example 16 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Denizen-For-Bukkit by DenizenScript.

the class EntityKilledScriptEvent method onEntityKilled.

@EventHandler
public void onEntityKilled(EntityDamageEvent event) {
    entity = new dEntity(event.getEntity());
    // Check for possibility of death first
    if (entity.isValid() && entity.isLivingEntity()) {
        if (event.getFinalDamage() < entity.getLivingEntity().getHealth()) {
            return;
        }
    } else {
        return;
    }
    damage = new Element(event.getDamage());
    final_damage = new Element(event.getFinalDamage());
    cause = new Element(CoreUtilities.toLowerCase(event.getCause().name()));
    damager = null;
    projectile = null;
    if (event instanceof EntityDamageByEntityEvent) {
        damager = new dEntity(((EntityDamageByEntityEvent) event).getDamager());
        if (damager.isProjectile()) {
            projectile = damager;
            if (damager.hasShooter()) {
                damager = damager.getShooter();
            }
        }
    }
    cancelled = event.isCancelled();
    this.event = event;
    fire();
    event.setCancelled(cancelled);
    event.setDamage(damage.asDouble());
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) EventHandler(org.bukkit.event.EventHandler)

Example 17 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Denizen-For-Bukkit by DenizenScript.

the class EntityDamagedScriptEvent method onEntityDamaged.

@EventHandler
public void onEntityDamaged(EntityDamageEvent event) {
    entity = new dEntity(event.getEntity());
    damage = new Element(event.getDamage());
    final_damage = new Element(event.getFinalDamage());
    cause = new Element(CoreUtilities.toLowerCase(event.getCause().name()));
    damager = null;
    projectile = null;
    held = null;
    if (event instanceof EntityDamageByEntityEvent) {
        damager = new dEntity(((EntityDamageByEntityEvent) event).getDamager());
        if (damager.isProjectile()) {
            projectile = damager;
            if (damager.hasShooter()) {
                damager = damager.getShooter();
            }
        }
        if (damager != null) {
            held = damager.getItemInHand();
            if (held != null) {
                held.setAmount(1);
            }
        }
    }
    cancelled = event.isCancelled();
    this.event = event;
    fire();
    event.setCancelled(cancelled);
    event.setDamage(damage.asDouble());
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) EventHandler(org.bukkit.event.EventHandler)

Example 18 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Denizen-For-Bukkit by DenizenScript.

the class EntityDeathScriptEvent method onEntityDeath.

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    LivingEntity livingEntity = event.getEntity();
    dEntity.rememberEntity(livingEntity);
    entity = new dEntity(livingEntity);
    dPlayer player = null;
    if (entity.isPlayer()) {
        player = entity.getDenizenPlayer();
    }
    damager = null;
    EntityDamageEvent lastDamage = entity.getBukkitEntity().getLastDamageCause();
    if (lastDamage != null) {
        if (lastDamage instanceof EntityDamageByEntityEvent) {
            damager = new dEntity(((EntityDamageByEntityEvent) lastDamage).getDamager()).getDenizenObject();
        }
    }
    message = null;
    inventory = null;
    PlayerDeathEvent subEvent = null;
    if (event instanceof PlayerDeathEvent) {
        subEvent = (PlayerDeathEvent) event;
        message = new Element(subEvent.getDeathMessage());
        // Null check to prevent NPCs from causing an NPE
        if (player != null) {
            inventory = player.getInventory();
        }
        keep_inv = subEvent.getKeepInventory();
        keep_level = subEvent.getKeepLevel();
    }
    cause = null;
    if (event.getEntity().getLastDamageCause() != null) {
        cause = new Element(event.getEntity().getLastDamageCause().getCause().toString());
    }
    drops = new dList();
    for (ItemStack stack : event.getDrops()) {
        if (stack == null) {
            drops.add("i@air");
        } else {
            drops.add(new dItem(stack).identify());
        }
    }
    changed_drops = false;
    xp = event.getDroppedExp();
    this.event = event;
    fire();
    event.setDroppedExp(xp);
    if (changed_drops) {
        event.getDrops().clear();
        for (String drop : drops) {
            dItem item = dItem.valueOf(drop);
            if (item != null) {
                event.getDrops().add(item.getItemStack());
            }
        }
    }
    if (event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setKeepInventory(keep_inv);
        ((PlayerDeathEvent) event).setKeepLevel(keep_level);
    }
    if (message != null && subEvent != null) {
        subEvent.setDeathMessage(message.asString());
    }
    if (cancelled && subEvent != null) {
        subEvent.setDeathMessage(null);
    }
    dEntity.forgetEntity(livingEntity);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) ItemStack(org.bukkit.inventory.ItemStack) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Example 19 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project modules-extra by CubeEngine.

the class ListenerDeath method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    // TODO handle when there is no reference on lookup of dependent actions
    DeathKill killAction = this.newAction(DeathKill.class, event.getEntity().getWorld());
    if (killAction != null) {
        // TODO check config for killer type
        killAction.setLocation(event.getEntity().getLocation());
        EntityDamageEvent cause = event.getEntity().getLastDamageCause();
        if (cause == null) {
            killAction.otherKiller = DamageCause.CUSTOM;
        } else if (cause instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) cause).getDamager();
            if (damager instanceof Player) {
                killAction.playerKiller = new PlayerSection((Player) damager);
            } else if (damager instanceof Projectile) {
                killAction.projectile = true;
                if (((Projectile) damager).getShooter() instanceof Entity) {
                    if (((Projectile) damager).getShooter() instanceof Player) {
                        killAction.playerKiller = new PlayerSection((Player) ((Projectile) damager).getShooter());
                    } else {
                        killAction.entityKiller = new EntitySection((Entity) ((Projectile) damager).getShooter());
                    }
                } else {
                    killAction.entityKiller = new EntitySection(damager);
                }
            } else {
                killAction.entityKiller = new EntitySection(damager);
            }
        } else {
            killAction.otherKiller = cause.getCause();
        }
        this.logAction(killAction);
    }
    Reference<DeathKill> reference = this.reference(killAction);
    LivingEntity killed = event.getEntity();
    if (killed instanceof Player) {
        DeathPlayer action = this.newAction(DeathPlayer.class, killed.getWorld());
        if (action != null) {
            action.killer = reference;
            action.setPlayer((Player) killed);
            this.logAction(action);
        }
        if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
            Reference<DeathPlayer> deathRef = this.reference(action);
            for (ItemStack itemStack : event.getDrops()) {
                PlayerDeathDrop dropAction = newAction(PlayerDeathDrop.class);
                dropAction.item = itemStack;
                dropAction.death = deathRef;
                this.logAction(dropAction);
            }
        }
        return;
    }
    Class<? extends EntityDeathAction> actionType;
    if (killed instanceof Wither || killed instanceof EnderDragon) {
        actionType = DeathBoss.class;
    } else if (killed instanceof Animals) {
        if (killed instanceof Tameable && ((Tameable) killed).isTamed()) {
            actionType = DeathPet.class;
        } else {
            actionType = DeathAnimal.class;
        }
    } else if (killed instanceof Villager) {
        actionType = DeathNpc.class;
    } else if (killed instanceof Monster) {
        actionType = DeathMonster.class;
    } else {
        actionType = DeathOther.class;
    }
    EntityDeathAction action = this.newAction(actionType, killed.getWorld());
    if (action != null) {
        action.setKilled(killed);
        action.setLocation(killed.getLocation());
        action.killer = reference;
        this.logAction(action);
    }
    Reference<EntityDeathAction> deathRef = this.reference(action);
    if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
        for (ItemStack itemStack : event.getDrops()) {
            DeathDrop dropAction = newAction(DeathDrop.class);
            dropAction.item = itemStack;
            dropAction.death = deathRef;
            this.logAction(dropAction);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) PlayerSection(org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection) LivingEntity(org.bukkit.entity.LivingEntity) EnderDragon(org.bukkit.entity.EnderDragon) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) EntitySection(org.cubeengine.module.log.action.block.entity.ActionEntityBlock.EntitySection) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Wither(org.bukkit.entity.Wither) Player(org.spongepowered.api.entity.player.Player) Tameable(org.bukkit.entity.Tameable) Projectile(org.bukkit.entity.Projectile) Animals(org.bukkit.entity.Animals) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ItemStack(org.spongepowered.api.item.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 20 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project MassiveCore by MassiveCraft.

the class PlayerUtil method isDuplicateDamageEvent.

public static boolean isDuplicateDamageEvent(EntityDamageByEntityEvent event) {
    // Get the id ...
    Entity damager = MUtil.getLiableDamager(event);
    Entity damagee = event.getEntity();
    if (damager == null)
        return false;
    if (damagee == null)
        return false;
    final String id = damager.getUniqueId().toString() + damagee.getUniqueId().toString();
    // ... get current ...
    EntityDamageByEntityEvent current = idToDamageEvent.get(id);
    // ... object equality ...
    if (current != null)
        return current != event;
    // ... store ...
    idToDamageEvent.put(id, event);
    // ... and return.
    return false;
}
Also used : Entity(org.bukkit.entity.Entity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent)

Aggregations

EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)35 EventHandler (org.bukkit.event.EventHandler)22 Entity (org.bukkit.entity.Entity)19 Player (org.bukkit.entity.Player)17 LivingEntity (org.bukkit.entity.LivingEntity)15 Projectile (org.bukkit.entity.Projectile)12 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)12 ItemStack (org.bukkit.inventory.ItemStack)6 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)5 Element (net.aufdemrand.denizencore.objects.Element)5 ProjectileSource (org.bukkit.projectiles.ProjectileSource)5 EntityTag (com.denizenscript.denizen.objects.EntityTag)4 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)4 Arrow (org.bukkit.entity.Arrow)4 ArrayList (java.util.ArrayList)3 Animals (org.bukkit.entity.Animals)3 Tameable (org.bukkit.entity.Tameable)3 EntityDamageByBlockEvent (org.bukkit.event.entity.EntityDamageByBlockEvent)3 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2