Search in sources :

Example 1 with SaveEvent

use of com.elmakers.mine.bukkit.api.event.SaveEvent 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)

Aggregations

MageData (com.elmakers.mine.bukkit.api.data.MageData)1 SaveEvent (com.elmakers.mine.bukkit.api.event.SaveEvent)1 YamlDataFile (com.elmakers.mine.bukkit.data.YamlDataFile)1 ArrayList (java.util.ArrayList)1