save when new default values exist

This commit is contained in:
jascotty2 2019-09-03 18:27:25 -05:00
parent 844dc23bd1
commit e31f1ff3e4
2 changed files with 11 additions and 3 deletions

View File

@ -276,7 +276,7 @@ public class SongodaCore {
final String er = e.getMessage();
System.out.println("Connection with Songoda servers failed: " + (er.contains("URL") ? er.substring(0, er.indexOf("URL") + 3) : er));
} catch (ParseException e) {
System.out.println("Failed to parse json.");
System.out.println("Failed to parse json for " + plugin.getJavaPlugin().getName() + " update check");
}
}

View File

@ -409,7 +409,7 @@ public class Config extends ConfigSection {
public void delaySave() {
// save async even if no plugin or if plugin disabled
if (changed && saveTask == null) {
if (saveTask == null && (changed || hasNewDefaults())) {
autosaveTimer = new Timer((plugin != null ? plugin.getName() + "-ConfigSave-" : "ConfigSave-") + getFile().getName());
autosaveTimer.schedule(saveTask = new SaveTask(), autosaveInterval * 1000L);
}
@ -417,7 +417,7 @@ public class Config extends ConfigSection {
public boolean saveChanges() {
boolean saved = true;
if (changed) {
if (changed || hasNewDefaults()) {
saved = save();
}
if(saveTask != null) {
@ -430,6 +430,14 @@ public class Config extends ConfigSection {
return saved;
}
boolean hasNewDefaults() {
if (file != null && !file.exists()) return true;
for (String def : defaults.keySet()) {
if (!values.containsKey(def)) return true;
}
return false;
}
public boolean save() {
if(saveTask != null) {
//Close Threads