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; }
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); }
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 }
@Override public void damage(double amount) { Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class); modifiers.put(DamageModifier.BASE, 1.0); Map<DamageModifier, Function<Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class); modifierFunctions.put(DamageModifier.BASE, damage -> damage); EntityDamageEvent event = new EntityDamageEvent(this, DamageCause.CUSTOM, modifiers, modifierFunctions); event.setDamage(amount); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { setHealth(health - amount); } }
@Override public void damage(double amount, Entity source) { Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class); modifiers.put(DamageModifier.BASE, 1.0); Map<DamageModifier, Function<Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class); modifierFunctions.put(DamageModifier.BASE, damage -> damage); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(source, this, DamageCause.ENTITY_ATTACK, modifiers, modifierFunctions); event.setDamage(amount); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { setHealth(health - amount); } }
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 EntityHuman) { 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); }
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); }
private static void processSwordCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); SwordsManager swordsManager = mcMMOPlayer.getSwordsManager(); double initialDamage = event.getDamage(); Map<DamageModifier, Double> modifiers = getModifiers(event); if (swordsManager.canActivateAbility()) { mcMMOPlayer.checkAbilityActivation(SkillType.SWORDS); } if (swordsManager.canUseBleed()) { swordsManager.bleedCheck(target); } if (swordsManager.canUseSerratedStrike()) { swordsManager.serratedStrikes(target, initialDamage, modifiers); } startGainXp(mcMMOPlayer, target, SkillType.SWORDS); }
public static EntityDamageByEntityEvent applyScaledModifiers(double initialDamage, double finalDamage, EntityDamageByEntityEvent event) { // No additional damage if (initialDamage == finalDamage) { return event; } for (DamageModifier modifier : DamageModifier.values()) { if (!event.isApplicable(modifier)) { continue; } if (modifier == DamageModifier.BASE) { event.setDamage(modifier, finalDamage); continue; } event.setDamage(modifier, finalDamage / initialDamage * event.getDamage(modifier)); } return event; }