Skip to content

Commit

Permalink
add better legacy saves update error messages, empty section handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 13, 2021
1 parent e1f7198 commit 72bd9b3
Showing 1 changed file with 8 additions and 4 deletions.
Expand Up @@ -54,7 +54,7 @@ public static void updateLegacySaves() {
Debug.log("==== Update global data ====");
YamlConfiguration globalSection = saveSection.getConfigurationSection("Global");
if (globalSection.contains("Flags")) {
applyFlags(Denizen.getInstance().serverFlagMap, globalSection.getConfigurationSection("Flags"));
applyFlags("Server", Denizen.getInstance().serverFlagMap, globalSection.getConfigurationSection("Flags"));
}
if (globalSection.contains("Scripts")) {
YamlConfiguration scriptsSection = globalSection.getConfigurationSection("Scripts");
Expand Down Expand Up @@ -83,7 +83,7 @@ public static void updateLegacySaves() {
YamlConfiguration actual = subSection.getConfigurationSection(uuidString.str);
AbstractFlagTracker tracker = player.getFlagTracker();
if (actual.contains("Flags")) {
applyFlags(tracker, actual.getConfigurationSection("Flags"));
applyFlags(player.identify(), tracker, actual.getConfigurationSection("Flags"));
}
if (actual.contains("Scripts")) {
YamlConfiguration scriptsSection = actual.getConfigurationSection("Scripts");
Expand Down Expand Up @@ -118,7 +118,7 @@ public void run() {
}
AbstractFlagTracker tracker = npc.getFlagTracker();
if (actual.contains("Flags")) {
applyFlags(tracker, actual.getConfigurationSection("Flags"));
applyFlags(npc.identify(), tracker, actual.getConfigurationSection("Flags"));
}
npc.reapplyTracker(tracker);
Debug.log("==== Done late-updating NPC data ====");
Expand All @@ -130,8 +130,11 @@ public void run() {
Debug.log("==== Done updating legacy saves (except NPCs) ====");
}

public static void applyFlags(AbstractFlagTracker tracker, YamlConfiguration section) {
public static void applyFlags(String object, AbstractFlagTracker tracker, YamlConfiguration section) {
try {
if (section == null || section.getKeys(false).isEmpty()) {
return;
}
for (StringHolder flagName : section.getKeys(false)) {
if (flagName.low.endsWith("-expiration")) {
continue;
Expand All @@ -147,6 +150,7 @@ public static void applyFlags(AbstractFlagTracker tracker, YamlConfiguration sec
}
}
catch (Throwable ex) {
Debug.echoError("Error while updating legacy flags for " + object);
Debug.echoError(ex);
}
}
Expand Down

0 comments on commit 72bd9b3

Please sign in to comment.