@@ -0,0 +1,3263 @@
+/*%0A * Copyright (c) 2013 - 2017 xxyy (Philipp Nowak; xyc@l1t.li). All rights reserved.%0A *%0A * Any usage, including, but not limited to, compiling, running, redistributing, printing,%0A *  copying and reverse-engineering is strictly prohibited without explicit written permission%0A *  from the original author and may result in legal steps being taken.%0A *%0A * See the included LICENSE file (core/src/main/resources) for details.%0A */%0A%0Apackage li.l1t.common.util;%0A%0Aimport org.bukkit.entity.*;%0Aimport org.bukkit.event.entity.EntityDamageByEntityEvent;%0Aimport org.bukkit.event.entity.EntityDamageEvent;%0A%0Aimport java.util.Optional;%0A%0A/**%0A * Provides static utility methods for dealing with damage events.%0A *%0A * @author %3Ca href=%22https://l1t.li/%22%3ELiterallie%3C/a%3E%0A * @since 2017-04-12%0A */%0Apublic class DamageHelper %7B%0A    private DamageHelper() %7B%0A%0A    %7D%0A%0A    /**%0A     * Attempts to find the actual damager of given event by looking at the event damager and then resolving the player%0A     * who owns that damager, if any. This especially applies to things like arrows and wolves. If the damager is a%0A     * player, they are returned directly.%0A     *%0A     * @param event the event to inspect%0A     * @return the player that actually caused given event's damage%0A     */%0A    public static Optional%3CPlayer%3E findActualDamager(EntityDamageEvent event) %7B%0A        if (event instanceof EntityDamageByEntityEvent) %7B%0A            Entity damager = ((EntityDamageByEntityEvent) event).getDamager();%0A            if (damager instanceof Player) %7B%0A                return Optional.of((Player) damager);%0A            %7D else if (damager instanceof Projectile) %7B%0A                return optionalIfPlayer(((Projectile) damager).getShooter());%0A            %7D else if (damager instanceof Wolf) %7B%0A                return optionalIfPlayer(((Wolf) damager).getOwner());%0A            %7D%0A        %7D%0A        return Optional.empty();%0A    %7D%0A%0A    private static Optional%3CPlayer%3E optionalIfPlayer(Object possiblePlayer) %7B%0A        if (possiblePlayer instanceof Player) %7B%0A            return Optional.of((Player) possiblePlayer);%0A        %7D else %7B%0A            return Optional.empty();%0A        %7D%0A    %7D%0A%0A    /**%0A     * @param event the event to inspect%0A     * @return whether given event would cause the affected entity to die%0A     */%0A    public static boolean isFatalHit(EntityDamageEvent event) %7B%0A        Entity entity = event.getEntity();%0A        return entity instanceof Damageable &&%0A                (((Damageable) entity).getHealth() - event.getFinalDamage()) %3C= 0D;%0A    %7D%0A%0A    /**%0A     * Cancels given event and, if the damage cause was a wolf, resets their target so that they won't immediately%0A     * attack the same player again.%0A     *%0A     * @param event the event to operate on%0A     */%0A    public static void cancelAndStopWolves(EntityDamageEvent event) %7B%0A        event.setCancelled(true);%0A        if (event instanceof EntityDamageByEntityEvent) %7B%0A            Entity damager = ((EntityDamageByEntityEvent) event).getDamager();%0A            if (damager.getType() == EntityType.WOLF) %7B%0A                Wolf wolf = (Wolf) damager;%0A                AnimalTamer prevOwner = wolf.getOwner();%0A                wolf.setOwner((Player) event.getEntity());%0A                wolf.setOwner(prevOwner);%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add DamageHelper for dealing with damage events