CustomBlockConfig.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.gmail.nossr50.config.mods;
  2. import com.gmail.nossr50.config.ConfigCollections;
  3. import com.gmail.nossr50.datatypes.mods.CustomBlock;
  4. import com.gmail.nossr50.mcMMO;
  5. import org.bukkit.Material;
  6. import org.bukkit.configuration.ConfigurationSection;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Set;
  11. public class CustomBlockConfig extends ConfigCollections {
  12. public List<Material> customExcavationBlocks = new ArrayList<>();
  13. public List<Material> customHerbalismBlocks = new ArrayList<>();
  14. public List<Material> customMiningBlocks = new ArrayList<>();
  15. public List<Material> customOres = new ArrayList<>();
  16. public List<Material> customLogs = new ArrayList<>();
  17. public List<Material> customLeaves = new ArrayList<>();
  18. public List<Material> customAbilityBlocks = new ArrayList<>();
  19. public HashMap<Material, CustomBlock> customBlockMap = new HashMap<>();
  20. private boolean needsUpdate = false;
  21. protected CustomBlockConfig(String fileName) {
  22. //super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false);
  23. super(mcMMO.p.getDataFolder().getPath() + "mods", fileName, false);
  24. loadKeys();
  25. }
  26. @Override
  27. protected void loadKeys() {
  28. loadBlocks("Excavation", customExcavationBlocks);
  29. loadBlocks("Herbalism", customHerbalismBlocks);
  30. loadBlocks("Mining", customMiningBlocks);
  31. loadBlocks("Woodcutting", null);
  32. loadBlocks("Ability_Blocks", customAbilityBlocks);
  33. if (needsUpdate) {
  34. needsUpdate = false;
  35. backup();
  36. }
  37. }
  38. private void loadBlocks(String skillType, List<Material> blockList) {
  39. if (needsUpdate) {
  40. return;
  41. }
  42. ConfigurationSection skillSection = config.getConfigurationSection(skillType);
  43. if (skillSection == null) {
  44. return;
  45. }
  46. Set<String> skillConfigSet = skillSection.getKeys(false);
  47. for (String blockName : skillConfigSet) {
  48. if (config.contains(skillType + "." + blockName + ".Drop_Item")) {
  49. needsUpdate = true;
  50. return;
  51. }
  52. String[] blockInfo = blockName.split("[|]");
  53. Material blockMaterial = Material.matchMaterial(blockInfo[0]);
  54. if (blockMaterial == null) {
  55. plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + blockInfo[0]);
  56. continue;
  57. }
  58. if (blockList != null) {
  59. blockList.add(blockMaterial);
  60. }
  61. if (skillType.equals("Ability_Blocks")) {
  62. continue;
  63. }
  64. int xp = getIntValue(skillType + "." + blockName + ".XP_Gain");
  65. int smeltingXp = 0;
  66. if (skillType.equals("Mining") && getBooleanValue(skillType + "." + blockName + ".Is_Ore")) {
  67. customOres.add(blockMaterial);
  68. smeltingXp = getIntValue(skillType + "." + blockName + ".Smelting_XP_Gain", xp / 10);
  69. } else if (skillType.equals("Woodcutting")) {
  70. if (getBooleanValue(skillType + "." + blockName + ".Is_Log")) {
  71. customLogs.add(blockMaterial);
  72. } else {
  73. customLeaves.add(blockMaterial);
  74. xp = 0; // Leaves don't grant XP
  75. }
  76. }
  77. customBlockMap.put(blockMaterial, new CustomBlock(xp, getBooleanValue(skillType + "." + blockName + ".Double_Drops_Enabled"), smeltingXp));
  78. }
  79. }
  80. }