Search in sources :

Example 31 with EntityDamageByEntityEvent

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

the class EntityKilledScriptEvent method onEntityKilled.

@EventHandler(priority = EventPriority.HIGH)
public void onEntityKilled(EntityDamageEvent event) {
    entity = new EntityTag(event.getEntity());
    // Check for possibility of death first
    if (entity.isValid() && entity.isLivingEntity()) {
        if (event.getFinalDamage() < entity.getLivingEntity().getHealth()) {
            return;
        }
    } else {
        return;
    }
    final_damage = new ElementTag(event.getFinalDamage());
    cause = new ElementTag(CoreUtilities.toLowerCase(event.getCause().name()));
    damager = null;
    projectile = null;
    if (event instanceof EntityDamageByEntityEvent) {
        damager = new EntityTag(((EntityDamageByEntityEvent) event).getDamager());
        if (damager.isProjectile()) {
            projectile = damager;
            if (damager.hasShooter()) {
                damager = damager.getShooter();
            }
        }
    }
    this.event = event;
    fire(event);
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 32 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();
    EntityTag.rememberEntity(livingEntity);
    entity = new EntityTag(livingEntity);
    cause = null;
    damager = null;
    EntityDamageEvent lastDamage = entity.getBukkitEntity().getLastDamageCause();
    if (lastDamage != null) {
        cause = new ElementTag(event.getEntity().getLastDamageCause().getCause().toString());
        if (lastDamage instanceof EntityDamageByEntityEvent) {
            EntityTag damageEntity = new EntityTag(((EntityDamageByEntityEvent) lastDamage).getDamager());
            EntityTag shooter = damageEntity.getShooter();
            if (shooter != null) {
                damager = shooter;
            } else {
                damager = damageEntity;
            }
        } else if (livingEntity.getKiller() != null) {
            damager = new EntityTag(livingEntity.getKiller());
        }
    }
    cancelled = false;
    this.event = event;
    fire(event);
    EntityTag.forgetEntity(livingEntity);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Example 33 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Jobs by GamingMesh.

the class JobsPaymentListener method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
    // Entity that died must be living
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    LivingEntity lVictim = (LivingEntity) event.getEntity();
    // mob spawner, no payment or experience
    if (lVictim.hasMetadata(mobSpawnerMetadata)) {
        lVictim.removeMetadata(mobSpawnerMetadata, plugin);
        return;
    }
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
        org.bukkit.entity.Player pDamager = null;
        if (e.getDamager() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) e.getDamager();
        } else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) ((Projectile) e.getDamager()).getShooter();
        } else if (e.getDamager() instanceof Tameable) {
            Tameable t = (Tameable) e.getDamager();
            if (t.isTamed() && t.getOwner() instanceof org.bukkit.entity.Player) {
                pDamager = (org.bukkit.entity.Player) t.getOwner();
            }
        }
        if (pDamager != null) {
            // check if in creative
            if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
                return;
            if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
                return;
            // restricted area multiplier
            double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(pDamager);
            // pay
            JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
            Jobs.action(jDamager, new EntityActionInfo(lVictim.getType(), ActionType.KILL), multiplier);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Tameable(org.bukkit.entity.Tameable) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Player(org.bukkit.entity.Player) EntityActionInfo(com.gamingmesh.jobs.actions.EntityActionInfo) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 34 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Glowstone by GlowstoneMC.

the class GlowLivingEntity method damage.

@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
    // invincibility timer
    if (noDamageTicks > 0 || health <= 0 || !canTakeDamage(cause) || isInvulnerable()) {
        return;
    } else {
        noDamageTicks = maximumNoDamageTicks;
    }
    // fire resistance
    if (hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) {
        if (source instanceof Fireball) {
            return;
        } else {
            switch(cause) {
                case FIRE:
                case FIRE_TICK:
                case HOT_FLOOR:
                case LAVA:
                    return;
                default:
            }
        }
    }
    // armor damage protection
    // formula source: http://minecraft.gamepedia.com/Armor#Damage_Protection
    double defensePoints = getAttributeManager().getPropertyValue(Key.KEY_ARMOR);
    double toughness = getAttributeManager().getPropertyValue(Key.KEY_ARMOR_TOUGHNESS);
    amount = amount * (1 - Math.min(20.0, Math.max(defensePoints / 5.0, defensePoints - amount / (2.0 + toughness / 4.0))) / 25);
    // fire event
    EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null ? new EntityDamageEvent(this, cause, amount) : new EntityDamageByEntityEvent(source, this, cause, amount));
    if (event.isCancelled()) {
        return;
    }
    // apply damage
    amount = event.getFinalDamage();
    lastDamage = amount;
    if (isPlayerHit(source)) {
        playerDamageTick = ticksLived;
        if (health - amount <= 0) {
            killer = determinePlayer(source);
            if (killer != null) {
                killer.incrementStatistic(Statistic.KILL_ENTITY, getType());
            }
        }
    }
    setHealth(health - amount);
    playEffectKnownAndSelf(EntityEffect.HURT);
    if (cause == DamageCause.ENTITY_ATTACK && source != null) {
        Vector distance = RayUtil.getRayBetween(getLocation(), ((LivingEntity) source).getEyeLocation());
        Vector rayLength = RayUtil.getVelocityRay(distance).normalize();
        Vector currentVelocity = getVelocity();
        currentVelocity.add(rayLength.multiply(((amount + 1) / 2d)));
        setVelocity(currentVelocity);
    }
    // play sounds, handle death
    if (health > 0) {
        Sound hurtSound = getHurtSound();
        if (hurtSound != null && !isSilent()) {
            world.playSound(location, hurtSound, getSoundVolume(), getSoundPitch());
        }
    }
    setLastDamager(source);
}
Also used : Fireball(org.bukkit.entity.Fireball) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Sound(org.bukkit.Sound) Vector(org.bukkit.util.Vector) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 35 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Glowstone by GlowstoneMC.

