Search in sources :

Example 1 with Checker

use of ch.njol.util.Checker in project MagicPlugin by elBukkit.

the class CondHasPath method check.

@Override
public boolean check(final Event e) {
    return entities.check(e, new Checker<Entity>() {

        @Override
        public boolean check(final Entity entity) {
            final Mage mage = MagicPlugin.getAPI().getController().getRegisteredMage(entity);
            if (mage == null) {
                return false;
            }
            return paths.check(e, new Checker<String>() {

                @Override
                public boolean check(final String pathKey) {
                    Wand wand = mage.getActiveWand();
                    if (checkPath(wand, pathKey)) {
                        return true;
                    }
                    MageClass activeClass = mage.getActiveClass();
                    if (checkPath(activeClass, pathKey)) {
                        return true;
                    }
                    return false;
                }
            }, isNegated());
        }
    });
}
Also used : Entity(org.bukkit.entity.Entity) Checker(ch.njol.util.Checker) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Example 2 with Checker

use of ch.njol.util.Checker in project MagicPlugin by elBukkit.

the class CondHasItem method check.

@Override
public boolean check(final Event e) {
    return entities.check(e, new Checker<Entity>() {

        @Override
        public boolean check(final Entity entity) {
            final MageController controller = MagicPlugin.getAPI().getController();
            final Mage mage = controller.getRegisteredMage(entity);
            if (mage == null) {
                return false;
            }
            final Wand wand = offhand ? mage.getOffhandWand() : mage.getActiveWand();
            if (itemKeys == null) {
                return (wand != null) != isNegated();
            }
            final LivingEntity living = mage.getLivingEntity();
            final ItemStack item = wand == null && living != null ? (offhand ? living.getEquipment().getItemInOffHand() : living.getEquipment().getItemInMainHand()) : null;
            return itemKeys.check(e, new Checker<String>() {

                @Override
                public boolean check(final String targetKey) {
                    if (armor) {
                        if (living == null)
                            return false;
                        for (ItemStack armorItem : living.getEquipment().getArmorContents()) {
                            if (armorItem == null)
                                continue;
                            String key = controller.getWandKey(armorItem);
                            if (key != null && key.equalsIgnoreCase(targetKey))
                                return true;
                            key = controller.getItemKey(armorItem);
                            if (key != null && key.equalsIgnoreCase(targetKey))
                                return true;
                        }
                        return false;
                    }
                    if (wand != null && wand.getTemplateKey().equalsIgnoreCase(targetKey)) {
                        return true;
                    }
                    if (item != null) {
                        String itemKey = controller.getItemKey(item);
                        if (itemKey != null && itemKey.equalsIgnoreCase(targetKey)) {
                            return true;
                        }
                    }
                    return false;
                }
            }, isNegated());
        }
    });
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Checker(ch.njol.util.Checker) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with Checker

use of ch.njol.util.Checker in project MagicPlugin by elBukkit.

the class CondHasSpell method check.

@Override
public boolean check(final Event e) {
    return entities.check(e, new Checker<Entity>() {

        @Override
        public boolean check(final Entity entity) {
            final Mage mage = MagicPlugin.getAPI().getController().getRegisteredMage(entity);
            if (mage == null) {
                return false;
            }
            return spells.check(e, new Checker<String>() {

                @Override
                public boolean check(final String spellKey) {
                    Wand wand = mage.getActiveWand();
                    if (wand != null && wand.hasSpell(spellKey)) {
                        return true;
                    }
                    MageClass activeClass = mage.getActiveClass();
                    if (activeClass != null && activeClass.hasSpell(spellKey)) {
                        return true;
                    }
                    return false;
                }
            }, isNegated());
        }
    });
}
Also used : Entity(org.bukkit.entity.Entity) Checker(ch.njol.util.Checker) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Aggregations

Checker (ch.njol.util.Checker)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 Wand (com.elmakers.mine.bukkit.api.wand.Wand)3 Entity (org.bukkit.entity.Entity)3 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)2 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 LivingEntity (org.bukkit.entity.LivingEntity)1 ItemStack (org.bukkit.inventory.ItemStack)1