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.inventory.ItemStack; import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.RepairItemType; import com.gmail.nossr50.skills.repair.RepairMaterialType; import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.RepairableFactory; public class CustomToolConfig extends ConfigLoader { private static CustomToolConfig instance; private List repairables; public List customAxes = new ArrayList(); public List customBows = new ArrayList(); public List customHoes = new ArrayList(); public List customPickaxes = new ArrayList(); public List customShovels = new ArrayList(); public List customSwords = new ArrayList(); public List customTool = new ArrayList(); public HashMap customToolMap = new HashMap(); private CustomToolConfig() { super("ModConfigs", "tools.yml"); loadKeys(); } public static CustomToolConfig getInstance() { if (instance == null) { instance = new CustomToolConfig(); } return instance; } public List getLoadedRepairables() { if (repairables == null) { return new ArrayList(); } return repairables; } @Override protected void loadKeys() { repairables = new ArrayList(); loadTool("Axes", customAxes); loadTool("Bows", customBows); loadTool("Hoes", customHoes); loadTool("Pickaxes", customPickaxes); loadTool("Shovels", customShovels); loadTool("Swords", customSwords); } private void loadTool(String toolType, List materialList) { ConfigurationSection toolSection = config.getConfigurationSection(toolType); if (toolSection == null) { return; } Set toolConfigSet = toolSection.getKeys(false); for (String toolName : toolConfigSet) { Material toolMaterial = Material.matchMaterial(toolName); if (toolMaterial == null) { plugin.getLogger().warning("Invalid material name. This item will be skipped."); continue; } boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable"); Material repairMaterial = Material.matchMaterial(config.getString(toolType + "." + toolName + ".Repair_Material", "")); if (repairMaterial == null) { plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable."); repairable = false; } if (repairable) { byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", -1); int repairQuantity = Repair.getRepairAndSalvageQuantities(new ItemStack(toolMaterial), repairMaterial, repairData); if (repairQuantity == 0) { repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Quantity", 2); } short durability = toolMaterial.getMaxDurability(); if (durability == 0) { durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 60); } repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, 0, repairQuantity, durability, RepairItemType.TOOL, RepairMaterialType.OTHER, 1.0)); } double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0); boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true); int tier = config.getInt(toolType + "." + toolName + ".Tier", 1); CustomTool tool = new CustomTool(tier, abilityEnabled, multiplier); materialList.add(toolMaterial); customTool.add(toolMaterial); customToolMap.put(toolMaterial, tool); } } }