Backup old mod configs & replace with new.

This commit is contained in:
GJ 2013-10-08 13:10:09 -04:00
parent 81140824e4
commit e1bf55b077
4 changed files with 63 additions and 15 deletions

View File

@ -18,6 +18,8 @@ import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
public class CustomArmorConfig extends ConfigLoader { public class CustomArmorConfig extends ConfigLoader {
private static CustomArmorConfig instance; private static CustomArmorConfig instance;
private boolean needsUpdate = false;
private List<Repairable> repairables; private List<Repairable> repairables;
private List<Material> customBoots = new ArrayList<Material>(); private List<Material> customBoots = new ArrayList<Material>();
@ -50,10 +52,17 @@ public class CustomArmorConfig extends ConfigLoader {
protected void loadKeys() { protected void loadKeys() {
repairables = new ArrayList<Repairable>(); repairables = new ArrayList<Repairable>();
loadArmor("Boots", customBoots); while (!needsUpdate) {
loadArmor("Chestplates", customChestplates); loadArmor("Boots", customBoots);
loadArmor("Helmets", customHelmets); loadArmor("Chestplates", customChestplates);
loadArmor("Leggings", customLeggings); loadArmor("Helmets", customHelmets);
loadArmor("Leggings", customLeggings);
}
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadArmor(String armorType, List<Material> materialList) { private void loadArmor(String armorType, List<Material> materialList) {
@ -66,6 +75,11 @@ public class CustomArmorConfig extends ConfigLoader {
Set<String> armorConfigSet = armorSection.getKeys(false); Set<String> armorConfigSet = armorSection.getKeys(false);
for (String armorName : armorConfigSet) { for (String armorName : armorConfigSet) {
if (config.contains(armorType + "." + armorName + "." + ".ID")) {
needsUpdate = true;
return;
}
Material armorMaterial = Material.matchMaterial(armorName); Material armorMaterial = Material.matchMaterial(armorName);
if (armorMaterial == null) { if (armorMaterial == null) {

View File

@ -16,6 +16,8 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlockConfig extends ConfigLoader { public class CustomBlockConfig extends ConfigLoader {
private static CustomBlockConfig instance; private static CustomBlockConfig instance;
private boolean needsUpdate = false;
private List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>(); private List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>(); private List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>(); private List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>();
@ -42,11 +44,18 @@ public class CustomBlockConfig extends ConfigLoader {
@Override @Override
protected void loadKeys() { protected void loadKeys() {
loadBlocks("Excavation", customExcavationBlocks); while (!needsUpdate) {
loadBlocks("Herbalism", customHerbalismBlocks); loadBlocks("Excavation", customExcavationBlocks);
loadBlocks("Mining", customMiningBlocks); loadBlocks("Herbalism", customHerbalismBlocks);
loadBlocks("Woodcutting", customWoodcuttingBlocks); loadBlocks("Mining", customMiningBlocks);
loadBlocks("Ability_Blocks", customAbilityBlocks); loadBlocks("Woodcutting", customWoodcuttingBlocks);
loadBlocks("Ability_Blocks", customAbilityBlocks);
}
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadBlocks(String skillType, List<MaterialData> blockList) { private void loadBlocks(String skillType, List<MaterialData> blockList) {
@ -59,6 +68,11 @@ public class CustomBlockConfig extends ConfigLoader {
Set<String> skillConfigSet = skillSection.getKeys(false); Set<String> skillConfigSet = skillSection.getKeys(false);
for (String blockName : skillConfigSet) { for (String blockName : skillConfigSet) {
if (config.contains(skillType + "." + blockName + "." + ".ID")) {
needsUpdate = true;
return;
}
String[] blockInfo = blockName.split("[|]"); String[] blockInfo = blockName.split("[|]");
Material blockMaterial = Material.matchMaterial(blockInfo[0]); Material blockMaterial = Material.matchMaterial(blockInfo[0]);

View File

@ -32,6 +32,11 @@ public class CustomEntityConfig extends ConfigLoader {
@Override @Override
protected void loadKeys() { protected void loadKeys() {
if (config.getConfigurationSection("Hostile") != null) {
backup();
return;
}
for (String entityName : config.getKeys(false)) { for (String entityName : config.getKeys(false)) {
Class<?> clazz = null; Class<?> clazz = null;
String className = config.getString(entityName + ".Class", ""); String className = config.getString(entityName + ".Class", "");

View File

@ -19,6 +19,9 @@ import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
public class CustomToolConfig extends ConfigLoader { public class CustomToolConfig extends ConfigLoader {
private static CustomToolConfig instance; private static CustomToolConfig instance;
private boolean needsUpdate = false;
private List<Repairable> repairables; private List<Repairable> repairables;
private List<Material> customAxes = new ArrayList<Material>(); private List<Material> customAxes = new ArrayList<Material>();
@ -55,12 +58,19 @@ public class CustomToolConfig extends ConfigLoader {
protected void loadKeys() { protected void loadKeys() {
repairables = new ArrayList<Repairable>(); repairables = new ArrayList<Repairable>();
loadTool("Axes", customAxes); while (!needsUpdate) {
loadTool("Bows", customBows); loadTool("Axes", customAxes);
loadTool("Hoes", customHoes); loadTool("Bows", customBows);
loadTool("Pickaxes", customPickaxes); loadTool("Hoes", customHoes);
loadTool("Shovels", customShovels); loadTool("Pickaxes", customPickaxes);
loadTool("Swords", customSwords); loadTool("Shovels", customShovels);
loadTool("Swords", customSwords);
}
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadTool(String toolType, List<Material> materialList) { private void loadTool(String toolType, List<Material> materialList) {
@ -73,6 +83,11 @@ public class CustomToolConfig extends ConfigLoader {
Set<String> toolConfigSet = toolSection.getKeys(false); Set<String> toolConfigSet = toolSection.getKeys(false);
for (String toolName : toolConfigSet) { for (String toolName : toolConfigSet) {
if (config.contains(toolType + "." + toolName + "." + ".ID")) {
needsUpdate = true;
return;
}
Material toolMaterial = Material.matchMaterial(toolName); Material toolMaterial = Material.matchMaterial(toolName);
if (toolMaterial == null) { if (toolMaterial == null) {