Mining.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package com.gmail.nossr50.skills;
  2. import org.bukkit.Bukkit;
  3. import org.bukkit.CoalType;
  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.getspout.spoutapi.sound.SoundEffect;
  10. import org.bukkit.enchantments.Enchantment;
  11. import org.bukkit.event.player.PlayerAnimationEvent;
  12. import com.gmail.nossr50.Users;
  13. import com.gmail.nossr50.m;
  14. import com.gmail.nossr50.config.LoadProperties;
  15. import com.gmail.nossr50.spout.SpoutStuff;
  16. import com.gmail.nossr50.datatypes.PlayerProfile;
  17. import com.gmail.nossr50.datatypes.SkillType;
  18. public class Mining
  19. {
  20. /**
  21. * Drop items from Mining & Blast Mining skills.
  22. *
  23. * @param block The block to process drops for
  24. */
  25. public static void miningDrops(Block block) {
  26. Location loc = block.getLocation();
  27. Material type = block.getType();
  28. ItemStack item = new ItemStack(type);
  29. switch (type) {
  30. case COAL_ORE:
  31. item = new ItemStack(Material.COAL, 1, (short) 0, CoalType.COAL.getData());
  32. m.mcDropItem(loc, item);
  33. break;
  34. case DIAMOND_ORE:
  35. item = new ItemStack(Material.DIAMOND);
  36. m.mcDropItem(loc, item);
  37. break;
  38. case GLOWING_REDSTONE_ORE:
  39. case REDSTONE_ORE:
  40. item = new ItemStack(Material.REDSTONE);
  41. m.mcDropItems(loc, item, 4);
  42. m.mcRandomDropItem(loc, item, 50);
  43. break;
  44. case GLOWSTONE:
  45. item = new ItemStack(Material.GLOWSTONE_DUST);
  46. m.mcDropItems(loc, item, 2);
  47. m.mcRandomDropItems(loc, item, 50, 2);
  48. break;
  49. case LAPIS_ORE:
  50. item = new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 0x4);
  51. m.mcDropItems(loc, item, 4);
  52. m.mcRandomDropItems(loc, item, 50, 4);
  53. break;
  54. case STONE:
  55. item = new ItemStack(Material.COBBLESTONE);
  56. m.mcDropItem(loc, item);
  57. break;
  58. default:
  59. m.mcDropItem(loc, item);
  60. break;
  61. }
  62. }
  63. /**
  64. * Award XP for Mining blocks.
  65. *
  66. * @param player The player to award XP to
  67. * @param block The block to award XP for
  68. */
  69. public static void miningXP(Player player, Block block) {
  70. PlayerProfile PP = Users.getProfile(player);
  71. Material type = block.getType();
  72. int xp = 0;
  73. switch (type) {
  74. case COAL_ORE:
  75. xp += LoadProperties.mcoal;
  76. break;
  77. case DIAMOND_ORE:
  78. xp += LoadProperties.mdiamond;
  79. break;
  80. case ENDER_STONE:
  81. xp += LoadProperties.mendstone;
  82. break;
  83. case GLOWING_REDSTONE_ORE:
  84. case REDSTONE_ORE:
  85. xp += LoadProperties.mredstone;
  86. break;
  87. case GLOWSTONE:
  88. xp += LoadProperties.mglowstone;
  89. break;
  90. case GOLD_ORE:
  91. xp += LoadProperties.mgold;
  92. break;
  93. case IRON_ORE:
  94. xp += LoadProperties.miron;
  95. break;
  96. case LAPIS_ORE:
  97. xp += LoadProperties.mlapis;
  98. break;
  99. case MOSSY_COBBLESTONE:
  100. xp += LoadProperties.mmossstone;
  101. break;
  102. case NETHERRACK:
  103. xp += LoadProperties.mnetherrack;
  104. break;
  105. case OBSIDIAN:
  106. xp += LoadProperties.mobsidian;
  107. break;
  108. case SANDSTONE:
  109. xp += LoadProperties.msandstone;
  110. break;
  111. case STONE:
  112. xp += LoadProperties.mstone;
  113. break;
  114. default:
  115. break;
  116. }
  117. PP.addXP(SkillType.MINING, xp, player);
  118. Skills.XpCheckSkill(SkillType.MINING, player);
  119. }
  120. /**
  121. * Process Mining block drops.
  122. *
  123. * @param player The player mining the block
  124. * @param block The block being broken
  125. */
  126. public static void miningBlockCheck(Player player, Block block) {
  127. if (block.hasMetadata("mcmmoPlacedBlock")) {
  128. return;
  129. }
  130. miningXP(player, block);
  131. if (canBeSuperBroken(block.getType())) {
  132. final int MAX_BONUS_LEVEL = 1000;
  133. int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
  134. if (MAX_BONUS_LEVEL > 1000 || (Math.random() * 1000 <= skillLevel)) {
  135. if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
  136. m.mcDropItem(block.getLocation(), new ItemStack(block.getType()));
  137. }
  138. else {
  139. miningDrops(block);
  140. }
  141. }
  142. }
  143. }
  144. /**
  145. * Check to see if a block is broken by Super Breaker.
  146. *
  147. * @param type The type of Block to check
  148. * @return true if the block would be broken by Super Breaker, false otherwise
  149. */
  150. public static Boolean canBeSuperBroken(Material type) {
  151. switch (type) {
  152. case COAL_ORE:
  153. case DIAMOND_ORE:
  154. case ENDER_STONE:
  155. case GLOWING_REDSTONE_ORE:
  156. case GLOWSTONE:
  157. case GOLD_ORE:
  158. case IRON_ORE:
  159. case LAPIS_ORE:
  160. case MOSSY_COBBLESTONE:
  161. case NETHERRACK:
  162. case OBSIDIAN:
  163. case REDSTONE_ORE:
  164. case SANDSTONE:
  165. case STONE:
  166. return true;
  167. default:
  168. return false;
  169. }
  170. }
  171. /**
  172. * Handle the Super Breaker ability.
  173. *
  174. * @param player The player using the ability
  175. * @param block The block being affected
  176. */
  177. public static void SuperBreakerBlockCheck(Player player, Block block) {
  178. Material type = block.getType();
  179. int tier = m.getTier(player.getItemInHand());
  180. int durabilityLoss = LoadProperties.abilityDurabilityLoss;
  181. PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
  182. switch (type) {
  183. case OBSIDIAN:
  184. if (tier < 4) {
  185. return;
  186. }
  187. durabilityLoss = durabilityLoss * 5; //Obsidian needs to do more damage than normal
  188. /* FALL THROUGH */
  189. case DIAMOND_ORE:
  190. case GLOWING_REDSTONE_ORE:
  191. case GOLD_ORE:
  192. case LAPIS_ORE:
  193. case REDSTONE_ORE:
  194. if (tier < 3) {
  195. return;
  196. }
  197. /* FALL THROUGH */
  198. case IRON_ORE:
  199. if (tier < 2) {
  200. return;
  201. }
  202. /* FALL THROUGH */
  203. case COAL_ORE:
  204. case ENDER_STONE:
  205. case GLOWSTONE:
  206. case MOSSY_COBBLESTONE:
  207. case NETHERRACK:
  208. case SANDSTONE:
  209. case STONE:
  210. if (!block.hasMetadata("mcmmoPlacedBlock")) {
  211. return;
  212. }
  213. Bukkit.getPluginManager().callEvent(armswing);
  214. Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
  215. miningBlockCheck(player, block);
  216. miningBlockCheck(player, block);
  217. if (LoadProperties.spoutEnabled) {
  218. SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
  219. }
  220. }
  221. }
  222. }