From b62bb48bb6a2e7694861ffed23a5ac101abedd36 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 22 Jul 2021 18:39:59 +0100 Subject: [PATCH] Fixed loadable config reloading --- .../internal/config/json/EcoLoadableJSONConfig.java | 8 ++++++++ .../internal/config/updating/EcoConfigHandler.java | 8 ++++++++ .../internal/config/yaml/EcoLoadableYamlConfig.java | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/json/EcoLoadableJSONConfig.java b/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/json/EcoLoadableJSONConfig.java index 0ad6e36b3..6eceadfe8 100644 --- a/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/json/EcoLoadableJSONConfig.java +++ b/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/json/EcoLoadableJSONConfig.java @@ -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(); diff --git a/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/updating/EcoConfigHandler.java b/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/updating/EcoConfigHandler.java index 44491116b..e58000a0d 100644 --- a/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/updating/EcoConfigHandler.java +++ b/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/updating/EcoConfigHandler.java @@ -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; @@ -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(); + } } } } diff --git a/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/yaml/EcoLoadableYamlConfig.java b/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/yaml/EcoLoadableYamlConfig.java index 24c1a4ee1..6c3ac69b6 100644 --- a/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/yaml/EcoLoadableYamlConfig.java +++ b/eco-core/core-backend/src/main/java/com/willfp/eco/internal/config/yaml/EcoLoadableYamlConfig.java @@ -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; @@ -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();