Search in sources :

Example 36 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand 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 37 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand 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)

Example 38 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class StashSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (!target.hasEntity())
        return SpellResult.NO_TARGET;
    Entity targetEntity = target.getEntity();
    if (!(targetEntity instanceof HumanEntity))
        return SpellResult.NO_TARGET;
    Player showPlayer = mage.getPlayer();
    if (showPlayer == null)
        return SpellResult.PLAYER_REQUIRED;
    String typeString = parameters.getString("type", "ender");
    // Special case for wands
    if (targetEntity instanceof Player && targetEntity != showPlayer) {
        Player targetPlayer = (Player) targetEntity;
        Mage targetMage = controller.getMage(targetPlayer);
        if (!mage.isSuperPowered() && isSuperProtected(targetMage)) {
            return SpellResult.NO_TARGET;
        }
        if (targetMage.getActiveWand() != null && typeString.equalsIgnoreCase("inventory")) {
            targetMage.getActiveWand().closeInventory();
        }
    }
    // Make sure to close the player's wand
    Wand activeWand = mage.getActiveWand();
    if (activeWand != null) {
        activeWand.closeInventory();
    }
    HumanEntity humanTarget = (HumanEntity) targetEntity;
    if (typeString.equalsIgnoreCase("inventory")) {
        Inventory inventory = humanTarget.getInventory();
        showPlayer.openInventory(inventory);
    } else {
        Inventory enderInventory = humanTarget.getEnderChest();
        showPlayer.openInventory(enderInventory);
    }
    return SpellResult.CAST;
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) Target(com.elmakers.mine.bukkit.utility.Target) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) HumanEntity(org.bukkit.entity.HumanEntity) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Inventory(org.bukkit.inventory.Inventory)

Example 39 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class MountArmorStandAction method mount.

@Override
protected SpellResult mount(CastContext context) {
    Mage mage = context.getMage();
    Player player = mage.getPlayer();
    if (player == null && mountWand) {
        return SpellResult.PLAYER_REQUIRED;
    }
    item = null;
    if (mountWand) {
        Wand wand = context.getWand();
        if (wand == null) {
            return SpellResult.NO_TARGET;
        }
        wand.deactivate();
        item = wand.getItem();
        if (item == null || item.getType() == Material.AIR) {
            return SpellResult.FAIL;
        }
        slotNumber = wand.getHeldSlot();
    }
    if (!mountTarget && !mountNewArmorStand(context)) {
        return SpellResult.FAIL;
    }
    if (mountWand) {
        player.getInventory().setItem(slotNumber, new ItemStack(Material.AIR));
    }
    SpellResult result = super.mount(context);
    ;
    if (mount == null || !(mount instanceof ArmorStand)) {
        result = SpellResult.FAIL;
    }
    return result;
}
Also used : Player(org.bukkit.entity.Player) ArmorStand(org.bukkit.entity.ArmorStand) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Example 40 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class EnchantWandAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    Wand wand = context.getWand();
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    if (levels <= 0) {
        return SpellResult.FAIL;
    }
    if (wand == null) {
        context.showMessage("no_wand", "You must be holding a wand!");
        return SpellResult.FAIL;
    }
    if (requiredPath != null || exactPath != null) {
        WandUpgradePath path = wand.getPath();
        if (path == null) {
            context.showMessage(context.getMessage("no_upgrade", "You may not learn with that $wand.").replace("$wand", wand.getName()));
            return SpellResult.FAIL;
        }
        if ((requiredPath != null && !path.hasPath(requiredPath)) || (exactPath != null && !exactPath.equals(path.getKey()))) {
            WandUpgradePath requiresPath = com.elmakers.mine.bukkit.wand.WandUpgradePath.getPath(requiredPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_path", "You may not learn with that $wand.").replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in EnchantWand action: " + requiredPath);
            }
            return SpellResult.FAIL;
        }
    }
    if (requireItem != null) {
        MageController controller = context.getController();
        boolean foundItem = false;
        ItemStack[] contents = player.getInventory().getContents();
        for (int i = 0; i < contents.length; i++) {
            ItemStack item = contents[i];
            if (controller.itemsAreEqual(item, requireItem)) {
                player.getInventory().setItem(i, null);
                foundItem = true;
                break;
            }
        }
        if (!foundItem) {
            context.showMessage("insufficient_resources", "You must have a $requires");
            return SpellResult.INSUFFICIENT_RESOURCES;
        }
    }
    int xpLevels = levels;
    if (useXp) {
        xpLevels = mage.getLevel();
    }
    int levelsUsed = wand.enchant(xpLevels, mage);
    if (levelsUsed == 0) {
        return SpellResult.FAIL;
    }
    if (useXp) {
        mage.setLevel(Math.max(0, mage.getLevel() - levelsUsed));
    }
    return SpellResult.CAST;
}
Also used : WandUpgradePath(com.elmakers.mine.bukkit.api.wand.WandUpgradePath) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Wand (com.elmakers.mine.bukkit.api.wand.Wand)60 Mage (com.elmakers.mine.bukkit.api.magic.Mage)47 ItemStack (org.bukkit.inventory.ItemStack)20 Player (org.bukkit.entity.Player)18 MageController (com.elmakers.mine.bukkit.api.magic.MageController)14 Entity (org.bukkit.entity.Entity)10 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)7 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)7 ArrayList (java.util.ArrayList)7 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)6 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)5 Inventory (org.bukkit.inventory.Inventory)5 ItemMeta (org.bukkit.inventory.meta.ItemMeta)5 ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)4 Spell (com.elmakers.mine.bukkit.api.spell.Spell)4 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)4 Nullable (javax.annotation.Nullable)4 Checker (ch.njol.util.Checker)3 IOException (java.io.IOException)3 Block (org.bukkit.block.Block)3