Don't save config if it fails to load.

This commit is contained in:
bloodshot 2019-08-23 18:04:04 -04:00
parent 6991d6395c
commit 760c9d93ff
3 changed files with 18 additions and 9 deletions

View File

@ -64,8 +64,9 @@ public ClaimTemplateStorage(Path path) {
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimTemplateConfig.class).bindToNew();
reload();
save();
if (reload()) {
save();
}
} catch (Exception e) {
GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize claim template data", e);
}
@ -115,14 +116,16 @@ public void save() {
}
}
public void reload() {
public boolean reload() {
try {
this.root = this.loader.load(ConfigurationOptions.defaults()
.setHeader(GriefDefenderPlugin.CONFIG_HEADER));
this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
} catch (Exception e) {
GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
return false;
}
return true;
}
public CommentedConfigurationNode getRootNode() {

View File

@ -312,8 +312,9 @@ public MessageStorage(Path path) {
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(MessageDataConfig.class).bindToNew();
reload();
save();
if (reload()) {
save();
}
} catch (Exception e) {
GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
}
@ -332,14 +333,16 @@ public void save() {
}
}
public void reload() {
public boolean reload() {
try {
this.root = this.loader.load(ConfigurationOptions.defaults());
this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
MESSAGE_DATA = this.configBase;
} catch (Exception e) {
GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
return false;
}
return true;
}
@SuppressWarnings({"unchecked", "rawtypes"})

View File

@ -58,8 +58,9 @@ public PlayerStorageData(Path path) {
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(PlayerDataConfig.class).bindToNew();
reload();
save();
if (reload()) {
save();
}
} catch (Exception e) {
GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
}
@ -83,13 +84,15 @@ public void save() {
}
}
public void reload() {
public boolean reload() {
try {
this.root = this.loader.load(ConfigurationOptions.defaults());
this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
} catch (Exception e) {
GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
return false;
}
return true;
}
public CommentedConfigurationNode getRootNode() {