Configs rework, fixed mod config files not loading, fixed comment blocks not being copied

This commit is contained in:
bm01 2012-07-03 21:57:24 +02:00
parent 5ee440d9a5
commit b80a29ca04
12 changed files with 157 additions and 225 deletions

View File

@ -5,21 +5,26 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.mcMMO;
public class Config extends ConfigLoader {
public int xpGainMultiplier = 1;
private static Config instance;
public int xpGainMultiplier = 1;
private Config() {
super("config.yml");
xpGainMultiplier = getExperienceGainsGlobalMultiplier();
}
public static Config getInstance() {
if (instance == null) {
instance = new Config(mcMMO.p);
instance.load();
instance = new Config();
}
return instance;
}
@Override
protected void loadKeys() {}
/*
* GENERAL SETTINGS
*/
@ -370,19 +375,4 @@ public class Config extends ConfigLoader {
public double getFormulaMultiplierAxes() { return config.getDouble("Experience.Formula.Multiplier.Axes", 1.0); }
public double getFormulaMultiplierAcrobatics() { return config.getDouble("Experience.Formula.Multiplier.Acrobatics", 1.0); }
public double getFormulaMultiplierFishing() { return config.getDouble("Experience.Formula.Multiplier.Fishing", 1.0); }
/*
* CONFIG LOADING
*/
private Config(mcMMO plugin) {
super(plugin, "config.yml");
saveIfNotExist();
xpGainMultiplier = getExperienceGainsGlobalMultiplier();
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO config.yml File...");
}
}

View File

@ -1,7 +1,9 @@
package com.gmail.nossr50.config;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -9,69 +11,69 @@ import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.mcMMO;
public abstract class ConfigLoader {
protected static final mcMMO plugin = mcMMO.p;
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;
public ConfigLoader(String relativePath, String fileName){
this.fileName = fileName;
dataFolder = plugin.getDataFolder();
configFile = new File(dataFolder, File.separator + fileName);
configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName);
load();
}
public ConfigLoader(String fileName){
this.fileName = fileName;
configFile = new File(plugin.getDataFolder(), fileName);
load();
}
protected void load() {
if (!configFile.exists()) {
plugin.getLogger().info("Creating mcMMO " + fileName + " File...");
createFile();
}
else {
plugin.getLogger().info("Loading mcMMO " + fileName + " File...");
}
config = YamlConfiguration.loadConfiguration(configFile);
}
/**
* Load this config file.
*/
public void load() {
if (!configFile.exists()) {
dataFolder.mkdir();
saveConfig();
}
addDefaults();
loadKeys();
}
/**
* Save this config file.
*/
private void saveConfig() {
try {
config.save(configFile);
}
catch (IOException ex) {
plugin.getLogger().severe("Could not save config to " + configFile + ex);
}
}
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.
*/
protected void addDefaults() {
config.options().copyDefaults(true);
saveConfig();
}
/**
* Load the keys from this config file.
*/
protected abstract void loadKeys();
protected void createFile() {
if (configFile.exists()) {
return;
}
configFile.getParentFile().mkdirs();
InputStream inputStream = plugin.getResource(fileName);
if (inputStream != null) {
try {
copyStreamToFile(inputStream, configFile);
} catch (Exception e) {
e.printStackTrace();
}
}
else {
plugin.getLogger().severe("Missing ressource file: '" + configFile.getName() + "' please notify the plugin authors");
}
}
private static void copyStreamToFile(InputStream inputStream, File file) throws Exception {
OutputStream outputStream = new FileOutputStream(file);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
inputStream.close();
outputStream.close();
}
}

View File

