CustomBlocksConfig.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.gmail.nossr50.mods.config;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Set;
  5. import org.bukkit.configuration.ConfigurationSection;
  6. import org.bukkit.inventory.ItemStack;
  7. import org.bukkit.material.MaterialData;
  8. import com.gmail.nossr50.config.ConfigLoader;
  9. import com.gmail.nossr50.mods.datatypes.CustomBlock;
  10. public class CustomBlocksConfig extends ConfigLoader {
  11. private static CustomBlocksConfig instance;
  12. public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
  13. public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
  14. public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
  15. public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
  16. public List<ItemStack> customOres = new ArrayList<ItemStack>();
  17. public List<ItemStack> customLogs = new ArrayList<ItemStack>();
  18. public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
  19. public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>();
  20. public List<ItemStack> customItems = new ArrayList<ItemStack>();
  21. public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
  22. public CustomBlocksConfig() {
  23. super("ModConfigs", "blocks.yml");
  24. loadKeys();
  25. }
  26. public static CustomBlocksConfig getInstance() {
  27. if (instance == null) {
  28. instance = new CustomBlocksConfig();
  29. }
  30. return instance;
  31. }
  32. @Override
  33. protected void loadKeys() {
  34. loadBlocks("Excavation", customExcavationBlocks);
  35. loadBlocks("Herbalism", customHerbalismBlocks);
  36. loadBlocks("Mining", customMiningBlocks);
  37. loadBlocks("Woodcutting", customWoodcuttingBlocks);
  38. loadBlocks("Ability_Blocks", customAbilityBlocks);
  39. }
  40. private void loadBlocks(String skillType, List<ItemStack> blockList) {
  41. ConfigurationSection skillSection = config.getConfigurationSection(skillType);
  42. if (skillSection == null)
  43. return;
  44. Set<String> skillConfigSet = skillSection.getKeys(false);
  45. for (String blockName : skillConfigSet) {
  46. int id = config.getInt(skillType + "." + blockName + ".ID", 0);
  47. byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
  48. int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0);
  49. int tier = config.getInt(skillType + "." + blockName + ".Tier", 1);
  50. boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
  51. int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0);
  52. byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0);
  53. int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
  54. int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
  55. CustomBlock block;
  56. ItemStack itemDrop;
  57. ItemStack blockItem;
  58. if (id == 0) {
  59. plugin.getLogger().warning("Missing ID. This block will be skipped.");
  60. continue;
  61. }
  62. if (skillType.equals("Ability_Blocks")) {
  63. blockItem = (new MaterialData(id, data)).toItemStack(1);
  64. blockList.add(blockItem);
  65. continue;
  66. }
  67. if (dropItem && dropID == 0) {
  68. plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
  69. dropItem = false;
  70. }
  71. if (dropItem) {
  72. itemDrop = (new MaterialData(dropID, dropData)).toItemStack(1);
  73. }
  74. else {
  75. itemDrop = (new MaterialData(id, data)).toItemStack(1);
  76. }
  77. block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id);
  78. blockItem = (new MaterialData(id, data)).toItemStack(1);
  79. if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {
  80. customOres.add(blockItem);
  81. }
  82. else if (skillType.equals("Woodcutting")) {
  83. if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) {
  84. customLogs.add(blockItem);
  85. }
  86. else {
  87. customLeaves.add(blockItem);
  88. block.setXpGain(0); //Leaves don't grant XP
  89. }
  90. }
  91. blockList.add(blockItem);
  92. customItems.add(blockItem);
  93. customBlocks.add(block);
  94. }
  95. }
  96. }