Search in sources :

Example 1 with MageSpell

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

the class MagicController method loadSpell.

@Nullable
public static Spell loadSpell(String name, ConfigurationSection node, MageController controller) {
    String className = node.getString("class");
    if (className == null || className.equalsIgnoreCase("action") || className.equalsIgnoreCase("actionspell")) {
        className = "com.elmakers.mine.bukkit.spell.ActionSpell";
    } else if (className.indexOf('.') <= 0) {
        className = BUILTIN_SPELL_CLASSPATH + "." + className;
    }
    Class<?> spellClass = null;
    try {
        spellClass = Class.forName(className);
    } catch (Throwable ex) {
        controller.getLogger().log(Level.WARNING, "Error loading spell: " + className, ex);
        return null;
    }
    if (spellClass.getAnnotation(Deprecated.class) != null) {
        controller.getLogger().warning("Spell " + name + " is using a deprecated spell class " + className + ". This will be removed in the future, please see the default configs for alternatives.");
    }
    Object newObject;
    try {
        newObject = spellClass.getDeclaredConstructor().newInstance();
    } catch (Throwable ex) {
        controller.getLogger().log(Level.WARNING, "Error loading spell: " + className, ex);
        return null;
    }
    if (newObject == null || !(newObject instanceof MageSpell)) {
        controller.getLogger().warning("Error loading spell: " + className + ", does it implement MageSpell?");
        return null;
    }
    MageSpell newSpell = (MageSpell) newObject;
    newSpell.initialize(controller);
    newSpell.loadTemplate(name, node);
    com.elmakers.mine.bukkit.api.spell.SpellCategory category = newSpell.getCategory();
    if (category instanceof SpellCategory) {
        ((SpellCategory) category).addSpellTemplate(newSpell);
    }
    return newSpell;
}
Also used : SpellCategory(com.elmakers.mine.bukkit.spell.SpellCategory) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) Nullable(javax.annotation.Nullable)

Example 2 with MageSpell

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

the class MagicController method addSpell.

public void addSpell(Spell variant) {
    SpellTemplate conflict = spells.get(variant.getKey());
    if (conflict != null) {
        getLogger().log(Level.WARNING, "Duplicate spell key: '" + conflict.getKey() + "'");
    } else {
        spells.put(variant.getKey(), variant);
        SpellData data = templateDataMap.get(variant.getSpellKey().getBaseKey());
        if (data == null) {
            data = new SpellData(variant.getSpellKey().getBaseKey());
            templateDataMap.put(variant.getSpellKey().getBaseKey(), data);
        }
        if (variant instanceof MageSpell) {
            ((MageSpell) variant).setSpellData(data);
        }
        String alias = variant.getAlias();
        if (alias != null && alias.length() > 0) {
            spellAliases.put(alias, variant);
        }
    }
}
Also used : SpellData(com.elmakers.mine.bukkit.api.data.SpellData) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 3 with MageSpell

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

the class Mage method deactivateAllSpells.

@Override
public void deactivateAllSpells(boolean force, boolean quiet) {
    // Copy this set since spells will get removed while iterating!
    List<MageSpell> active = new ArrayList<>(activeSpells);
    for (MageSpell spell : active) {
        if (spell.deactivate(force, quiet)) {
            activeSpells.remove(spell);
        }
    }
    // This is mainly here to prevent multi-wand spamming and for
    // Disarm to be more powerful.. because Disarm needs to be more
    // powerful :|
    cancelPending(false);
}
Also used : ArrayList(java.util.ArrayList) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell)

Example 4 with MageSpell

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

the class Mage method activateSpell.

@Override
public void activateSpell(Spell spell) {
    if (spell instanceof MageSpell) {
        MageSpell mageSpell = ((MageSpell) spell);
        activeSpells.add(mageSpell);
        mageSpell.setActive(true);
    }
}
Also used : MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell)

Example 5 with MageSpell

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

the class Mage method getSpell.

@Nullable
@Override
public MageSpell getSpell(String key) {
    if (loading)
        return null;
    MageSpell playerSpell = spells.get(key);
    if (playerSpell == null) {
        playerSpell = createSpell(key);
        if (playerSpell != null) {
            SpellData spellData = this.spellData.get(key);
            if (spellData == null) {
                spellData = new SpellData(key);
                this.spellData.put(key, spellData);
            }
            playerSpell.load(spellData);
        }
    } else {
        playerSpell.setMage(this);
    }
    return playerSpell;
}
Also used : SpellData(com.elmakers.mine.bukkit.api.data.SpellData) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) Nullable(javax.annotation.Nullable)

Aggregations

MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)14 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)6 ArrayList (java.util.ArrayList)6 Nullable (javax.annotation.Nullable)6 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)3 BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)3 ItemStack (org.bukkit.inventory.ItemStack)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 SpellData (com.elmakers.mine.bukkit.api.data.SpellData)2 Messages (com.elmakers.mine.bukkit.api.magic.Messages)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 Wand (com.elmakers.mine.bukkit.api.wand.Wand)2 ActionSpell (com.elmakers.mine.bukkit.spell.ActionSpell)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 Player (org.bukkit.entity.Player)2 CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1