package com.gmail.nossr50.config.mods; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.material.MaterialData; import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.datatypes.mods.CustomBlock; public class CustomBlockConfig extends ConfigLoader { private boolean needsUpdate = false; public List customExcavationBlocks = new ArrayList(); public List customHerbalismBlocks = new ArrayList(); public List customMiningBlocks = new ArrayList(); public List customOres = new ArrayList(); public List customLogs = new ArrayList(); public List customLeaves = new ArrayList(); public List customAbilityBlocks = new ArrayList(); public HashMap customBlockMap = new HashMap(); protected CustomBlockConfig(String fileName) { super("mods", fileName); loadKeys(); } @Override protected void loadKeys() { loadBlocks("Excavation", customExcavationBlocks); loadBlocks("Herbalism", customHerbalismBlocks); loadBlocks("Mining", customMiningBlocks); loadBlocks("Woodcutting", null); loadBlocks("Ability_Blocks", customAbilityBlocks); if (needsUpdate) { needsUpdate = false; backup(); } } private void loadBlocks(String skillType, List blockList) { if (needsUpdate) { return; } ConfigurationSection skillSection = config.getConfigurationSection(skillType); if (skillSection == null) { return; } Set skillConfigSet = skillSection.getKeys(false); for (String blockName : skillConfigSet) { if (config.contains(skillType + "." + blockName + "." + ".Drop_Item")) { needsUpdate = true; return; } String[] blockInfo = blockName.split("[|]"); Material blockMaterial = Material.matchMaterial(blockInfo[0]); if (blockMaterial == null) { plugin.getLogger().warning("Invalid material name. [" + blockInfo[0] + "] This item will be skipped. - " + blockName); continue; } if (blockInfo.length == 2) { String[] dataInfo = blockInfo[1].split("[-]"); if (dataInfo.length == 2) { byte startData = Byte.valueOf(dataInfo[0]); byte endData = Byte.valueOf(dataInfo[1]); System.out.println(blockName + " Data range; [" + startData + " - " + endData + "]"); for (byte blockData = startData; blockData < endData; blockData++) { MaterialData blockMaterialData = new MaterialData(blockMaterial, blockData); loadBlock(skillType, blockList, blockName, blockMaterialData); } return; } } byte blockData = (blockInfo.length == 2) ? Byte.valueOf(blockInfo[1]) : 0; MaterialData blockMaterialData = new MaterialData(blockMaterial, blockData); loadBlock(skillType, blockList, blockName, blockMaterialData); } } private void loadBlock(String skillType, List blockList, String blockName, MaterialData blockMaterialData) { System.out.println("Loading block: " + blockMaterialData.getItemType() + " " + blockMaterialData.getData()); if (blockList != null) { blockList.add(blockMaterialData); } if (skillType.equals("Ability_Blocks")) { return; } int xp = config.getInt(skillType + "." + blockName + ".XP_Gain"); int smeltingXp = 0; if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { customOres.add(blockMaterialData); smeltingXp = config.getInt(skillType + "." + blockName + ".Smelting_XP_Gain", xp / 10); } else if (skillType.equals("Woodcutting")) { if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { customLogs.add(blockMaterialData); } else { customLeaves.add(blockMaterialData); xp = 0; // Leaves don't grant XP } } customBlockMap.put(blockMaterialData, new CustomBlock(xp, config.getBoolean(skillType + "." + blockName + ".Double_Drops_Enabled"), smeltingXp)); } }