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