the class GlowItemFrame method entityInteract.

// //////////////////////////////////////////////////////////////////////////
// Overrides
@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
    if (message.getAction() == Action.INTERACT.ordinal() && message.getHandSlot() == EquipmentSlot.HAND) {
        if (InventoryUtil.isEmpty(getItem())) {
            ItemStack isInHand = player.getItemInHand();
            if (isInHand != null) {
                setItem(isInHand);
                if (player.getGameMode() != GameMode.CREATIVE) {
                    int amount = player.getItemInHand().getAmount();
                    isInHand.setAmount(amount - 1);
                    if (isInHand.getAmount() <= 0) {
                        isInHand = null;
                    }
                    player.setItemInHand(isInHand);
                }
            }
        } else {
            int rot = (getRotation().ordinal() + 1) % 8;
            setRotation(Rotation.values()[rot]);
        }
    }
    if (message.getAction() == Action.ATTACK.ordinal()) {
        if (isEmpty()) {
            if (EventFactory.getInstance().callEvent(new HangingBreakByEntityEvent(this, player)).isCancelled()) {
                return false;
            }
            if (player.getGameMode() != GameMode.CREATIVE) {
                world.dropItemNaturally(location, new ItemStack(Material.ITEM_FRAME));
            }
            remove();
        } else {
            if (EventFactory.getInstance().callEvent(new EntityDamageByEntityEvent(player, this, DamageCause.ENTITY_ATTACK, 0)).isCancelled()) {
                return false;
            }
            if (player.getGameMode() != GameMode.CREATIVE) {
                world.dropItemNaturally(location, getItem().clone());
            }
            setItem(InventoryUtil.createEmptyStack());
        }
    }
    return true;
}
Also used : HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ItemStack(org.bukkit.inventory.ItemStack)

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