mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-19 16:59:37 +01:00
Updates to config loading.
This commit is contained in:
parent
0fe90df01e
commit
b88e076f27
@ -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
|
||||
|
@ -389,274 +389,4 @@ public class mcMMO extends JavaPlugin {
|
||||
|
||||
getCommand("mchud").setExecutor(new MchudCommand(this));
|
||||
}
|
||||
|
||||
/*
|
||||
* Boilerplate Custom Config Stuff (Treasures)
|
||||
*/
|
||||
|
||||
private FileConfiguration treasuresConfig = null;
|
||||
private File treasuresConfigFile = null;
|
||||
|
||||
/**
|
||||
* Reload the Treasures.yml file.
|
||||
*/
|
||||
public void reloadTreasuresConfig() {
|
||||
if (treasuresConfigFile == null) {
|
||||
treasuresConfigFile = new File(getDataFolder(), "treasures.yml");
|
||||
}
|
||||
|
||||
treasuresConfig = YamlConfiguration.loadConfiguration(treasuresConfigFile);
|
||||
|
||||
if (isInJar("treasures.yml")) {
|
||||
InputStream defConfigStream = getResource("treasures.yml");
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
treasuresConfig.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Treasures config information.
|
||||
*
|
||||
* @return the configuration object for treasures.yml
|
||||
*/
|
||||
public FileConfiguration getTreasuresConfig() {
|
||||
if (treasuresConfig == null) {
|
||||
reloadTreasuresConfig();
|
||||
}
|
||||
|
||||
return treasuresConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Treasures config informtion.
|
||||
*/
|
||||
public void saveTreasuresConfig() {
|
||||
if (treasuresConfig == null || treasuresConfigFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
treasuresConfig.save(treasuresConfigFile);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Boilerplate Custom Config Stuff (Tools)
|
||||
*/
|
||||
|
||||
private FileConfiguration toolsConfig = null;
|
||||
private File toolsConfigFile = null;
|
||||
|
||||
/**
|
||||
* Reload the Tools.yml file.
|
||||
*/
|
||||
public void reloadToolsConfig() {
|
||||
if (toolsConfigFile == null) {
|
||||
toolsConfigFile = new File(modDirectory, "tools.yml");
|
||||
}
|
||||
|
||||
toolsConfig = YamlConfiguration.loadConfiguration(toolsConfigFile);
|
||||
|
||||
if (isInJar("tools.yml")) {
|
||||
InputStream defConfigStream = getResource("tools.yml");
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
toolsConfig.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Tools config information.
|
||||
*
|
||||
* @return the configuration object for tools.yml
|
||||
*/
|
||||
public FileConfiguration getToolsConfig() {
|
||||
if (toolsConfig == null) {
|
||||
reloadToolsConfig();
|
||||
}
|
||||
|
||||
return toolsConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Tools config informtion.
|
||||
*/
|
||||
public void saveToolsConfig() {
|
||||
if (toolsConfig == null || toolsConfigFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
toolsConfig.save(toolsConfigFile);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
getLogger().severe("Could not save config to " + toolsConfigFile + ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Boilerplate Custom Config Stuff (Armor)
|
||||
*/
|
||||
|
||||
private FileConfiguration armorConfig = null;
|
||||
private File armorConfigFile = null;
|
||||
|
||||
/**
|
||||
* Reload the Armor.yml file.
|
||||
*/
|
||||
public void reloadArmorConfig() {
|
||||
if (armorConfigFile == null) {
|
||||
armorConfigFile = new File(modDirectory, "armor.yml");
|
||||
}
|
||||
|
||||
armorConfig = YamlConfiguration.loadConfiguration(armorConfigFile);
|
||||
|
||||
if (isInJar("armor.yml")) {
|
||||
InputStream defConfigStream = getResource("armor.yml");
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
armorConfig.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Armor config information.
|
||||
*
|
||||
* @return the configuration object for armor.yml
|
||||
*/
|
||||
public FileConfiguration getArmorConfig() {
|
||||
if (armorConfig == null) {
|
||||
reloadArmorConfig();
|
||||
}
|
||||
|
||||
return armorConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Armor config informtion.
|
||||
*/
|
||||
public void saveArmorConfig() {
|
||||
if (armorConfig == null || armorConfigFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
armorConfig.save(armorConfigFile);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
getLogger().severe("Could not save config to " + armorConfigFile + ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Boilerplate Custom Config Stuff (Blocks)
|
||||
*/
|
||||
|
||||
private FileConfiguration blocksConfig = null;
|
||||
private File blocksConfigFile = null;
|
||||
|
||||
/**
|
||||
* Reload the Blocks.yml file.
|
||||
*/
|
||||
public void reloadBlocksConfig() {
|
||||
if (blocksConfigFile == null) {
|
||||
blocksConfigFile = new File(modDirectory, "blocks.yml");
|
||||
}
|
||||
|
||||
blocksConfig = YamlConfiguration.loadConfiguration(blocksConfigFile);
|
||||
|
||||
if (isInJar("blocks.yml")) {
|
||||
InputStream defConfigStream = getResource("blocks.yml");
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
blocksConfig.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Blocks config information.
|
||||
*
|
||||
* @return the configuration object for blocks.yml
|
||||
*/
|
||||
public FileConfiguration getBlocksConfig() {
|
||||
if (blocksConfig == null) {
|
||||
reloadBlocksConfig();
|
||||
}
|
||||
|
||||
return blocksConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Blocks config informtion.
|
||||
*/
|
||||
public void saveBlocksConfig() {
|
||||
if (blocksConfig == null || blocksConfigFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
blocksConfig.save(blocksConfigFile);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
getLogger().severe("Could not save config to " + blocksConfigFile + ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Boilerplate Custom Config Stuff (Spout)
|
||||
*/
|
||||
|
||||
private FileConfiguration spoutConfig = null;
|
||||
private File spoutConfigFile = null;
|
||||
|
||||
/**
|
||||
* Reload the Spout.yml file.
|
||||
*/
|
||||
public void reloadSpoutConfig() {
|
||||
if (spoutConfigFile == null) {
|
||||
spoutConfigFile = new File(modDirectory, "spout.yml");
|
||||
}
|
||||
|
||||
spoutConfig = YamlConfiguration.loadConfiguration(spoutConfigFile);
|
||||
|
||||
if (isInJar("spout.yml")) {
|
||||
InputStream defConfigStream = getResource("spout.yml");
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
spoutConfig.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Spout config information.
|
||||
*
|
||||
* @return the configuration object for spout.yml
|
||||
*/
|
||||
public FileConfiguration getSpoutConfig() {
|
||||
if (spoutConfig == null) {
|
||||
reloadSpoutConfig();
|
||||
}
|
||||
|
||||
return spoutConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Spout config informtion.
|
||||
*/
|
||||
public void saveSpoutConfig() {
|
||||
if (spoutConfig == null || spoutConfigFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
spoutConfig.save(spoutConfigFile);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
getLogger().severe("Could not save config to " + spoutConfigFile + ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInJar(String resource) {
|
||||
InputStream iStream = getResource(resource);
|
||||
return iStream != null;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.getspout.spoutapi.keyboard.Keyboard;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.SpoutConfig;
|
||||
import com.gmail.nossr50.datatypes.HUDmmo;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.popups.PopupMMO;
|
||||
@ -134,7 +135,7 @@ public class SpoutStuff {
|
||||
* Setup Spout config options
|
||||
*/
|
||||
public static void setupSpoutConfigs() {
|
||||
String temp = plugin.getSpoutConfig().getString("Menu.Key", "KEY_M");
|
||||
String temp = SpoutConfig.getInstance().getMenuKey();
|
||||
|
||||
for (Keyboard x : Keyboard.values()) {
|
||||
if (x.toString().equalsIgnoreCase(temp)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user