Search in sources :

Example 11 with SpellKey

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

the class Wand method buildInventory.

protected void buildInventory() {
    // Force an update of the display inventory since chest mode is a different size
    displayInventory = null;
    updateHotbarCount();
    for (Inventory hotbar : hotbars) {
        hotbar.clear();
    }
    inventories.clear();
    List<ItemStack> unsorted = new ArrayList<>();
    for (String key : spells) {
        int spellLevel = getSpellLevel(key);
        SpellKey spellKey = new SpellKey(key, spellLevel);
        SpellTemplate spell = controller.getSpellTemplate(spellKey.getKey());
        ItemStack itemStack = createSpellItem(spell, "", controller, getActiveMage(), this, false);
        if (itemStack != null) {
            Integer slot = spellInventory.get(spell.getSpellKey().getBaseKey());
            if (slot == null) {
                unsorted.add(itemStack);
            } else {
                addToInventory(itemStack, slot);
            }
        }
    }
    WandMode brushMode = getBrushMode();
    for (String brushKey : brushes) {
        boolean addToInventory = brushMode == WandMode.INVENTORY || (MaterialBrush.isSpecialMaterialKey(brushKey) && !MaterialBrush.isSchematic(brushKey));
        if (addToInventory) {
            ItemStack itemStack = createBrushIcon(brushKey);
            if (itemStack == null) {
                controller.getPlugin().getLogger().warning("Unable to create brush icon for key " + brushKey);
                continue;
            }
            Integer slot = brushInventory.get(brushKey);
            if (activeBrush == null || activeBrush.length() == 0)
                activeBrush = brushKey;
            addToInventory(itemStack, slot);
        }
    }
    for (ItemStack unsortedItem : unsorted) {
        addToInventory(unsortedItem);
    }
    updateHasInventory();
    if (openInventoryPage >= inventories.size() && openInventoryPage != 0 && hasInventory) {
        setOpenInventoryPage(0);
    }
}
Also used : ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 12 with SpellKey

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

the class Wand method loadSpells.

protected void loadSpells(Collection<String> spellKeys) {
    clearSpells();
    WandUpgradePath path = getPath();
    for (String spellName : spellKeys) {
        String[] pieces = StringUtils.split(spellName, '@');
        Integer slot = parseSlot(pieces);
        // Handle aliases and upgrades smoothly
        String loadedKey = pieces[0].trim();
        SpellKey spellKey = new SpellKey(loadedKey);
        SpellTemplate spell = controller.getSpellTemplate(loadedKey);
        if (limitSpellsToPath && path != null && !path.containsSpell(spellKey.getBaseKey()))
            continue;
        // Downgrade spells if higher levels have gone missing
        while (spell == null && spellKey.getLevel() > 0) {
            spellKey = new SpellKey(spellKey.getBaseKey(), spellKey.getLevel() - 1);
            spell = controller.getSpellTemplate(spellKey.getKey());
        }
        if (spell != null) {
            spellKey = spell.getSpellKey();
            Integer currentLevel = spellLevels.get(spellKey.getBaseKey());
            if (spellKey.getLevel() > 1 && (currentLevel == null || currentLevel < spellKey.getLevel())) {
                setSpellLevel(spellKey.getBaseKey(), spellKey.getLevel());
            }
            if (slot != null) {
                spellInventory.put(spellKey.getBaseKey(), slot);
            }
            spells.add(spellKey.getBaseKey());
            if (activeSpell == null || activeSpell.length() == 0) {
                activeSpell = spellKey.getBaseKey();
            }
        }
    }
}
Also used : SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 13 with SpellKey

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

the class Wand method setActiveSpell.

@Override
public void setActiveSpell(String activeSpell) {
    if (activeSpell != null) {
        SpellKey spellKey = new SpellKey(activeSpell);
        this.activeSpell = spellKey.getBaseKey();
    } else {
        this.activeSpell = null;
    }
    checkActiveSpell();
    setProperty("active_spell", this.activeSpell);
    saveState();
    updateName();
}
Also used : SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey)

Example 14 with SpellKey

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

the class WandOrganizer method removeHotbar.

protected void removeHotbar(Map<String, Integer> spells, Map<String, Integer> brushes) {
    if (wand.getHotbarCount() == 0)
        return;
    List<Inventory> hotbars = wand.getHotbars();
    for (Inventory hotbar : hotbars) {
        int hotbarSize = hotbar.getSize();
        for (int i = 0; i < hotbarSize; i++) {
            ItemStack hotbarItem = hotbar.getItem(i);
            if (hotbarItem == null || hotbarItem.getType() == Material.AIR)
                continue;
            String spellName = Wand.getSpell(hotbarItem);
            if (spellName != null) {
                SpellKey spellKey = new SpellKey(spellName);
                spellName = spellKey.getBaseKey();
            }
            if (spellName != null) {
                spells.remove(spellName);
            } else {
                String materialKey = Wand.getBrush(hotbarItem);
                if (materialKey != null) {
                    brushes.remove(materialKey);
                }
            }
        }
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey)

Example 15 with SpellKey

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

the class MagicConfigurableExecutor method onLevelSpells.

protected boolean onLevelSpells(String command, CommandSender sender, Player player, CasterProperties caster, Integer maxLevel) {
    Collection<String> spells = caster.getSpells();
    MageController controller = api.getController();
    int levelledCount = 0;
    for (String spellKey : spells) {
        SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
        if (spellTemplate == null)
            continue;
        SpellKey key = spellTemplate.getSpellKey();
        int currentLevel = key.getLevel();
        if (maxLevel != null && currentLevel >= maxLevel)
            continue;
        int targetLevel = key.getLevel();
        while (spellTemplate != null && (maxLevel == null || targetLevel < maxLevel)) {
            key = new SpellKey(key.getBaseKey(), targetLevel + 1);
            spellTemplate = controller.getSpellTemplate(key.getKey());
            if (spellTemplate != null) {
                targetLevel++;
            }
        }
        if (currentLevel >= targetLevel)
            continue;
        key = new SpellKey(key.getBaseKey(), targetLevel);
        caster.addSpell(key.getKey());
        levelledCount++;
    }
    if (sender != player) {
        if (levelledCount > 0) {
            sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
        } else {
            sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_not_levelled", "$name", player.getName()));
        }
    } else {
        if (levelledCount > 0) {
            sender.sendMessage(api.getMessages().getParameterized(command + ".spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
        } else {
            sender.sendMessage(api.getMessages().getParameterized(command + ".spells_not_levelled", "$name", player.getName()));
        }
    }
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

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