org.bukkit.event.entity.EntityDamageEvent.DamageModifier Java Examples

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent.DamageModifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
    EntityDamageEvent event;
    if (damager != null) {
        event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    } else {
        event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    }

    callEvent(event);

    if (!event.isCancelled()) {
        event.getEntity().setLastDamageCause(event);
    }

    return event;
}
 
Example #2
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption) {
    Map<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    Map<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<DamageModifier, Function<? super Double, Double>>(DamageModifier.class);
    modifiers.put(DamageModifier.BASE, rawDamage);
    modifierFunctions.put(DamageModifier.BASE, ZERO);
    if (source == DamageSource.FALLING_BLOCK || source == DamageSource.ANVIL) {
        modifiers.put(DamageModifier.HARD_HAT, hardHatModifier);
        modifierFunctions.put(DamageModifier.HARD_HAT, hardHat);
    }
    if (damagee instanceof EntityPlayer) {
        modifiers.put(DamageModifier.BLOCKING, blockingModifier);
        modifierFunctions.put(DamageModifier.BLOCKING, blocking);
    }
    modifiers.put(DamageModifier.ARMOR, armorModifier);
    modifierFunctions.put(DamageModifier.ARMOR, armor);
    modifiers.put(DamageModifier.RESISTANCE, resistanceModifier);
    modifierFunctions.put(DamageModifier.RESISTANCE, resistance);
    modifiers.put(DamageModifier.MAGIC, magicModifier);
    modifierFunctions.put(DamageModifier.MAGIC, magic);
    modifiers.put(DamageModifier.ABSORPTION, absorptionModifier);
    modifierFunctions.put(DamageModifier.ABSORPTION, absorption);
    return handleEntityDamageEvent(damagee, source, modifiers, modifierFunctions);
}
 
Example #3
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, double damage, boolean cancelOnZeroDamage) {
    if (entity instanceof EntityEnderCrystal && !(source instanceof EntityDamageSource)) {
        return false;
    }

    final EnumMap<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    final EnumMap<DamageModifier, Function<? super Double, Double>> functions = new EnumMap(DamageModifier.class);

    modifiers.put(DamageModifier.BASE, damage);
    functions.put(DamageModifier.BASE, ZERO);

    final EntityDamageEvent event = handleEntityDamageEvent(entity, source, modifiers, functions);
    if (event == null) {
        return false;
    }
    return event.isCancelled() || (cancelOnZeroDamage && event.getDamage() == 0);
}
 
Example #4
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
    EntityDamageEvent event;
    if (damager != null) {
        event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    } else {
        event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    }

    callEvent(event);

    if (!event.isCancelled()) {
        event.getEntity().setLastDamageCause(event);
    }

    return event;
}
 
Example #5
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption) {
    Map<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    Map<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<DamageModifier, Function<? super Double, Double>>(DamageModifier.class);
    modifiers.put(DamageModifier.BASE, rawDamage);
    modifierFunctions.put(DamageModifier.BASE, ZERO);
    if (source == DamageSource.fallingBlock || source == DamageSource.anvil) {
        modifiers.put(DamageModifier.HARD_HAT, hardHatModifier);
        modifierFunctions.put(DamageModifier.HARD_HAT, hardHat);
    }
    if (damagee instanceof EntityPlayer) {
        modifiers.put(DamageModifier.BLOCKING, blockingModifier);
        modifierFunctions.put(DamageModifier.BLOCKING, blocking);
    }
    modifiers.put(DamageModifier.ARMOR, armorModifier);
    modifierFunctions.put(DamageModifier.ARMOR, armor);
    modifiers.put(DamageModifier.RESISTANCE, resistanceModifier);
    modifierFunctions.put(DamageModifier.RESISTANCE, resistance);
    modifiers.put(DamageModifier.MAGIC, magicModifier);
    modifierFunctions.put(DamageModifier.MAGIC, magic);
    modifiers.put(DamageModifier.ABSORPTION, absorptionModifier);
    modifierFunctions.put(DamageModifier.ABSORPTION, absorption);
    return handleEntityDamageEvent(damagee, source, modifiers, modifierFunctions);
}
 
Example #6
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, double damage) {
    if (entity instanceof EntityEnderCrystal && !(source instanceof EntityDamageSource)) {
        return false;
    }

    final EnumMap<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    final EnumMap<DamageModifier, Function<? super Double, Double>> functions = new EnumMap(DamageModifier.class);

    modifiers.put(DamageModifier.BASE, damage);
    functions.put(DamageModifier.BASE, ZERO);

    final EntityDamageEvent event = handleEntityDamageEvent(entity, source, modifiers, functions);
    if (event == null) {
        return false;
    }
    return event.isCancelled() || (event.getDamage() == 0 && !(entity instanceof EntityItemFrame)); // Cauldron - fix frame removal
}
 
Example #7
Source File: Piercing.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
    if (e instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
        LivingEntity target = (LivingEntity) event.getEntity();

        int armorCounter = 0;
        for (ItemStack piece : target.getEquipment().getArmorContents())
            if (!piece.getType().equals(Material.AIR))
                armorCounter++;

        if (armorCounter == 0)
            return;
        
        event.setDamage(DamageModifier.ARMOR, 0); //Completely remove effects of Armor
        target.getWorld().playEffect(target.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
    }
}