Search in sources :

Example 6 with SpellKey

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

the class CasterProperties method addSpell.

@Override
public boolean addSpell(String spellKey) {
    BaseMagicConfigurable storage = getStorage("spells");
    if (storage != this && storage != null) {
        return storage.addSpell(spellKey);
    }
    SpellTemplate template = controller.getSpellTemplate(spellKey);
    if (template == null) {
        controller.getLogger().warning("Tried to add unknown spell: " + spellKey);
        return false;
    }
    // Convert to spell if aliased
    spellKey = template.getKey();
    Collection<String> spells = getBaseSpells();
    SpellKey key = new SpellKey(spellKey);
    SpellTemplate currentSpell = getSpellTemplate(spellKey);
    boolean modified = spells.add(key.getBaseKey());
    if (modified) {
        setProperty("spells", new ArrayList<>(spells));
    }
    boolean levelModified = false;
    if (key.getLevel() > 1) {
        levelModified = upgradeSpellLevel(key.getBaseKey(), key.getLevel());
    }
    if (!modified && !levelModified) {
        return false;
    }
    // Special handling for spells to remove
    Collection<SpellKey> spellsToRemove = template.getSpellsToRemove();
    for (SpellKey removeKey : spellsToRemove) {
        removeSpell(removeKey.getBaseKey());
    }
    Mage mage = getMage();
    if (mage != null) {
        if (currentSpell != null) {
            String levelDescription = template.getLevelDescription();
            if (levelDescription == null || levelDescription.isEmpty()) {
                levelDescription = template.getName();
            }
            sendLevelMessage("spell_upgraded", currentSpell.getName(), levelDescription);
            String upgradeDescription = template.getUpgradeDescription().replace("$name", currentSpell.getName());
            if (!upgradeDescription.isEmpty()) {
                mage.sendMessage(controller.getMessages().get("spell.upgrade_description_prefix") + upgradeDescription);
            }
            SpellUpgradeEvent upgradeEvent = new SpellUpgradeEvent(mage, getWand(), currentSpell, template);
            Bukkit.getPluginManager().callEvent(upgradeEvent);
        } else {
            // This is a little hacky, but it is here to fix duplicate spell messages from the spellshop.
            if (mage.getActiveGUI() == null)
                sendAddMessage("spell_added", template.getName());
            AddSpellEvent addEvent = new AddSpellEvent(mage, getWand(), template);
            Bukkit.getPluginManager().callEvent(addEvent);
        }
    }
    return true;
}
Also used : AddSpellEvent(com.elmakers.mine.bukkit.api.event.AddSpellEvent) SpellUpgradeEvent(com.elmakers.mine.bukkit.api.event.SpellUpgradeEvent) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 7 with SpellKey

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

the class CasterProperties method hasSpell.

@Override
public boolean hasSpell(String key) {
    SpellKey spellKey = new SpellKey(key);
    if (!getBaseSpells().contains(spellKey.getBaseKey()))
        return false;
    int level = getSpellLevel(spellKey.getBaseKey());
    return (level >= spellKey.getLevel());
}
Also used : SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey)

Example 8 with SpellKey

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

the class CasterProperties method removeSpell.

public boolean removeSpell(String spellKey) {
    Collection<String> spells = getBaseSpells();
    SpellKey key = new SpellKey(spellKey);
    boolean modified = spells.remove(key.getBaseKey());
    if (modified) {
        setProperty("spells", new ArrayList<>(spells));
        Map<String, Integer> spellLevels = getSpellLevels();
        if (spellLevels.remove(key.getBaseKey()) != null) {
            setProperty("spell_levels", spellLevels);
        }
    }
    return modified;
}
Also used : SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey)

Example 9 with SpellKey

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

the class CasterProperties method addItem.

@Override
public boolean addItem(ItemStack item) {
    if (Wand.isSpell(item) && !Wand.isSkill(item)) {
        String spell = Wand.getSpell(item);
        SpellKey spellKey = new SpellKey(spell);
        Map<String, Integer> spellLevels = getSpellLevels();
        Integer currentLevel = spellLevels.get(spellKey.getBaseKey());
        if ((currentLevel == null || currentLevel < spellKey.getLevel()) && addSpell(spell)) {
            return true;
        }
    } else if (Wand.isBrush(item)) {
        String materialKey = Wand.getBrush(item);
        Set<String> materials = getBrushes();
        if (!materials.contains(materialKey) && addBrush(materialKey)) {
            return true;
        }
    }
    Mage mage = getMage();
    if (mage != null && !mage.isAtMaxSkillPoints() && controller.skillPointItemsEnabled()) {
        Integer sp = Wand.getSP(item);
        if (sp != null) {
            int amount = (int) Math.floor(mage.getSPMultiplier() * sp * item.getAmount());
            mage.addSkillPoints(amount);
            return true;
        }
    }
    return false;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey)

Example 10 with SpellKey

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

the class SpellProgressAction method clicked.

@Override
public void clicked(InventoryClickEvent event) {
    event.setCancelled(true);
    if (context != null) {
        Mage mage = context.getMage();
        Wand wand = context.getWand();
        ItemStack item = event.getCurrentItem();
        if (wand != null && com.elmakers.mine.bukkit.wand.Wand.isSpell(item)) {
            String spellKey = com.elmakers.mine.bukkit.wand.Wand.getSpell(item);
            SpellKey upgradeKey = new SpellKey(spellKey);
            wand.setActiveSpell(upgradeKey.getBaseKey());
        }
        mage.deactivateGUI();
    }
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey)

Aggregations

SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)30 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)9 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)9 ArrayList (java.util.ArrayList)6 ItemStack (org.bukkit.inventory.ItemStack)6 Nullable (javax.annotation.Nullable)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 Map (java.util.Map)3 Set (java.util.Set)3 CastingCost (com.elmakers.mine.bukkit.api.spell.CastingCost)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)2 Inventory (org.bukkit.inventory.Inventory)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 SpellData (com.elmakers.mine.bukkit.api.data.SpellData)1