package com.gmail.nossr50.config.mods; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.mods.CustomBlock; public class CustomBlocksConfig extends ModConfigLoader{ private static CustomBlocksConfig instance; public static CustomBlocksConfig getInstance() { if (instance == null) { instance = new CustomBlocksConfig(mcMMO.p); } return instance; } public List customExcavationBlocks = new ArrayList(); public List customHerbalismBlocks = new ArrayList(); public List customMiningBlocks = new ArrayList(); public List customWoodcuttingBlocks = new ArrayList(); public List customOres = new ArrayList(); public List customLogs = new ArrayList(); public List customLeaves = new ArrayList(); public List customAbilityBlocks = new ArrayList(); public List customItems = new ArrayList(); public List customBlocks = new ArrayList(); 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); loadBlocks("Woodcutting", customWoodcuttingBlocks); loadBlocks("Ability_Blocks", customAbilityBlocks); } private void loadBlocks(String skillType, List blockList) { ConfigurationSection skillSection = config.getConfigurationSection(skillType); Set skillConfigSet = skillSection.getKeys(false); Iterator iterator = skillConfigSet.iterator(); while (iterator.hasNext()) { String blockName = iterator.next(); int id = config.getInt(skillType + "." + blockName + ".ID", 0); byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0); int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0); int tier = config.getInt(skillType + "." + blockName + ".Tier", 1); boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false); int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0); byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0); int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1); int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1); CustomBlock block; ItemStack itemDrop; ItemStack blockItem; if (id == 0) { plugin.getLogger().warning("Missing ID. This block will be skipped."); continue; } if (skillType == "Ability_Blocks") { blockItem = new ItemStack(id, 1, (short) 0, data); blockList.add(blockItem); continue; } if (dropItem && dropID == 0) { plugin.getLogger().warning("Incomplete item drop information. This block will drop itself."); dropItem = false; } if (dropItem) { itemDrop = new ItemStack(dropID, 1, (short) 0, dropData); } else { itemDrop = new ItemStack(id, 1, (short) 0, data); } block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id); blockItem = new ItemStack(id, 1, (short) 0, data); if (skillType == "Mining" && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { customOres.add(blockItem); } else if (skillType == "Woodcutting") { if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { customLogs.add(blockItem); } else { customLeaves.add(blockItem); block.setXpGain(0); //Leaves don't grant XP } } blockList.add(blockItem); customItems.add(blockItem); customBlocks.add(block); } } }