mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-27 12:35:12 +01:00
save when new default values exist
This commit is contained in:
parent
844dc23bd1
commit
e31f1ff3e4
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user