Search in sources :

Example 56 with Wand

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

the class WandCommandExecutor method onWandAdd.

public boolean onWandAdd(CommandSender sender, Player player, String[] parameters) {
    if (parameters.length < 1) {
        sender.sendMessage("Usage: /wand add <spell|material> [material:data]");
        return true;
    }
    Wand wand = checkWand(sender, player);
    if (wand == null) {
        return true;
    }
    Mage mage = controller.getMage(player);
    String spellName = parameters[0];
    if (spellName.equals("material") || spellName.equals("brush")) {
        if (parameters.length < 2) {
            sender.sendMessage("Use: /wand add brush <material:data>");
            return true;
        }
        String materialKey = parameters[1];
        if (!MaterialBrush.isValidMaterial(materialKey, false)) {
            sender.sendMessage(materialKey + " is not a valid brush");
            return true;
        }
        if (wand.addBrush(materialKey)) {
            wand.setActiveBrush(materialKey);
            if (sender != player) {
                sender.sendMessage("Added brush '" + materialKey + "' to " + player.getName() + "'s wand");
            }
        } else {
            wand.setActiveBrush(materialKey);
            mage.sendMessage("Brush activated: " + materialKey);
            if (sender != player) {
                sender.sendMessage(player.getName() + "'s wand already has brush " + materialKey);
            }
        }
        wand.saveState();
        return true;
    }
    Spell spell = mage.getSpell(spellName);
    if (spell == null) {
        sender.sendMessage("Spell '" + spellName + "' unknown, Use /spells for spell list");
        return true;
    }
    SpellTemplate currentSpell = wand.getBaseSpell(spellName);
    if (wand.addSpell(spellName)) {
        wand.setActiveSpell(spellName);
        if (currentSpell != null) {
            String levelDescription = spell.getLevelDescription();
            if (levelDescription == null || levelDescription.isEmpty()) {
                levelDescription = spell.getName();
            }
            if (sender != player) {
                sender.sendMessage(api.getMessages().get("wand.player_spell_upgraded").replace("$player", player.getName()).replace("$name", currentSpell.getName()).replace("$level", levelDescription));
            }
        } else {
            if (sender != player) {
                sender.sendMessage("Added '" + spell.getName() + "' to " + player.getName() + "'s wand");
            }
        }
    } else {
        wand.setActiveSpell(spellName);
        mage.sendMessage(spell.getName() + " activated");
        if (sender != player) {
            sender.sendMessage(player.getName() + "'s wand already has " + spell.getName());
        }
    }
    wand.saveState();
    return true;
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Spell(com.elmakers.mine.bukkit.api.spell.Spell) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 57 with Wand

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

the class CastingCost method has.

@Override
public boolean has(Spell spell) {
    CastContext context = spell.getCurrentCast();
    Mage mage = context.getMage();
    Wand wand = context.getWand();
    return has(mage, wand, spell);
}
Also used : CastContext(com.elmakers.mine.bukkit.api.action.CastContext) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Example 58 with Wand

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

the class CastingCost method use.

@Override
public void use(Spell spell) {
    CastContext context = spell.getCurrentCast();
    Mage mage = context.getMage();
    Wand wand = context.getWand();
    deduct(mage, wand, spell);
}
Also used : CastContext(com.elmakers.mine.bukkit.api.action.CastContext) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Example 59 with Wand

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

the class MagicTabExecutor method giveWand.

public boolean giveWand(CommandSender sender, Player player, String wandKey, boolean quiet, boolean giveItem, boolean giveValue, boolean showWorth) {
    Mage mage = controller.getMage(player);
    Wand currentWand = mage.getActiveWand();
    if (currentWand != null) {
        currentWand.closeInventory();
    }
    Wand wand = api.createWand(wandKey);
    if (wand != null) {
        if (giveItem) {
            ItemStack item = wand.getItem();
            if (item == null) {
                if (!quiet) {
                    if (wandKey == null) {
                        wandKey = "(default)";
                    }
                    sender.sendMessage(api.getMessages().getParameterized("wand.unknown_template", "$name", wandKey));
                    if (sender != player) {
                        sender.sendMessage("Wand " + wand.getName() + " has an invalid icon");
                    }
                }
                return true;
            } else {
                api.giveItemToPlayer(player, wand.getItem());
                if (sender != player && !quiet) {
                    sender.sendMessage("Gave wand " + wand.getName() + " to " + player.getName());
                }
            }
        }
        if (showWorth) {
            showWorth(sender, wand.getItem());
        }
    } else {
        if (!quiet) {
            if (wandKey == null) {
                wandKey = "(default)";
            }
            sender.sendMessage(api.getMessages().getParameterized("wand.unknown_template", "$name", wandKey));
        }
        return false;
    }
    return true;
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack)

Example 60 with Wand

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

the class MagicTabExecutor method showWorth.

protected void showWorth(CommandSender sender, ItemStack item) {
    if (api.isWand(item) || (api.isUpgrade(item))) {
        Wand wand = api.getWand(item);
        if (wand == null) {
            sender.sendMessage("I'm not sure what that's worth, sorry!");
            return;
        }
        sender.sendMessage(ChatColor.AQUA + "WIP: Wand " + ChatColor.GOLD + wand.getName() + ChatColor.AQUA + " is worth " + ChatColor.GREEN + wand.getWorth());
    } else if (api.isSpell(item)) {
        SpellTemplate template = api.getSpellTemplate(api.getSpell(item));
        if (template == null) {
            sender.sendMessage("I'm not sure what that's worth, sorry!");
            return;
        }
        sender.sendMessage(ChatColor.AQUA + "Spell " + ChatColor.GOLD + template.getName() + ChatColor.AQUA + " is worth " + ChatColor.GREEN + template.getWorth());
    } else if (api.isBrush(item)) {
        String materialBrush = api.getBrush(item);
        if (materialBrush == null) {
            sender.sendMessage("I'm not sure what that's worth, sorry!");
            return;
        }
        // TODO: Config-driven!
        int brushWorth = 500;
        sender.sendMessage(ChatColor.AQUA + "WIP: Brush " + ChatColor.GOLD + materialBrush + ChatColor.AQUA + " is worth " + ChatColor.GREEN + brushWorth);
    } else {
        sender.sendMessage("I'm not sure what that's worth, sorry!");
    }
}
Also used : Wand(com.elmakers.mine.bukkit.api.wand.Wand) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

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