CustomToolConfig.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.gmail.nossr50.config.mods;
  2. import com.gmail.nossr50.config.Config;
  3. import com.gmail.nossr50.datatypes.mods.CustomTool;
  4. import com.gmail.nossr50.datatypes.skills.ItemType;
  5. import com.gmail.nossr50.datatypes.skills.MaterialType;
  6. import com.gmail.nossr50.mcMMO;
  7. import com.gmail.nossr50.skills.repair.repairables.Repairable;
  8. import com.gmail.nossr50.skills.repair.repairables.RepairableFactory;
  9. import com.gmail.nossr50.util.skills.SkillUtils;
  10. import org.bukkit.Material;
  11. import org.bukkit.configuration.ConfigurationSection;
  12. import org.bukkit.inventory.ItemStack;
  13. import java.util.ArrayList;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Set;
  17. public class CustomToolConfig extends Config {
  18. public List<Material> customAxes = new ArrayList<Material>();
  19. public List<Material> customBows = new ArrayList<Material>();
  20. public List<Material> customHoes = new ArrayList<Material>();
  21. public List<Material> customPickaxes = new ArrayList<Material>();
  22. public List<Material> customShovels = new ArrayList<Material>();
  23. public List<Material> customSwords = new ArrayList<Material>();
  24. public HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
  25. public List<Repairable> repairables = new ArrayList<Repairable>();
  26. private boolean needsUpdate = false;
  27. protected CustomToolConfig(String fileName) {
  28. //super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false);
  29. super(mcMMO.p.getDataFolder().getPath() + "mods", fileName, false);
  30. loadKeys();
  31. }
  32. @Override
  33. protected void loadKeys() {
  34. loadTool("Axes", customAxes);
  35. loadTool("Bows", customBows);
  36. loadTool("Hoes", customHoes);
  37. loadTool("Pickaxes", customPickaxes);
  38. loadTool("Shovels", customShovels);
  39. loadTool("Swords", customSwords);
  40. if (needsUpdate) {
  41. needsUpdate = false;
  42. backup();
  43. }
  44. }
  45. private void loadTool(String toolType, List<Material> materialList) {
  46. if (needsUpdate) {
  47. return;
  48. }
  49. ConfigurationSection toolSection = config.getConfigurationSection(toolType);
  50. if (toolSection == null) {
  51. return;
  52. }
  53. Set<String> toolConfigSet = toolSection.getKeys(false);
  54. for (String toolName : toolConfigSet) {
  55. if (config.contains(toolType + "." + toolName + "." + ".ID")) {
  56. needsUpdate = true;
  57. return;
  58. }
  59. Material toolMaterial = Material.matchMaterial(toolName);
  60. if (toolMaterial == null) {
  61. plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + toolName);
  62. continue;
  63. }
  64. boolean repairable = getBooleanValue(toolType + "." + toolName + ".Repairable");
  65. Material repairMaterial = Material.matchMaterial(getStringValue(toolType + "." + toolName + ".Repair_Material", ""));
  66. if (repairable && (repairMaterial == null)) {
  67. plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable. - " + toolName);
  68. repairable = false;
  69. }
  70. if (repairable) {
  71. byte repairData = (byte) getIntValue(toolType + "." + toolName + ".Repair_Material_Data_Value", -1);
  72. int repairQuantity = SkillUtils.getRepairAndSalvageQuantities(new ItemStack(toolMaterial), repairMaterial, repairData);
  73. if (repairQuantity == 0) {
  74. repairQuantity = getIntValue(toolType + "." + toolName + ".Repair_Material_Quantity", 2);
  75. }
  76. String repairItemName = getStringValue(toolType + "." + toolName + ".Repair_Material_Pretty_Name");
  77. int repairMinimumLevel = getIntValue(toolType + "." + toolName + ".Repair_MinimumLevel", 0);
  78. double repairXpMultiplier = getDoubleValue(toolType + "." + toolName + ".Repair_XpMultiplier", 1);
  79. short durability = toolMaterial.getMaxDurability();
  80. if (durability == 0) {
  81. durability = (short) getIntValue(toolType + "." + toolName + ".Durability", 60);
  82. }
  83. repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, repairItemName, repairMinimumLevel, repairQuantity, durability, ItemType.TOOL, MaterialType.OTHER, repairXpMultiplier));
  84. }
  85. double multiplier = getDoubleValue(toolType + "." + toolName + ".XP_Modifier", 1.0);
  86. boolean abilityEnabled = getBooleanValue(toolType + "." + toolName + ".Ability_Enabled", true);
  87. int tier = getIntValue(toolType + "." + toolName + ".Tier", 1);
  88. CustomTool tool = new CustomTool(tier, abilityEnabled, multiplier);
  89. materialList.add(toolMaterial);
  90. customToolMap.put(toolMaterial, tool);
  91. }
  92. }
  93. }