Skip to content

Commit

Permalink
Fix config reloading
Browse files Browse the repository at this point in the history
Signed-off-by: DevDrizzy <[email protected]>
  • Loading branch information
DevDrizzy committed Feb 27, 2023
1 parent 3c20ceb commit f5a17d2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/java/xyz/refinedev/api/storage/YamlStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ public void readConfig() {
Object value = field.get(null);

// Load the field's value from config
if (this.config.contains(configValue.path()) && this.config.get(configValue.path()) != null) {
field.set(this, config.get(configValue.path()));
if (this.config.contains(configValue.path())) {
field.setAccessible(true);
field.set(null, config.get(configValue.path()));
field.setAccessible(false);
} else {
this.config.set(configValue.path(), value); // Add a default value from the field
}
Expand All @@ -122,12 +124,10 @@ public void readConfig() {
* Write our config values to the config
*/
public void writeConfig() {
this.clearConfig();

for ( Field field : this.fields) {
ConfigValue configValue = field.getAnnotation(ConfigValue.class);
try {
Object value = field.get(this);
Object value = field.get(null);
config.set(configValue.path(), value);
} catch (IllegalArgumentException | IllegalAccessException ex) {
LOGGER.error("[Storage] Error invoking " + field, ex);
Expand All @@ -137,6 +137,17 @@ public void writeConfig() {
this.saveConfig();
}

public void reloadConfig() {
try {
this.config.load();
} catch (IOException ex) {
LOGGER.error("[Storage] Could not load " + name + ".yml, please correct your syntax errors!");
LOGGER.error("[Storage] Error: " + ex.getMessage());
}

this.readConfig();
}

/**
* Save the YAMLConfig (Bukkit API)
*/
Expand Down

0 comments on commit f5a17d2

Please sign in to comment.