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

This commit is contained in:
NuclearW 2012-05-23 15:32:58 -04:00
parent 450e938092
commit 83a3488d0d
4 changed files with 19 additions and 3 deletions

View File

@ -380,7 +380,7 @@ public class Config extends ConfigLoader {
private Config(mcMMO plugin) {
super(plugin, "config.yml");
config = plugin.getConfig();
saveIfNotExist();
xpGainMultiplier = getExperienceGainsGlobalMultiplier();
}

View File

@ -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.
*/

View File

@ -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); }

View File

@ -43,6 +43,7 @@ public class TreasuresConfig extends ConfigLoader{
private TreasuresConfig(mcMMO plugin) {
super(plugin, "treasures.yml");
saveIfNotExist();
}
@Override