Search in sources :

Example 1 with YamlDataFile

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

the class MagicController method save.

public void save(boolean asynchronous) {
    if (!initialized)
        return;
    maps.save(asynchronous);
    final List<YamlDataFile> saveData = new ArrayList<>();
    final List<MageData> saveMages = new ArrayList<>();
    if (savePlayerData && mageDataStore != null) {
        savePlayerData(saveMages);
    }
    info("Saving " + saveMages.size() + " players");
    saveSpellData(saveData);
    saveLostWands(saveData);
    if (mageDataStore != null) {
        if (asynchronous) {
            Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

                @Override
                public void run() {
                    synchronized (saveLock) {
                        for (MageData mageData : saveMages) {
                            mageDataStore.save(mageData, null);
                        }
                        for (YamlDataFile config : saveData) {
                            config.save();
                        }
                        info("Finished saving");
                    }
                }
            });
        } else {
            synchronized (saveLock) {
                for (MageData mageData : saveMages) {
                    mageDataStore.save(mageData, null);
                }
                for (YamlDataFile config : saveData) {
                    config.save();
                }
                info("Finished saving");
            }
        }
    }
    SaveEvent saveEvent = new SaveEvent(asynchronous);
    Bukkit.getPluginManager().callEvent(saveEvent);
}
Also used : SaveEvent(com.elmakers.mine.bukkit.api.event.SaveEvent) MageData(com.elmakers.mine.bukkit.api.data.MageData) YamlDataFile(com.elmakers.mine.bukkit.data.YamlDataFile) ArrayList(java.util.ArrayList)

Example 2 with YamlDataFile

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

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

the class MagicController method saveLostWands.

protected void saveLostWands(Collection<YamlDataFile> stores) {
    String lastKey = "";
    try {
        YamlDataFile lostWandsConfiguration = createDataFile(LOST_WANDS_FILE);
        for (Entry<String, LostWand> wandEntry : lostWands.entrySet()) {
            lastKey = wandEntry.getKey();
            if (lastKey == null || lastKey.length() == 0)
                continue;
            ConfigurationSection wandNode = lostWandsConfiguration.createSection(lastKey);
            if (wandNode == null) {
                getLogger().warning("Error saving lost wand data for " + lastKey);
                continue;
            }
            if (!wandEntry.getValue().isValid()) {
                getLogger().warning("Invalid lost and data for " + lastKey);
                continue;
            }
            wandEntry.getValue().save(wandNode);
        }
        stores.add(lostWandsConfiguration);
    } catch (Throwable ex) {
        getLogger().warning("Error saving lost wand data for " + lastKey);
        ex.printStackTrace();
    }
}
Also used : LostWand(com.elmakers.mine.bukkit.wand.LostWand) YamlDataFile(com.elmakers.mine.bukkit.data.YamlDataFile) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 4 with YamlDataFile

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

the class MagicController method createDataFile.

protected YamlDataFile createDataFile(String fileName) {
    File dataFile = new File(dataFolder, fileName + ".yml");
    YamlDataFile configuration = new YamlDataFile(getLogger(), dataFile);
    return configuration;
}
Also used : YamlDataFile(com.elmakers.mine.bukkit.data.YamlDataFile) YamlDataFile(com.elmakers.mine.bukkit.data.YamlDataFile) File(java.io.File)

Aggregations

YamlDataFile (com.elmakers.mine.bukkit.data.YamlDataFile)4 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 MageData (com.elmakers.mine.bukkit.api.data.MageData)1 SpellData (com.elmakers.mine.bukkit.api.data.SpellData)1 SaveEvent (com.elmakers.mine.bukkit.api.event.SaveEvent)1 LostWand (com.elmakers.mine.bukkit.wand.LostWand)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1