mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Updates to config loading.
This commit is contained in:
@ -385,7 +385,7 @@ public class Config extends ConfigLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
public void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveDefaultConfig();
|
||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
|
||||
@ -18,12 +19,21 @@ public abstract class ConfigLoader {
|
||||
this.plugin = plugin;
|
||||
dataFolder = plugin.getDataFolder();
|
||||
configFile = new File(dataFolder, File.separator + fileName);
|
||||
config = YamlConfiguration.loadConfiguration(this.configFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load this config file.
|
||||
*/
|
||||
protected abstract void load();
|
||||
public void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save this config file.
|
||||
@ -32,8 +42,8 @@ public abstract class ConfigLoader {
|
||||
try {
|
||||
config.save(configFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
catch (IOException ex) {
|
||||
plugin.getLogger().severe("Could not save config to " + configFile + ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +51,6 @@ public abstract class ConfigLoader {
|
||||
* Add the defaults to this config file.
|
||||
*/
|
||||
protected void addDefaults() {
|
||||
// Load from included config.yml
|
||||
config.options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
@ -27,8 +27,10 @@ public class HiddenConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
if(plugin.isInJar(fileName)) loadKeys();
|
||||
public void load() {
|
||||
if (plugin.getResource(fileName) != null) {
|
||||
loadKeys();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,7 @@ public class RepairConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
public void load() {
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ public class RepairConfig extends ConfigLoader {
|
||||
|
||||
ConfigurationSection section = config.getConfigurationSection("Repairables");
|
||||
Set<String> keys = section.getKeys(false);
|
||||
|
||||
for (String key : keys) {
|
||||
// Validate all the things!
|
||||
List<String> reason = new ArrayList<String>();
|
||||
|
@ -16,8 +16,8 @@ public class RepairConfigManager {
|
||||
|
||||
Pattern pattern = Pattern.compile("repair\\.(?:.+)\\.yml");
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
|
||||
File vanilla = new File(dataFolder, "repair.vanilla.yml");
|
||||
|
||||
if (!vanilla.exists()) {
|
||||
plugin.saveResource("repair.vanilla.yml", false);
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ public class SpoutConfig extends ConfigLoader {
|
||||
|
||||
public SpoutConfig(mcMMO plugin) {
|
||||
super(plugin, "spout.yml");
|
||||
config = plugin.getSpoutConfig();
|
||||
}
|
||||
|
||||
public boolean spoutEnabled;
|
||||
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
|
||||
public String getMenuKey() { return config.getString("Menu.Key", "KEY_M"); }
|
||||
|
||||
/* XP Bar */
|
||||
public boolean getXPBarEnabled() { return config.getBoolean("XP.Bar.Enabled", true); }
|
||||
@ -77,17 +77,6 @@ public class SpoutConfig extends ConfigLoader {
|
||||
public double getRetroHUDFishingGreen() { return config.getDouble("HUD.Retro.Colors.Fishing.GREEN", 0.3); }
|
||||
public double getRetroHUDFishingBlue() { return config.getDouble("HUD.Retro.Colors.Fishing.BLUE", 0.75); }
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveSpoutConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
plugin.getLogger().info("Loading mcMMO spout.yml File...");
|
||||
|
@ -43,18 +43,6 @@ public class TreasuresConfig extends ConfigLoader{
|
||||
|
||||
private TreasuresConfig(mcMMO plugin) {
|
||||
super(plugin, "treasures.yml");
|
||||
config = plugin.getTreasuresConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveTreasuresConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,18 +37,6 @@ public class CustomArmorConfig extends ModConfigLoader{
|
||||
|
||||
public CustomArmorConfig(mcMMO plugin) {
|
||||
super(plugin, "armor.yml");
|
||||
config = plugin.getArmorConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveArmorConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,18 +36,6 @@ public class CustomBlocksConfig extends ModConfigLoader{
|
||||
|
||||
public CustomBlocksConfig(mcMMO plugin) {
|
||||
super(plugin, "blocks.yml");
|
||||
config = plugin.getBlocksConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveBlocksConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,18 +39,6 @@ public class CustomToolsConfig extends ModConfigLoader {
|
||||
|
||||
private CustomToolsConfig(mcMMO plugin) {
|
||||
super(plugin, "tools.yml");
|
||||
config = plugin.getToolsConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!configFile.exists()) {
|
||||
dataFolder.mkdir();
|
||||
plugin.saveToolsConfig();
|
||||
}
|
||||
|
||||
addDefaults();
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user