Mining.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. This file is part of mcMMO.
  3. mcMMO is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. mcMMO is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. package com.gmail.nossr50.skills;
  15. import org.bukkit.Bukkit;
  16. import org.bukkit.Location;
  17. import org.bukkit.Material;
  18. import org.bukkit.block.Block;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.getspout.spoutapi.sound.SoundEffect;
  22. import org.bukkit.enchantments.Enchantment;
  23. import org.bukkit.event.player.PlayerAnimationEvent;
  24. import com.gmail.nossr50.Users;
  25. import com.gmail.nossr50.m;
  26. import com.gmail.nossr50.mcMMO;
  27. import com.gmail.nossr50.config.LoadProperties;
  28. import com.gmail.nossr50.spout.SpoutStuff;
  29. import com.gmail.nossr50.datatypes.PlayerProfile;
  30. import com.gmail.nossr50.datatypes.SkillType;
  31. public class Mining
  32. {
  33. public static void miningDrops(Block block)
  34. {
  35. Location loc = block.getLocation();
  36. Material type = block.getType();
  37. ItemStack item = new ItemStack(type, 1);
  38. switch (type)
  39. {
  40. case COAL_ORE:
  41. item = new ItemStack(Material.COAL, 1, (byte)0, (byte)0x0);
  42. m.mcDropItem(loc, item);
  43. break;
  44. case DIAMOND_ORE:
  45. item = new ItemStack(Material.DIAMOND, 1);
  46. m.mcDropItem(loc, item);
  47. break;
  48. case GLOWING_REDSTONE_ORE:
  49. case REDSTONE_ORE:
  50. item = new ItemStack(Material.REDSTONE, 1);
  51. m.mcDropItems(loc, item, 4);
  52. m.mcRandomDropItem(loc, item, 50);
  53. break;
  54. case GLOWSTONE:
  55. item = new ItemStack(Material.GLOWSTONE_DUST, 1);
  56. m.mcDropItems(loc, item, 2);
  57. m.mcRandomDropItems(loc, item, 50, 2);
  58. break;
  59. case LAPIS_ORE:
  60. item = new ItemStack(Material.INK_SACK, 1, (byte)0, (byte)0x4);
  61. m.mcDropItems(loc, item, 4);
  62. m.mcRandomDropItems(loc, item, 50, 4);
  63. break;
  64. case STONE:
  65. item = new ItemStack(Material.COBBLESTONE, 1);
  66. m.mcDropItem(loc, item);
  67. break;
  68. default:
  69. m.mcDropItem(loc, item);
  70. break;
  71. }
  72. }
  73. public static void miningXP(Player player, Block block)
  74. {
  75. PlayerProfile PP = Users.getProfile(player);
  76. Material type = block.getType();
  77. int xp = 0;
  78. switch (type)
  79. {
  80. case COAL_ORE:
  81. xp += LoadProperties.mcoal;
  82. break;
  83. case DIAMOND_ORE:
  84. xp += LoadProperties.mdiamond;
  85. break;
  86. case ENDER_STONE:
  87. xp += LoadProperties.mendstone;
  88. break;
  89. case GLOWING_REDSTONE_ORE:
  90. case REDSTONE_ORE:
  91. xp += LoadProperties.mredstone;
  92. break;
  93. case GLOWSTONE:
  94. xp += LoadProperties.mglowstone;
  95. break;
  96. case GOLD_ORE:
  97. xp += LoadProperties.mgold;
  98. break;
  99. case IRON_ORE:
  100. xp += LoadProperties.miron;
  101. break;
  102. case LAPIS_ORE:
  103. xp += LoadProperties.mlapis;
  104. break;
  105. case MOSSY_COBBLESTONE:
  106. xp += LoadProperties.mmossstone;
  107. break;
  108. case NETHERRACK:
  109. xp += LoadProperties.mnetherrack;
  110. break;
  111. case OBSIDIAN:
  112. xp += LoadProperties.mobsidian;
  113. break;
  114. case SANDSTONE:
  115. xp += LoadProperties.msandstone;
  116. break;
  117. case STONE:
  118. xp += LoadProperties.mstone;
  119. break;
  120. }
  121. PP.addXP(SkillType.MINING, xp, player);
  122. Skills.XpCheckSkill(SkillType.MINING, player);
  123. }
  124. public static void blockProcSimulate(Block block, Player player)
  125. {
  126. //Drop natural block with Silk Touch
  127. if(player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
  128. m.mcDropItem(block.getLocation(), new ItemStack(block.getType(), 1));
  129. else
  130. miningDrops(block);
  131. }
  132. public static void blockProcCheck(Block block, Player player)
  133. {
  134. int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
  135. if(skillLevel > 1000 || (Math.random() * 1000 <= skillLevel))
  136. blockProcSimulate(block, player);
  137. }
  138. public static void miningBlockCheck(Player player, Block block, mcMMO plugin)
  139. {
  140. if(plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5)
  141. return;
  142. miningXP(player, block);
  143. if(canBeSuperBroken(block))
  144. blockProcCheck(block, player);
  145. }
  146. /*
  147. * Handling SuperBreaker stuff
  148. */
  149. public static Boolean canBeSuperBroken(Block block)
  150. {
  151. switch(block.getType()){
  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. }
  168. return false;
  169. }
  170. public static void SuperBreakerBlockCheck(Player player, Block block, mcMMO plugin)
  171. {
  172. Material type = block.getType();
  173. int tier = m.getTier(player.getItemInHand());
  174. int durabilityLoss = LoadProperties.abilityDurabilityLoss;
  175. PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
  176. switch(type)
  177. {
  178. case OBSIDIAN:
  179. if(tier < 4)
  180. return;
  181. durabilityLoss = durabilityLoss * 5; //Obsidian needs to do more damage than normal
  182. case DIAMOND_ORE:
  183. case GLOWING_REDSTONE_ORE:
  184. case GOLD_ORE:
  185. case LAPIS_ORE:
  186. case REDSTONE_ORE:
  187. if(tier < 3)
  188. return;
  189. case IRON_ORE:
  190. if(tier < 2)
  191. return;
  192. case COAL_ORE:
  193. case ENDER_STONE:
  194. case GLOWSTONE:
  195. case MOSSY_COBBLESTONE:
  196. case NETHERRACK:
  197. case SANDSTONE:
  198. case STONE:
  199. if((block.getData() == (byte) 5) || plugin.misc.blockWatchList.contains(block))
  200. return;
  201. Bukkit.getPluginManager().callEvent(armswing);
  202. Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
  203. blockProcCheck(block, player);
  204. blockProcCheck(block, player);
  205. if(!plugin.misc.blockWatchList.contains(block) && block.getData() != (byte) 5)
  206. miningXP(player, block);
  207. if(LoadProperties.spoutEnabled)
  208. SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
  209. }
  210. }
  211. }