Search in sources :

Example 31 with SpellTemplate

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

the class Mage method createSpell.

@Nullable
protected MageSpell createSpell(String key) {
    MageSpell playerSpell = spells.get(key);
    if (playerSpell != null) {
        playerSpell.setMage(this);
        return playerSpell;
    }
    SpellTemplate spellTemplate = controller.getSpellTemplate(key);
    if (spellTemplate == null)
        return null;
    Spell newSpell = spellTemplate.createSpell();
    if (newSpell == null || !(newSpell instanceof MageSpell))
        return null;
    playerSpell = (MageSpell) newSpell;
    spells.put(newSpell.getKey(), playerSpell);
    playerSpell.setMage(this);
    return playerSpell;
}
Also used : MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ActionSpell(com.elmakers.mine.bukkit.spell.ActionSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) Nullable(javax.annotation.Nullable)

Example 32 with SpellTemplate

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

the class HeroesSkillSpell method canCast.

@Override
public boolean canCast(Location location) {
    if (!isCasting && mage != null && mage.isPlayer() && !heroes.canUseSkill(mage.getPlayer(), skillKey)) {
        return false;
    }
    if (skill instanceof HeroesSpellSkill) {
        HeroesSpellSkill spellSkill = (HeroesSpellSkill) skill;
        SpellTemplate template = spellSkill.getSpellTemplate();
        Spell spell = mage.getSpell(template.getKey());
        if (spell != null) {
            return spell.canCast(location);
        }
    }
    return super.canCast(location);
}
Also used : BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 33 with SpellTemplate

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

the class HeroesSpellSkill method getSkillName.

/**
 * This code is redudant, but unfortunately it needs to be since we need to know the
 * skill name for the super() constructor call.
 */
private static String getSkillName(Heroes heroes, String spellKey) {
    Plugin magicPlugin = heroes.getServer().getPluginManager().getPlugin("Magic");
    if (magicPlugin == null || (!(magicPlugin instanceof MagicAPI) && !magicPlugin.isEnabled())) {
        heroes.getLogger().warning("MagicHeroes skills require the Magic plugin");
        throw new RuntimeException("MagicHeroes skills require the Magic plugin");
    }
    MagicAPI api = (MagicAPI) magicPlugin;
    MageController controller = api.getController();
    SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
    if (spellTemplate == null) {
        controller.getLogger().warning("Failed to load Magic skill spell: " + spellKey);
        throw new RuntimeException("Failed to load Magic skill spell: " + spellKey);
    }
    String baseName = ChatColor.stripColor(spellTemplate.getName().replace(" ", ""));
    return controller.getHeroesSkillPrefix() + baseName;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) MagicAPI(com.elmakers.mine.bukkit.api.magic.MagicAPI) Plugin(org.bukkit.plugin.Plugin) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 34 with SpellTemplate

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

the class MagicController method loadSpells.

protected void loadSpells(Map<String, ConfigurationSection> spellConfigs) {
    if (spellConfigs == null)
        return;
    // Reset existing spells.
    spells.clear();
    spellAliases.clear();
    categories.clear();
    for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
        String key = entry.getKey();
        if (key.equals("default") || key.equals("override"))
            continue;
        ConfigurationSection spellNode = entry.getValue();
        if (spellNode == null) {
            continue;
        }
        Spell newSpell = null;
        try {
            newSpell = loadSpell(key, spellNode, this);
        } catch (Exception ex) {
            newSpell = null;
            ex.printStackTrace();
        }
        if (newSpell == null) {
            getLogger().warning("Magic: Error loading spell " + key);
            continue;
        }
        if (!newSpell.hasIcon()) {
            String icon = spellNode.getString("icon");
            if (icon != null && !icon.isEmpty()) {
                getLogger().info("Couldn't load spell icon '" + icon + "' for spell: " + newSpell.getKey());
            }
        }
        addSpell(newSpell);
    }
    // Second pass to fulfill requirements, which needs all spells loaded
    for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
        SpellTemplate template = getSpellTemplate(entry.getKey());
        if (template != null) {
            template.loadPrerequisites(entry.getValue());
        }
    }
    // Update registered mages so their spells are current
    for (Mage mage : mages.values()) {
        if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
            ((com.elmakers.mine.bukkit.magic.Mage) mage).loadSpells(spellConfigurations);
        }
    }
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 35 with SpellTemplate

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

the class MageCommandExecutor method onMageRemove.

public boolean onMageRemove(CommandSender sender, Player player, String[] parameters) {
    if (parameters.length < 1) {
        sender.sendMessage("Use: /mage remove <spell|material> [material:data]");
        return true;
    }
    Mage mage = controller.getMage(player);
    MageClass activeClass = mage.getActiveClass();
    if (activeClass == null) {
        sender.sendMessage("Can't modify player " + player.getName());
        return true;
    }
    String spellName = parameters[0];
    if (spellName.equals("material") || spellName.equals("brush")) {
        if (parameters.length < 2) {
            sender.sendMessage("Use: /mage remove brush <material:data>");
            return true;
        }
        String materialKey = parameters[1];
        if (activeClass.removeBrush(materialKey)) {
            mage.sendMessage("Brush '" + materialKey + "' has been removed");
            if (sender != player) {
                sender.sendMessage("Removed brush '" + materialKey + "' from " + player.getName());
            }
        } else {
            if (sender != player) {
                sender.sendMessage(player.getName() + " does not have brush " + materialKey);
            }
        }
        return true;
    }
    if (activeClass.removeSpell(spellName)) {
        SpellTemplate template = api.getSpellTemplate(spellName);
        if (template != null) {
            spellName = template.getName();
        }
        mage.sendMessage("Spell '" + spellName + "' has been removed");
        if (sender != player) {
            sender.sendMessage("Removed '" + spellName + "' from " + player.getName());
        }
    } else {
        if (sender != player) {
            sender.sendMessage(player.getName() + " does not have " + spellName);
        }
    }
    return true;
}
Also used : MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) 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