use of com.denizenscript.denizencore.utilities.YamlConfiguration in project Denizen-For-Bukkit by DenizenScript.
the class CuboidTag method getSaveObject.
@Override
@Note("Cuboids")
public Object getSaveObject() {
YamlConfiguration section = new YamlConfiguration();
section.set("object", identifyFull());
section.set("flags", flagTracker.toString());
return section;
}
use of com.denizenscript.denizencore.utilities.YamlConfiguration in project Denizen-For-Bukkit by DenizenScript.
the class EllipsoidTag method getSaveObject.
@Override
@Note("Ellipsoids")
public Object getSaveObject() {
YamlConfiguration section = new YamlConfiguration();
section.set("object", identifyFull());
section.set("flags", flagTracker.toString());
return section;
}
use of com.denizenscript.denizencore.utilities.YamlConfiguration in project Denizen-For-Bukkit by DenizenScript.
the class PolygonTag method getSaveObject.
@Override
@Note("Polygons")
public Object getSaveObject() {
YamlConfiguration section = new YamlConfiguration();
section.set("object", identifyFull());
section.set("flags", flagTracker.toString());
return section;
}
use of com.denizenscript.denizencore.utilities.YamlConfiguration in project Denizen-For-Bukkit by DenizenScript.
the class LegacySavesUpdater method updateLegacySaves.
public static void updateLegacySaves() {
Debug.log("==== UPDATING LEGACY SAVES TO NEW FLAG ENGINE ====");
File savesFile = new File(Denizen.getInstance().getDataFolder(), "saves.yml");
if (!savesFile.exists()) {
Debug.echoError("Legacy update went weird: file doesn't exist?");
return;
}
YamlConfiguration saveSection;
try {
FileInputStream fis = new FileInputStream(savesFile);
String saveData = ScriptHelper.convertStreamToString(fis, false);
fis.close();
if (saveData.trim().length() == 0) {
Debug.log("Nothing to update.");
savesFile.delete();
return;
}
saveSection = YamlConfiguration.load(saveData);
if (saveSection == null) {
Debug.echoError("Something went very wrong: legacy saves file failed to load!");
return;
}
} catch (Throwable ex) {
Debug.echoError(ex);
return;
}
if (!savesFile.renameTo(new File(Denizen.getInstance().getDataFolder(), "saves.yml.bak"))) {
Debug.echoError("Legacy saves file failed to rename!");
}
if (saveSection.contains("Global")) {
Debug.log("==== Update global data ====");
YamlConfiguration globalSection = saveSection.getConfigurationSection("Global");
if (globalSection.contains("Flags")) {
applyFlags("Server", DenizenCore.serverFlagMap, globalSection.getConfigurationSection("Flags"));
}
if (globalSection.contains("Scripts")) {
YamlConfiguration scriptsSection = globalSection.getConfigurationSection("Scripts");
for (StringHolder script : scriptsSection.getKeys(false)) {
YamlConfiguration scriptSection = scriptsSection.getConfigurationSection(script.str);
if (scriptSection.contains("Cooldown Time")) {
long time = Long.parseLong(scriptSection.getString("Cooldown Time"));
TimeTag cooldown = new TimeTag(time);
DenizenCore.serverFlagMap.setFlag("__interact_cooldown." + script.low, cooldown, cooldown);
}
}
}
}
if (saveSection.contains("Players")) {
Debug.log("==== Update player data ====");
YamlConfiguration playerSection = saveSection.getConfigurationSection("Players");
for (StringHolder plPrefix : playerSection.getKeys(false)) {
YamlConfiguration subSection = playerSection.getConfigurationSection(plPrefix.str);
for (StringHolder uuidString : subSection.getKeys(false)) {
if (uuidString.str.length() != 32) {
Debug.echoError("Cannot update data for player with non-ID entry listed: " + uuidString);
continue;
}
try {
UUID id = UUID.fromString(uuidString.str.substring(0, 8) + "-" + uuidString.str.substring(8, 12) + "-" + uuidString.str.substring(12, 16) + "-" + uuidString.str.substring(16, 20) + "-" + uuidString.str.substring(20, 32));
PlayerTag player = PlayerTag.valueOf(id.toString(), CoreUtilities.errorButNoDebugContext);
if (player == null) {
Debug.echoError("Cannot update data for player with id: " + uuidString);
continue;
}
YamlConfiguration actual = subSection.getConfigurationSection(uuidString.str);
AbstractFlagTracker tracker = player.getFlagTracker();
if (actual.contains("Flags")) {
applyFlags(player.identify(), tracker, actual.getConfigurationSection("Flags"));
}
if (actual.contains("Scripts")) {
YamlConfiguration scriptsSection = actual.getConfigurationSection("Scripts");
for (StringHolder script : scriptsSection.getKeys(false)) {
YamlConfiguration scriptSection = scriptsSection.getConfigurationSection(script.str);
if (scriptSection.contains("Current Step")) {
tracker.setFlag("__interact_step." + script, new ElementTag(scriptSection.getString("Current Step")), null);
}
if (scriptSection.contains("Cooldown Time")) {
long time = Long.parseLong(scriptSection.getString("Cooldown Time"));
TimeTag cooldown = new TimeTag(time);
tracker.setFlag("__interact_cooldown." + script, cooldown, cooldown);
}
}
}
player.reapplyTracker(tracker);
} catch (Throwable ex) {
Debug.echoError("Error updating flags for player with ID " + uuidString.str);
Debug.echoError(ex);
}
}
}
}
if (saveSection.contains("NPCs")) {
final YamlConfiguration npcsSection = saveSection.getConfigurationSection("NPCs");
new BukkitRunnable() {
@Override
public void run() {
Debug.log("==== Late update NPC data ====");
for (StringHolder npcId : npcsSection.getKeys(false)) {
YamlConfiguration actual = npcsSection.getConfigurationSection(npcId.str);
NPCTag npc = NPCTag.valueOf(npcId.str, CoreUtilities.errorButNoDebugContext);
if (npc == null) {
Debug.echoError("Cannot update data for NPC with id: " + npcId.str);
continue;
}
AbstractFlagTracker tracker = npc.getFlagTracker();
if (actual.contains("Flags")) {
applyFlags(npc.identify(), tracker, actual.getConfigurationSection("Flags"));
}
npc.reapplyTracker(tracker);
Debug.log("==== Done late-updating NPC data ====");
}
}
}.runTaskLater(Denizen.getInstance(), 3);
}
Denizen.getInstance().saveSaves(true);
Debug.log("==== Done updating legacy saves (except NPCs) ====");
}
use of com.denizenscript.denizencore.utilities.YamlConfiguration in project Denizen-For-Bukkit by DenizenScript.
the class InventoryTag method getSaveObject.
@Note("Inventories")
public Object getSaveObject() {
isSaving = true;
try {
YamlConfiguration section = new YamlConfiguration();
section.set("object", "in@" + idType + PropertyParser.getPropertiesString(this));
section.set("flags", flagTracker.toString());
return section;
} finally {
isSaving = false;
}
}
Aggregations