mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2025-03-10 13:09:45 +01:00
Don't save config if it fails to load.
This commit is contained in:
parent
6991d6395c
commit
760c9d93ff
@ -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() {
|
||||
|
@ -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"})
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user