Mining.java 9.7 KB

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