Search in sources :

Example 46 with SpellTemplate

use of com.elmakers.mine.bukkit.api.spell.SpellTemplate 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 47 with SpellTemplate

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

Example 48 with SpellTemplate

use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.

the class SpellsCommandExecutor method listSpellsByCategory.

public void listSpellsByCategory(CommandSender sender, String category) {
    List<SpellTemplate> categorySpells = new ArrayList<>();
    Collection<SpellTemplate> spellVariants = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
    Player player = sender instanceof Player ? (Player) sender : null;
    for (SpellTemplate spell : spellVariants) {
        SpellCategory spellCategory = spell.getCategory();
        if (spellCategory != null && spellCategory.getKey().equalsIgnoreCase(category) && (player == null || spell.hasCastPermission(player))) {
            categorySpells.add(spell);
        }
    }
    if (categorySpells.size() == 0) {
        String message = api.getMessages().get("general.no_spells_in_category");
        message = message.replace("$category", category);
        sender.sendMessage(message);
        return;
    }
    sender.sendMessage(category + ":");
    Collections.sort(categorySpells);
    for (SpellTemplate spell : categorySpells) {
        String name = spell.getName();
        String description = spell.getDescription();
        if (!name.equals(spell.getKey())) {
            description = name + " : " + description;
        }
        sender.sendMessage(ChatColor.AQUA + spell.getKey() + ChatColor.BLUE + " [" + spell.getIcon().getName() + "] : " + ChatColor.YELLOW + description);
    }
}
Also used : Player(org.bukkit.entity.Player) SpellCategory(com.elmakers.mine.bukkit.api.spell.SpellCategory) ArrayList(java.util.ArrayList) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Aggregations

SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)48 ArrayList (java.util.ArrayList)16 Mage (com.elmakers.mine.bukkit.api.magic.Mage)14 Spell (com.elmakers.mine.bukkit.api.spell.Spell)10 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)9 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)8 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)8 ItemStack (org.bukkit.inventory.ItemStack)8 Wand (com.elmakers.mine.bukkit.api.wand.Wand)7 Player (org.bukkit.entity.Player)7 MageController (com.elmakers.mine.bukkit.api.magic.MageController)5 Messages (com.elmakers.mine.bukkit.api.magic.Messages)5 SpellCategory (com.elmakers.mine.bukkit.api.spell.SpellCategory)5 BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Nullable (javax.annotation.Nullable)5 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)4 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)3 ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)3