Permalink
Browse files

Because loading a config we hadn't made yet makes sense

  • Loading branch information...
NuclearW committed May 23, 2012
1 parent 450e938 commit 83a3488d0d11bf99dd445af1b209fe9448cdf545
@@ -380,7 +380,7 @@ public boolean woodcuttingDoubleDropsDisabled() {
private Config(mcMMO plugin) {
super(plugin, "config.yml");
- config = plugin.getConfig();
+ saveIfNotExist();
xpGainMultiplier = getExperienceGainsGlobalMultiplier();
}
@@ -9,17 +9,18 @@
import com.gmail.nossr50.mcMMO;
public abstract class ConfigLoader {
-
+ protected String fileName;
protected File configFile;
protected File dataFolder;
protected final mcMMO plugin;
protected FileConfiguration config;
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 @@ private void saveConfig() {
}
}
+ 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.
*/
@@ -18,6 +18,7 @@ public static SpoutConfig getInstance() {
public SpoutConfig(mcMMO plugin) {
super(plugin, "spout.yml");
+ saveIfNotExist();
}
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
@@ -43,6 +43,7 @@ public static TreasuresConfig getInstance() {
private TreasuresConfig(mcMMO plugin) {
super(plugin, "treasures.yml");
+ saveIfNotExist();
}
@Override

0 comments on commit 83a3488

Please sign in to comment.