Mining.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. package com.gmail.nossr50.skills.mining;
  2. import org.bukkit.CoalType;
  3. import org.bukkit.DyeColor;
  4. import org.bukkit.Location;
  5. import org.bukkit.Material;
  6. import org.bukkit.block.Block;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.inventory.ItemStack;
  9. import org.bukkit.material.MaterialData;
  10. import com.gmail.nossr50.config.AdvancedConfig;
  11. import com.gmail.nossr50.config.Config;
  12. import com.gmail.nossr50.datatypes.PlayerProfile;
  13. import com.gmail.nossr50.datatypes.SkillType;
  14. import com.gmail.nossr50.datatypes.mods.CustomBlock;
  15. import com.gmail.nossr50.util.Misc;
  16. import com.gmail.nossr50.util.ModChecks;
  17. import com.gmail.nossr50.util.Skills;
  18. public class Mining {
  19. private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
  20. private static Config config = Config.getInstance();
  21. public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel();
  22. public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
  23. public static boolean doubleDropsDisabled = config.miningDoubleDropsDisabled();
  24. public static final int DIAMOND_TOOL_TIER = 4;
  25. public static final int IRON_TOOL_TIER = 3;
  26. public static final int STONE_TOOL_TIER = 2;
  27. /**
  28. * Award XP for Mining blocks.
  29. *
  30. * @param player The player to award XP to
  31. * @param block The block to award XP for
  32. */
  33. protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) {
  34. int xp = 0;
  35. switch (type) {
  36. case COAL_ORE:
  37. xp += config.getMiningXPCoalOre();
  38. break;
  39. case DIAMOND_ORE:
  40. xp += config.getMiningXPDiamondOre();
  41. break;
  42. case ENDER_STONE:
  43. xp += config.getMiningXPEndStone();
  44. break;
  45. case GLOWING_REDSTONE_ORE:
  46. case REDSTONE_ORE:
  47. xp += config.getMiningXPRedstoneOre();
  48. break;
  49. case GLOWSTONE:
  50. xp += config.getMiningXPGlowstone();
  51. break;
  52. case GOLD_ORE:
  53. xp += config.getMiningXPGoldOre();
  54. break;
  55. case IRON_ORE:
  56. xp += config.getMiningXPIronOre();
  57. break;
  58. case LAPIS_ORE:
  59. xp += config.getMiningXPLapisOre();
  60. break;
  61. case MOSSY_COBBLESTONE:
  62. xp += config.getMiningXPMossyStone();
  63. break;
  64. case NETHERRACK:
  65. xp += config.getMiningXPNetherrack();
  66. break;
  67. case OBSIDIAN:
  68. xp += config.getMiningXPObsidian();
  69. break;
  70. case SANDSTONE:
  71. xp += config.getMiningXPSandstone();
  72. break;
  73. case STONE:
  74. xp += config.getMiningXPStone();
  75. break;
  76. case EMERALD_ORE:
  77. xp += config.getMiningXPEmeraldOre();
  78. break;
  79. default:
  80. if (ModChecks.isCustomMiningBlock(block)) {
  81. xp += ModChecks.getCustomBlock(block).getXpGain();
  82. }
  83. break;
  84. }
  85. Skills.xpProcessing(player, profile, SkillType.MINING, xp);
  86. }
  87. /**
  88. * Handle double drops when using Silk Touch.
  89. *
  90. * @param block The block to process drops for
  91. * @param location The location of the block
  92. * @param type The material type of the block
  93. */
  94. protected static void silkTouchDrops(Block block, Location location, Material type) {
  95. ItemStack item = new ItemStack(type);
  96. switch (type) {
  97. case ENDER_STONE:
  98. case GOLD_ORE:
  99. case IRON_ORE:
  100. case MOSSY_COBBLESTONE:
  101. case NETHERRACK:
  102. case OBSIDIAN:
  103. case SANDSTONE:
  104. miningDrops(block, location, type);
  105. break;
  106. case COAL_ORE:
  107. if (config.getCoalDoubleDropsEnabled()) {
  108. Misc.dropItem(location, item);
  109. }
  110. break;
  111. case DIAMOND_ORE:
  112. if (config.getDiamondDoubleDropsEnabled()) {
  113. Misc.dropItem(location, item);
  114. }
  115. break;
  116. case GLOWING_REDSTONE_ORE:
  117. case REDSTONE_ORE:
  118. if (config.getRedstoneDoubleDropsEnabled()) {
  119. Misc.dropItem(location, item);
  120. }
  121. break;
  122. case GLOWSTONE:
  123. if (config.getGlowstoneDoubleDropsEnabled()) {
  124. Misc.dropItem(location, item);
  125. }
  126. break;
  127. case LAPIS_ORE:
  128. if (config.getLapisDoubleDropsEnabled()) {
  129. Misc.dropItem(location, item);
  130. }
  131. break;
  132. case STONE:
  133. if (config.getStoneDoubleDropsEnabled()) {
  134. Misc.dropItem(location, item);
  135. }
  136. break;
  137. case EMERALD_ORE:
  138. if (config.getEmeraldDoubleDropsEnabled()) {
  139. Misc.dropItem(location, item);
  140. }
  141. break;
  142. default:
  143. if (ModChecks.isCustomMiningBlock(block)) {
  144. ItemStack dropItem = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  145. Misc.dropItem(location, dropItem);
  146. }
  147. break;
  148. }
  149. }
  150. /**
  151. * Drop items from Mining & Blast Mining skills.
  152. *
  153. * @param block The block to process drops for
  154. * @param location The location of the block
  155. * @param type The material type of the block
  156. */
  157. protected static void miningDrops(Block block, Location location, Material type) {
  158. ItemStack item = new ItemStack(type);
  159. switch (type) {
  160. case COAL_ORE:
  161. if (config.getCoalDoubleDropsEnabled()) {
  162. item = (new MaterialData(Material.COAL, CoalType.COAL.getData())).toItemStack(1);
  163. Misc.dropItem(location, item);
  164. }
  165. break;
  166. case DIAMOND_ORE:
  167. if (config.getDiamondDoubleDropsEnabled()) {
  168. item = new ItemStack(Material.DIAMOND);
  169. Misc.dropItem(location, item);
  170. }
  171. break;
  172. case ENDER_STONE:
  173. if (config.getEndStoneDoubleDropsEnabled()) {
  174. Misc.dropItem(location, item);
  175. }
  176. break;
  177. case GLOWING_REDSTONE_ORE:
  178. case REDSTONE_ORE:
  179. if (config.getRedstoneDoubleDropsEnabled()) {
  180. item = new ItemStack(Material.REDSTONE);
  181. Misc.dropItems(location, item, 4);
  182. Misc.randomDropItem(location, item, 50);
  183. }
  184. break;
  185. case GLOWSTONE:
  186. if (config.getGlowstoneDoubleDropsEnabled()) {
  187. item = new ItemStack(Material.GLOWSTONE_DUST);
  188. Misc.dropItems(location, item, 2);
  189. Misc.randomDropItems(location, item, 50, 2);
  190. }
  191. break;
  192. case GOLD_ORE:
  193. if (config.getGoldDoubleDropsEnabled()) {
  194. Misc.dropItem(location, item);
  195. }
  196. break;
  197. case IRON_ORE:
  198. if (config.getIronDoubleDropsEnabled()) {
  199. Misc.dropItem(location, item);
  200. }
  201. break;
  202. case LAPIS_ORE:
  203. if (config.getLapisDoubleDropsEnabled()) {
  204. try {
  205. item = (new MaterialData(Material.INK_SACK, DyeColor.BLUE.getDyeData())).toItemStack(1);
  206. }
  207. catch(Exception e) {
  208. item = (new MaterialData(Material.INK_SACK, (byte) 4)).toItemStack(1);
  209. }
  210. catch(NoSuchMethodError e) {
  211. item = (new MaterialData(Material.INK_SACK, (byte) 4)).toItemStack(1);
  212. }
  213. Misc.dropItems(location, item, 4);
  214. Misc.randomDropItems(location, item, 50, 4);
  215. }
  216. break;
  217. case MOSSY_COBBLESTONE:
  218. if (config.getMossyCobblestoneDoubleDropsEnabled()) {
  219. Misc.dropItem(location, item);
  220. }
  221. break;
  222. case NETHERRACK:
  223. if (config.getNetherrackDoubleDropsEnabled()) {
  224. Misc.dropItem(location, item);
  225. }
  226. break;
  227. case OBSIDIAN:
  228. if (config.getObsidianDoubleDropsEnabled()) {
  229. Misc.dropItem(location, item);
  230. }
  231. break;
  232. case SANDSTONE:
  233. if (config.getSandstoneDoubleDropsEnabled()) {
  234. Misc.dropItem(location, item);
  235. }
  236. break;
  237. case STONE:
  238. if (config.getStoneDoubleDropsEnabled()) {
  239. item = new ItemStack(Material.COBBLESTONE);
  240. Misc.dropItem(location, item);
  241. }
  242. break;
  243. case EMERALD_ORE:
  244. if (config.getEmeraldDoubleDropsEnabled()) {
  245. item = new ItemStack(Material.EMERALD);
  246. Misc.dropItem(location, item);
  247. }
  248. break;
  249. default:
  250. if (ModChecks.isCustomMiningBlock(block)) {
  251. CustomBlock customBlock = ModChecks.getCustomBlock(block);
  252. int minimumDropAmount = customBlock.getMinimumDropAmount();
  253. int maximumDropAmount = customBlock.getMaximumDropAmount();
  254. item = ModChecks.getCustomBlock(block).getItemDrop();
  255. if (minimumDropAmount != maximumDropAmount) {
  256. Misc.dropItems(location, item, minimumDropAmount);
  257. Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
  258. }
  259. else {
  260. Misc.dropItems(location, item, minimumDropAmount);
  261. }
  262. }
  263. break;
  264. }
  265. }
  266. }