diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index bf7993f4f..86312b79d 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -380,7 +380,7 @@ public class Config extends ConfigLoader { private Config(mcMMO plugin) { super(plugin, "config.yml"); - config = plugin.getConfig(); + saveIfNotExist(); xpGainMultiplier = getExperienceGainsGlobalMultiplier(); } diff --git a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java index fb2330826..97865fa02 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java @@ -9,7 +9,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import com.gmail.nossr50.mcMMO; public abstract class ConfigLoader { - + protected String fileName; protected File configFile; protected File dataFolder; protected final mcMMO plugin; @@ -17,9 +17,10 @@ public abstract class ConfigLoader { public ConfigLoader(mcMMO plugin, String fileName){ this.plugin = plugin; + this.fileName = fileName; dataFolder = plugin.getDataFolder(); configFile = new File(dataFolder, File.separator + fileName); - config = YamlConfiguration.loadConfiguration(this.configFile); + config = YamlConfiguration.loadConfiguration(configFile); } /** @@ -47,6 +48,19 @@ public abstract class ConfigLoader { } } + protected void saveIfNotExist() { + if (!configFile.exists()) { + if (plugin.getResource(fileName) != null) { + plugin.saveResource(fileName, false); + } + } + rereadFromDisk(); + } + + protected void rereadFromDisk() { + config = YamlConfiguration.loadConfiguration(configFile); + } + /** * Add the defaults to this config file. */ diff --git a/src/main/java/com/gmail/nossr50/config/SpoutConfig.java b/src/main/java/com/gmail/nossr50/config/SpoutConfig.java index 3c49eb953..68fb3b1b8 100644 --- a/src/main/java/com/gmail/nossr50/config/SpoutConfig.java +++ b/src/main/java/com/gmail/nossr50/config/SpoutConfig.java @@ -18,6 +18,7 @@ public class SpoutConfig extends ConfigLoader { public SpoutConfig(mcMMO plugin) { super(plugin, "spout.yml"); + saveIfNotExist(); } public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); } diff --git a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java index dfbe81ad6..bb4e4179c 100644 --- a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java +++ b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java @@ -43,6 +43,7 @@ public class TreasuresConfig extends ConfigLoader{ private TreasuresConfig(mcMMO plugin) { super(plugin, "treasures.yml"); + saveIfNotExist(); } @Override