Search in sources :

Example 1 with MythicMob

use of io.lumine.xikage.mythicmobs.mobs.MythicMob in project MyPet by xXKeyleXx.

the class MythicMobsHook method on.

@EventHandler
public void on(MyPetDamageEvent event) {
    try {
        if (MythicMobs.inst().getMobManager().isActiveMob(BukkitAdapter.adapt(event.getTarget()))) {
            ActiveMob defender = MythicMobs.inst().getMobManager().getMythicMobInstance(event.getTarget());
            MythicMob defenderType = defender.getType();
            if (defenderType.getIsInvincible()) {
                event.setCancelled(true);
                return;
            }
            double damage, baseDamage = damage = event.getDamage();
            damage -= defender.getArmor();
            if (baseDamage >= 1D && damage < 1D) {
                damage = 1D;
            }
            double modifier = getEntityAttackModifier(defenderType);
            damage *= modifier;
            event.setDamage(damage);
            if (damage == 0) {
                event.setCancelled(true);
            }
        }
    } catch (NumberFormatException ignored) {
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : MythicMob(io.lumine.xikage.mythicmobs.mobs.MythicMob) ActiveMob(io.lumine.xikage.mythicmobs.mobs.ActiveMob) EventHandler(org.bukkit.event.EventHandler)

Example 2 with MythicMob

use of io.lumine.xikage.mythicmobs.mobs.MythicMob in project MyPet by xXKeyleXx.

the class MythicMobsHook method canHurt.

@Override
public boolean canHurt(Player attacker, Entity defender) {
    try {
        if (MythicMobs.inst().getMobManager().isActiveMob(BukkitAdapter.adapt(defender))) {
            MythicMob defenderType = MythicMobs.inst().getMobManager().getMythicMobInstance(defender).getType();
            if (defenderType.getIsInvincible()) {
                return false;
            }
            if (defenderType.hasFaction() && PREVENT_DAMAGE_TO_FACTIONS.contains(defenderType.getFaction())) {
                return false;
            }
            if (PREVENT_DAMAGE_TO_MOBS.contains(defenderType.getInternalName())) {
                return false;
            }
            double modifier = getEntityAttackModifier(defenderType);
            if (modifier == 0) {
                return false;
            }
        }
    } catch (NumberFormatException ignored) {
    } catch (Throwable t) {
        t.printStackTrace();
    }
    return true;
}
Also used : MythicMob(io.lumine.xikage.mythicmobs.mobs.MythicMob)

Aggregations

MythicMob (io.lumine.xikage.mythicmobs.mobs.MythicMob)2 ActiveMob (io.lumine.xikage.mythicmobs.mobs.ActiveMob)1 EventHandler (org.bukkit.event.EventHandler)1