CustomToolsConfig.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.gmail.nossr50.config.mods;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Set;
  7. import org.bukkit.configuration.ConfigurationSection;
  8. import com.gmail.nossr50.config.ConfigLoader;
  9. import com.gmail.nossr50.datatypes.mods.CustomTool;
  10. import com.gmail.nossr50.skills.repair.Repairable;
  11. import com.gmail.nossr50.skills.repair.RepairableFactory;
  12. public class CustomToolsConfig extends ConfigLoader {
  13. private static CustomToolsConfig instance;
  14. private List<Repairable> repairables;
  15. public List<Integer> customAxeIDs = new ArrayList<Integer>();
  16. public List<Integer> customBowIDs = new ArrayList<Integer>();
  17. public List<Integer> customHoeIDs = new ArrayList<Integer>();
  18. public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
  19. public List<Integer> customShovelIDs = new ArrayList<Integer>();
  20. public List<Integer> customSwordIDs = new ArrayList<Integer>();
  21. public List<Integer> customIDs = new ArrayList<Integer>();
  22. public List<CustomTool> customToolList = new ArrayList<CustomTool>();
  23. public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
  24. private CustomToolsConfig() {
  25. super("ModConfigs", "tools.yml");
  26. }
  27. public static CustomToolsConfig getInstance() {
  28. if (instance == null) {
  29. instance = new CustomToolsConfig();
  30. }
  31. return instance;
  32. }
  33. @Override
  34. protected void loadKeys() {
  35. repairables = new ArrayList<Repairable>();
  36. loadTool("Axes", customAxeIDs);
  37. loadTool("Bows", customBowIDs);
  38. loadTool("Hoes", customHoeIDs);
  39. loadTool("Pickaxes", customPickaxeIDs);
  40. loadTool("Shovels", customShovelIDs);
  41. loadTool("Swords", customSwordIDs);
  42. }
  43. private void loadTool(String toolType, List<Integer> idList) {
  44. ConfigurationSection toolSection = config.getConfigurationSection(toolType);
  45. Set<String> toolConfigSet = toolSection.getKeys(false);
  46. Iterator<String> iterator = toolConfigSet.iterator();
  47. while (iterator.hasNext()) {
  48. String toolName = iterator.next();
  49. int id = config.getInt(toolType + "." + toolName + ".ID", 0);
  50. double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
  51. boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true);
  52. int tier = config.getInt(toolType + "." + toolName + ".Tier", 1);
  53. boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
  54. int repairID = config.getInt(toolType + "." + toolName + ".Repair_Material_ID", 0);
  55. byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", 0);
  56. int repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Quantity", 0);
  57. short durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 0);
  58. if (id == 0) {
  59. plugin.getLogger().warning("Missing ID. This item will be skipped.");
  60. continue;
  61. }
  62. if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
  63. plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
  64. repairable = false;
  65. }
  66. CustomTool tool;
  67. if (repairable) {
  68. repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability));
  69. }
  70. tool = new CustomTool(tier, abilityEnabled, multiplier, durability, id);
  71. idList.add(id);
  72. customIDs.add(id);
  73. customToolList.add(tool);
  74. customTools.put(id, tool);
  75. }
  76. }
  77. public List<Repairable> getLoadedRepairables() {
  78. if(repairables == null) return new ArrayList<Repairable>();
  79. return repairables;
  80. }
  81. }