@ -4,42 +4,32 @@ import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.mcMMO;
public class HiddenConfig extends ConfigLoader {
private static String fileName;
public class HiddenConfig {
private static HiddenConfig instance;
private static String fileName;
private static YamlConfiguration config;
private static boolean chunkletsEnabled;
public HiddenConfig(mcMMO plugin, String fileName) {
super(plugin, fileName);
public HiddenConfig(String fileName) {
HiddenConfig.fileName = fileName;
load();
}
public static HiddenConfig getInstance() {
if (instance == null) {
instance = new HiddenConfig(mcMMO.p, "hidden.yml");
instance.load();
instance = new HiddenConfig("hidden.yml");
}
return instance;
}
@Override
public void load() {
if (plugin.getResource(fileName) != null) {
loadKeys();
if (mcMMO.p.getResource(fileName) != null) {
config = YamlConfiguration.loadConfiguration(mcMMO.p.getResource(fileName));
chunkletsEnabled = config.getBoolean("Options.Chunklets", true);
}
}
@Override
protected void loadKeys() {
config = YamlConfiguration.loadConfiguration(plugin.getResource(fileName));
chunkletsEnabled = config.getBoolean("Options.Chunklets", true);
}
public boolean getChunkletsEnabled() {
return chunkletsEnabled;
}

View File

@ -1,25 +1,38 @@
package com.gmail.nossr50.config;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.HudType;
public class SpoutConfig extends ConfigLoader {
private static SpoutConfig instance;
public HudType defaultHudType;
private SpoutConfig() {
super("spout.yml");
}
public static SpoutConfig getInstance() {
if (instance == null) {
instance = new SpoutConfig(mcMMO.p);
instance.load();
instance = new SpoutConfig();
}
return instance;
}
public HudType defaultHudType;
@Override
protected void loadKeys() {
// Setup default HUD
String temp = config.getString("Spout.HUD.Default", "STANDARD");
private SpoutConfig(mcMMO plugin) {
super(plugin, "spout.yml");
saveIfNotExist();
for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(temp.toString())) {
defaultHudType = hudType;
break;
}
}
if (defaultHudType == null) {
defaultHudType = HudType.STANDARD;
}
}
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
@ -77,23 +90,4 @@ public class SpoutConfig extends ConfigLoader {
public double getRetroHUDFishingRed() { return config.getDouble("HUD.Retro.Colors.Fishing.RED", 0.3); }
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
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO spout.yml File...");
// Setup default HUD
String temp = config.getString("Spout.HUD.Default", "STANDARD");
for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(temp.toString())) {
defaultHudType = hudType;
break;
}
}
if (defaultHudType == null) {
defaultHudType = HudType.STANDARD;
}
}
}

View File

@ -11,23 +11,12 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Treasure;
public class TreasuresConfig extends ConfigLoader{
private static TreasuresConfig instance;
public static TreasuresConfig getInstance() {
if (instance == null) {
instance = new TreasuresConfig(mcMMO.p);
instance.load();
}
return instance;
}
public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>();
@ -41,15 +30,20 @@ public class TreasuresConfig extends ConfigLoader{
public List<FishingTreasure> fishingRewardsTier4 = new ArrayList<FishingTreasure>();
public List<FishingTreasure> fishingRewardsTier5 = new ArrayList<FishingTreasure>();
private TreasuresConfig(mcMMO plugin) {
super(plugin, "treasures.yml");
saveIfNotExist();
private TreasuresConfig() {
super("treasures.yml");
}
public static TreasuresConfig getInstance() {
if (instance == null) {
instance = new TreasuresConfig();
}
return instance;
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO treasures.yml File...");
Map<String, Treasure> treasures = new HashMap<String, Treasure>();
ConfigurationSection treasureSection = config.getConfigurationSection("Treasures");
Set<String> treasureConfigSet = treasureSection.getKeys(false);

View File

@ -8,40 +8,36 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomItem;
import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomArmorConfig extends ModConfigLoader{
public class CustomArmorConfig extends ConfigLoader{
private static CustomArmorConfig instance;
private List<Repairable> repairables;
public List<Integer> customBootIDs = new ArrayList<Integer>();
public List<Integer> customChestplateIDs = new ArrayList<Integer>();
public List<Integer> customHelmetIDs = new ArrayList<Integer>();
public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customArmorList = new ArrayList<CustomItem>();
public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>();
public CustomArmorConfig() {
super("ModConfigs", "armor.yml");
}
public static CustomArmorConfig getInstance() {
if (instance == null) {
instance = new CustomArmorConfig(mcMMO.p);
instance = new CustomArmorConfig();
}
return instance;
}
private List<Repairable> repairables;
public List<Integer> customBootIDs = new ArrayList<Integer>();
public List<Integer> customChestplateIDs = new ArrayList<Integer>();
public List<Integer> customHelmetIDs = new ArrayList<Integer>();
public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customArmorList = new ArrayList<CustomItem>();
public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>();
public CustomArmorConfig(mcMMO plugin) {
super(plugin, "armor.yml");
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO armor.yml File...");
repairables = new ArrayList<Repairable>();
loadArmor("Boots", customBootIDs);

View File

@ -8,41 +8,36 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlocksConfig extends ModConfigLoader{
public class CustomBlocksConfig extends ConfigLoader {
private static CustomBlocksConfig instance;
public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customOres = new ArrayList<ItemStack>();
public List<ItemStack> customLogs = new ArrayList<ItemStack>();
public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customItems = new ArrayList<ItemStack>();
public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
public CustomBlocksConfig() {
super("ModConfigs", "blocks.yml");
}
public static CustomBlocksConfig getInstance() {
if (instance == null) {
instance = new CustomBlocksConfig(mcMMO.p);
instance = new CustomBlocksConfig();
}
return instance;
}
public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customOres = new ArrayList<ItemStack>();
public List<ItemStack> customLogs = new ArrayList<ItemStack>();
public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customItems = new ArrayList<ItemStack>();
public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
public CustomBlocksConfig(mcMMO plugin) {
super(plugin, "blocks.yml");
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO blocks.yml File...");
loadBlocks("Excavation", customExcavationBlocks);
loadBlocks("Herbalism", customHerbalismBlocks);
loadBlocks("Mining", customMiningBlocks);

View File

@ -8,42 +8,38 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomToolsConfig extends ModConfigLoader {
public class CustomToolsConfig extends ConfigLoader {
private static CustomToolsConfig instance;
public static CustomToolsConfig getInstance() {
if (instance == null) {
instance = new CustomToolsConfig(mcMMO.p);
}
return instance;
}
private List<Repairable> repairables;
public List<Integer> customAxeIDs = new ArrayList<Integer>();
public List<Integer> customBowIDs = new ArrayList<Integer>();
public List<Integer> customHoeIDs = new ArrayList<Integer>();
public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
public List<Integer> customShovelIDs = new ArrayList<Integer>();
public List<Integer> customSwordIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomTool> customToolList = new ArrayList<CustomTool>();
public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
private CustomToolsConfig(mcMMO plugin) {
super(plugin, "tools.yml");
private CustomToolsConfig() {
super("ModConfigs", "tools.yml");
}
public static CustomToolsConfig getInstance() {
if (instance == null) {
instance = new CustomToolsConfig();
}
return instance;
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO tools.yml File...");
repairables = new ArrayList<Repairable>();
loadTool("Axes", customAxeIDs);

View File

@ -1,13 +0,0 @@
package com.gmail.nossr50.config.mods;
import java.io.File;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
public abstract class ModConfigLoader extends ConfigLoader{
public ModConfigLoader(mcMMO plugin, String fileName) {
super(plugin, "ModConfigs" + File.separator + fileName);
}
}

View File

@ -7,7 +7,6 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.skills.repair.RepairItemType;
import com.gmail.nossr50.skills.repair.RepairMaterialType;
@ -17,16 +16,11 @@ import com.gmail.nossr50.skills.repair.RepairableFactory;
public class RepairConfig extends ConfigLoader {
private List<Repairable> repairables;
public RepairConfig(mcMMO plugin, String fileName) {
super(plugin, fileName);
public RepairConfig(String fileName) {
super(fileName);
this.config = YamlConfiguration.loadConfiguration(this.configFile);
}
@Override
public void load() {
loadKeys();
}
@Override
protected void loadKeys() {
repairables = new ArrayList<Repairable>();

View File

@ -22,22 +22,18 @@ public class RepairConfigManager {
plugin.saveResource("repair.vanilla.yml", false);
}
for (String location : dataFolder.list()) {
if (!pattern.matcher(location).matches()) {
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
plugin.getLogger().info("Loading " + location + " repair config file...");
File file = new File(dataFolder, location);
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
RepairConfig rConfig = new RepairConfig(plugin, location);
rConfig.load();
RepairConfig rConfig = new RepairConfig(fileName);
List<Repairable> rConfigRepairables = rConfig.getLoadedRepairables();
if (rConfigRepairables != null) {

View File

@ -127,17 +127,15 @@ public class mcMMO extends JavaPlugin {
List<Repairable> repairables = new ArrayList<Repairable>();
if (configInstance.getToolModsEnabled()) {
CustomToolsConfig.getInstance().load();
repairables.addAll(CustomToolsConfig.getInstance().getLoadedRepairables());
}
if (configInstance.getArmorModsEnabled()) {
CustomArmorConfig.getInstance().load();
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
}
if (configInstance.getBlockModsEnabled()) {
CustomBlocksConfig.getInstance().load();
CustomBlocksConfig.getInstance();
}
//Load repair configs, make manager, and register them at this time