Search in sources :

Example 1 with SpellData

use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.

the class MagicController method loadSpellData.

protected void loadSpellData() {
    try {
        ConfigurationSection configNode = loadDataFile(SPELLS_DATA_FILE);
        if (configNode == null)
            return;
        Set<String> keys = configNode.getKeys(false);
        for (String key : keys) {
            ConfigurationSection node = configNode.getConfigurationSection(key);
            SpellKey spellKey = new SpellKey(key);
            SpellData templateData = templateDataMap.get(spellKey.getBaseKey());
            if (templateData == null) {
                templateData = new SpellData(spellKey.getBaseKey());
                templateDataMap.put(templateData.getKey().getBaseKey(), templateData);
            }
            templateData.setCastCount(templateData.getCastCount() + node.getLong("cast_count", 0));
            templateData.setLastCast(Math.max(templateData.getLastCast(), node.getLong("last_cast", 0)));
        }
    } catch (Exception ex) {
        getLogger().warning("Failed to load spell metrics");
    }
}
Also used : SpellData(com.elmakers.mine.bukkit.api.data.SpellData) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with SpellData

use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.

the class MagicController method saveSpellData.

protected void saveSpellData(Collection<YamlDataFile> stores) {
    String lastKey = "";
    try {
        YamlDataFile spellsDataFile = createDataFile(SPELLS_DATA_FILE);
        for (SpellData data : templateDataMap.values()) {
            lastKey = data.getKey().getBaseKey();
            ConfigurationSection spellNode = spellsDataFile.createSection(lastKey);
            if (spellNode == null) {
                getLogger().warning("Error saving spell data for " + lastKey);
                continue;
            }
            spellNode.set("cast_count", data.getCastCount());
            spellNode.set("last_cast", data.getLastCast());
        }
        stores.add(spellsDataFile);
    } catch (Throwable ex) {
        getLogger().warning("Error saving spell data for " + lastKey);
        ex.printStackTrace();
    }
}
Also used : SpellData(com.elmakers.mine.bukkit.api.data.SpellData) YamlDataFile(com.elmakers.mine.bukkit.data.YamlDataFile) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 3 with SpellData

use of com.elmakers.mine.bukkit.api.data.SpellData 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 4 with SpellData

use of com.elmakers.mine.bukkit.api.data.SpellData in project MagicPlugin by elBukkit.

the class Mage method onLoad.

protected void onLoad(MageData data) {
    try {
        Collection<SpellData> spellDataList = data == null ? null : data.getSpellData();
        if (spellDataList != null) {
            for (SpellData spellData : spellDataList) {
                this.spellData.put(spellData.getKey().getKey(), spellData);
            }
        }
        // Load player-specific data
        Player player = getPlayer();
        if (player != null) {
            if (controller.isInventoryBackupEnabled()) {
                if (restoreInventory != null) {
                    controller.getLogger().info("Restoring saved inventory for player " + player.getName() + " - did the server not shut down properly?");
                    if (activeWand != null) {
                        activeWand.deactivate();
                    }
                    Inventory inventory = player.getInventory();
                    for (int slot = 0; slot < restoreInventory.size(); slot++) {
                        Object item = restoreInventory.get(slot);
                        if (item instanceof ItemStack) {
                            inventory.setItem(slot, (ItemStack) item);
                        } else {
                            inventory.setItem(slot, null);
                        }
                    }
                    restoreInventory = null;
                }
                if (restoreExperience != null) {
                    player.setExp(restoreExperience);
                    restoreExperience = null;
                }
                if (restoreLevel != null) {
                    player.setLevel(restoreLevel);
                    restoreLevel = null;
                }
            }
            if (activeWand == null) {
                String welcomeWand = controller.getWelcomeWand();
                if (!gaveWelcomeWand && welcomeWand.length() > 0) {
                    gaveWelcomeWand = true;
                    Wand wand = Wand.createWand(controller, welcomeWand);
                    if (wand != null) {
                        wand.takeOwnership(player);
                        giveItem(wand.getItem());
                        controller.getLogger().info("Gave welcome wand " + wand.getName() + " to " + player.getName());
                    } else {
                        controller.getLogger().warning("Unable to give welcome wand '" + welcomeWand + "' to " + player.getName());
                    }
                }
            }
            if (activeWand != null && restoreOpenWand && !activeWand.isInventoryOpen()) {
                activeWand.openInventory();
            }
            restoreOpenWand = false;
        }
        armorUpdated();
        loading = false;
    } catch (Exception ex) {
        controller.getLogger().warning("Error finalizing player data for " + playerName + ": " + ex.getMessage());
    }
}
Also used : Player(org.bukkit.entity.Player) SpellData(com.elmakers.mine.bukkit.api.data.SpellData) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory)

Example 5 with SpellData

use of com.elmakers.mine.bukkit.api.data.SpellData 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

SpellData (com.elmakers.mine.bukkit.api.data.SpellData)7 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)4 ItemStack (org.bukkit.inventory.ItemStack)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 BrushData (com.elmakers.mine.bukkit.api.data.BrushData)2 UndoData (com.elmakers.mine.bukkit.api.data.UndoData)2 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MageData (com.elmakers.mine.bukkit.api.data.MageData)1 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)1 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 LostWand (com.elmakers.mine.bukkit.api.wand.LostWand)1 YamlDataFile (com.elmakers.mine.bukkit.data.YamlDataFile)1 Wand (com.elmakers.mine.bukkit.wand.Wand)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1