From d7bac6d08f9a9b19bd2640927b1433908b6575a8 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 5 May 2024 18:38:46 +0200 Subject: [PATCH] Fixes missing config values not loading properly until a reload --- .../blacksmith/BlacksmithPlugin.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java b/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java index 29dea58..df48a67 100644 --- a/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java +++ b/src/main/java/net/knarcraft/blacksmith/BlacksmithPlugin.java @@ -148,24 +148,19 @@ public class BlacksmithPlugin extends JavaPlugin { public void onEnable() { instance = this; - //Copy default config to disk + //Copy default config to disk, and add missing configuration values this.saveDefaultConfig(); - this.getConfig(); - this.configuration = new StargateYamlConfiguration(); - try { - this.configuration.load(new File(getDataFolder(), CONFIG_FILE_NAME)); - } catch (IOException | InvalidConfigurationException exception) { - getLogger().log(Level.SEVERE, exception.getMessage()); - } - this.configuration.options().copyDefaults(true); - - // Initialize custom configuration files + this.getConfig().options().copyDefaults(true); this.reloadConfig(); - if (this.configuration.getString("scrapper.defaults.dropItem") == null) { - ConfigHelper.migrateConfig(this.getDataFolder().getPath().replaceAll("\\\\", "/"), this.configuration); + this.saveConfig(); + + //Migrate from an earlier configuration file syntax if necessary + if (getConfiguration().getString("scrapper.defaults.dropItem") == null) { + ConfigHelper.migrateConfig(this.getDataFolder().getPath().replaceAll("\\\\", "/"), + getConfiguration()); this.reloadConfig(); } - initializeConfigurations(this.configuration); + initializeConfigurations(getConfiguration()); //Set up Vault integration if (!setUpVault()) { @@ -237,6 +232,9 @@ public class BlacksmithPlugin extends JavaPlugin { prefix = description.getPrefix(); } BlacksmithPlugin.stringFormatter = new StringFormatter(prefix, translator); + + // This reload is necessary to get values just added to the configuration for some reason + this.reload(); } /**