Search in sources :

Example 1 with YamlConfiguration

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;
}
Also used : YamlConfiguration(com.denizenscript.denizencore.utilities.YamlConfiguration) Note(com.denizenscript.denizencore.objects.notable.Note)

Example 2 with YamlConfiguration

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;
}
Also used : YamlConfiguration(com.denizenscript.denizencore.utilities.YamlConfiguration) Note(com.denizenscript.denizencore.objects.notable.Note)

Example 3 with YamlConfiguration

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;
}
Also used : YamlConfiguration(com.denizenscript.denizencore.utilities.YamlConfiguration) Note(com.denizenscript.denizencore.objects.notable.Note)

Example 4 with YamlConfiguration

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) ====");
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) TimeTag(com.denizenscript.denizencore.objects.core.TimeTag) YamlConfiguration(com.denizenscript.denizencore.utilities.YamlConfiguration) FileInputStream(java.io.FileInputStream) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) NPCTag(com.denizenscript.denizen.objects.NPCTag) AbstractFlagTracker(com.denizenscript.denizencore.flags.AbstractFlagTracker) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) UUID(java.util.UUID) File(java.io.File)

Example 5 with YamlConfiguration

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;
    }
}
Also used : YamlConfiguration(com.denizenscript.denizencore.utilities.YamlConfiguration) Note(com.denizenscript.denizencore.objects.notable.Note)

Aggregations

YamlConfiguration (com.denizenscript.denizencore.utilities.YamlConfiguration)10 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)6 Note (com.denizenscript.denizencore.objects.notable.Note)4 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)3 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)3 ItemTag (com.denizenscript.denizen.objects.ItemTag)2 AbstractFlagTracker (com.denizenscript.denizencore.flags.AbstractFlagTracker)2 Mechanism (com.denizenscript.denizencore.objects.Mechanism)2 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)2 EnchantmentTag (com.denizenscript.denizen.objects.EnchantmentTag)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 InventoryTag (com.denizenscript.denizen.objects.InventoryTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 MapTagFlagTracker (com.denizenscript.denizencore.flags.MapTagFlagTracker)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 TimeTag (com.denizenscript.denizencore.objects.core.TimeTag)1 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)1 InstantQueue (com.denizenscript.denizencore.scripts.queues.core.InstantQueue)1