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);
}
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();
}
}
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();
}
}
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;
}
Aggregations