CustomBlocksConfig.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.gmail.nossr50.config.mods;
  2. import java.util.ArrayList;
  3. import java.util.Iterator;
  4. import java.util.List;
  5. import java.util.Set;
  6. import org.bukkit.configuration.ConfigurationSection;
  7. import org.bukkit.inventory.ItemStack;
  8. import com.gmail.nossr50.mcMMO;
  9. import com.gmail.nossr50.datatypes.mods.CustomBlock;
  10. public class CustomBlocksConfig extends ModConfigLoader{
  11. private static CustomBlocksConfig instance;
  12. public static CustomBlocksConfig getInstance() {
  13. if (instance == null) {
  14. instance = new CustomBlocksConfig(mcMMO.p);
  15. }
  16. return instance;
  17. }
  18. public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
  19. public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
  20. public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
  21. public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
  22. public List<ItemStack> customOres = new ArrayList<ItemStack>();
  23. public List<ItemStack> customLogs = new ArrayList<ItemStack>();
  24. public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
  25. public List<ItemStack> customItems = new ArrayList<ItemStack>();
  26. public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
  27. public CustomBlocksConfig(mcMMO plugin) {
  28. super(plugin, "blocks.yml");
  29. config = plugin.getBlocksConfig();
  30. }
  31. @Override
  32. public void load() {
  33. if (!configFile.exists()) {
  34. dataFolder.mkdir();
  35. plugin.saveBlocksConfig();
  36. }
  37. addDefaults();
  38. loadKeys();
  39. }
  40. @Override
  41. protected void loadKeys() {
  42. plugin.getLogger().info("Loading mcMMO blocks.yml File...");
  43. loadBlocks("Excavation", customExcavationBlocks);
  44. loadBlocks("Herbalism", customHerbalismBlocks);
  45. loadBlocks("Mining", customMiningBlocks);
  46. loadBlocks("Woodcutting", customWoodcuttingBlocks);
  47. }
  48. private void loadBlocks(String skillType, List<ItemStack> blockList) {
  49. ConfigurationSection skillSection = config.getConfigurationSection(skillType);
  50. Set<String> skillConfigSet = skillSection.getKeys(false);
  51. Iterator<String> iterator = skillConfigSet.iterator();
  52. while (iterator.hasNext()) {
  53. String blockName = iterator.next();
  54. int id = config.getInt(skillType + "." + blockName + ".ID", 0);
  55. byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
  56. int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0);
  57. boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
  58. int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0);
  59. byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0);
  60. if (id == 0) {
  61. plugin.getLogger().warning("Missing ID. This block will be skipped.");
  62. continue;
  63. }
  64. if (dropItem && dropID == 0) {
  65. plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
  66. dropItem = false;
  67. }
  68. CustomBlock block;
  69. ItemStack itemDrop;
  70. ItemStack blockItem;
  71. if (dropItem) {
  72. itemDrop = new ItemStack(dropID, 1, (short) 0, dropData);
  73. }
  74. else {
  75. itemDrop = new ItemStack(id, 1, (short) 0, data);
  76. }
  77. block = new CustomBlock(itemDrop, xp, data, id);
  78. blockItem = new ItemStack(id, 1, (short) 0, data);
  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. }