Skip to content

Commit

Permalink
Fixed loadable config reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jul 22, 2021
1 parent b238a10 commit b62bb48
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public EcoLoadableJSONConfig(@NotNull final String configName,
plugin.getConfigHandler().addConfig(this);
}

public void reloadFromFile() {
try {
init(this.configFile);
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public void createFile() {
String resourcePath = getResourcePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.willfp.eco.core.config.interfaces.LoadableConfig;
import com.willfp.eco.core.config.updating.ConfigHandler;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.eco.internal.config.json.EcoLoadableJSONConfig;
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
import com.willfp.eco.internal.config.yaml.EcoLoadableYamlConfig;
import com.willfp.eco.internal.config.yaml.EcoUpdatableYamlConfig;
import org.jetbrains.annotations.NotNull;
import org.reflections.Reflections;
Expand Down Expand Up @@ -76,6 +78,12 @@ public void updateConfigs() {
if (config instanceof EcoUpdatableYamlConfig updatableYamlConfig) {
updatableYamlConfig.update();
}
if (config instanceof EcoLoadableYamlConfig ecoLoadableYamlConfig) {
ecoLoadableYamlConfig.reloadFromFile();
}
if (config instanceof EcoLoadableJSONConfig ecoLoadableJSONConfig) {
ecoLoadableJSONConfig.reloadFromFile();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.willfp.eco.core.config.interfaces.WrappedYamlConfiguration;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -49,9 +50,19 @@ public EcoLoadableYamlConfig(@NotNull final String configName,
}

this.configFile = new File(directory, this.name);

this.getPlugin().getConfigHandler().addConfig(this);
init(YamlConfiguration.loadConfiguration(configFile));
}

public void reloadFromFile() {
try {
this.getHandle().load(this.getConfigFile());
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}

@Override
public void createFile() {
String resourcePath = getResourcePath();
Expand Down

0 comments on commit b62bb48

Please sign in to comment.