Skip to content

Commit

Permalink
optimize config
Browse files Browse the repository at this point in the history
  • Loading branch information
CodedRedGIT committed Jun 19, 2024
1 parent d8245aa commit d8ae3ac
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/me/codedred/playtimes/data/CustomConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ public void reloadConfig() {

this.dataConfig = YamlConfiguration.loadConfiguration(this.dataConfigFile);

if (name == "config.yml") checkAndAddDefaults();

InputStream defConfigStream = this.plugin.getResource(name);
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(
new InputStreamReader(defConfigStream)
);
this.dataConfig.setDefaults(defConfig);
if ("config.yml".equals(name)) checkAndAddDefaults();

try (InputStream defConfigStream = this.plugin.getResource(name)) {
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(
new InputStreamReader(defConfigStream)
);
this.dataConfig.setDefaults(defConfig);
}
} catch (IOException e) {
this.plugin.getLogger()
.log(Level.SEVERE, "Error reading default config", e);
}
}

Expand Down Expand Up @@ -155,7 +159,7 @@ public FileConfiguration getConfig() {
}

public void saveConfig() {
if ((this.dataConfig == null) || (this.dataConfigFile == null)) return;
if (this.dataConfig == null || this.dataConfigFile == null) return;
try {
getConfig().save(this.dataConfigFile);
} catch (IOException ex) {
Expand Down

0 comments on commit d8ae3ac

Please sign in to comment.