SuperBreakerEventHandler.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.gmail.nossr50.skills.mining;
  2. import org.bukkit.Material;
  3. import org.bukkit.Sound;
  4. import org.bukkit.block.Block;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.inventory.ItemStack;
  7. import com.gmail.nossr50.mcMMO;
  8. import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
  9. import com.gmail.nossr50.mods.ModChecks;
  10. import com.gmail.nossr50.skills.utilities.SkillTools;
  11. import com.gmail.nossr50.util.Misc;
  12. public class SuperBreakerEventHandler {
  13. private MiningManager manager;
  14. private Player player;
  15. private Block block;
  16. private Material blockType;
  17. private boolean customBlock;
  18. private ItemStack heldItem;
  19. private int tier;
  20. private int durabilityLoss;
  21. private FakePlayerAnimationEvent armswing;
  22. protected SuperBreakerEventHandler (MiningManager manager, Block block) {
  23. this.manager = manager;
  24. this.player = manager.getPlayer();
  25. this.block = block;
  26. this.blockType = block.getType();
  27. this.customBlock = ModChecks.isCustomMiningBlock(block);
  28. this.heldItem = player.getItemInHand();
  29. this.tier = Misc.getTier(heldItem);
  30. this.armswing = new FakePlayerAnimationEvent(player);
  31. calculateDurabilityLoss();
  32. }
  33. protected void callFakeArmswing() {
  34. mcMMO.p.getServer().getPluginManager().callEvent(armswing);
  35. }
  36. protected void processDurabilityLoss() {
  37. SkillTools.abilityDurabilityLoss(heldItem, durabilityLoss);
  38. }
  39. protected void processDropsAndXP() {
  40. manager.miningBlockCheck(block);
  41. }
  42. protected void playSound() {
  43. player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
  44. }
  45. /**
  46. * Check for the proper tier of item for use with Super Breaker.
  47. *
  48. * @return True if the item is the required tier or higher, false otherwise
  49. */
  50. protected boolean tierCheck() {
  51. if (customBlock) {
  52. if (ModChecks.getCustomBlock(block).getTier() < tier) {
  53. return false;
  54. }
  55. return true;
  56. }
  57. switch (blockType) {
  58. case OBSIDIAN:
  59. if (tier < Mining.DIAMOND_TOOL_TIER) {
  60. return false;
  61. }
  62. /* FALL THROUGH */
  63. case DIAMOND_ORE:
  64. case GLOWING_REDSTONE_ORE:
  65. case GOLD_ORE:
  66. case LAPIS_ORE:
  67. case REDSTONE_ORE:
  68. case EMERALD_ORE:
  69. if (tier < Mining.IRON_TOOL_TIER) {
  70. return false;
  71. }
  72. /* FALL THROUGH */
  73. case IRON_ORE:
  74. if (tier < Mining.STONE_TOOL_TIER) {
  75. return false;
  76. }
  77. /* FALL THROUGH */
  78. case COAL_ORE:
  79. case ENDER_STONE:
  80. case GLOWSTONE:
  81. case MOSSY_COBBLESTONE:
  82. case NETHERRACK:
  83. case SANDSTONE:
  84. case STONE:
  85. return true;
  86. default:
  87. return false;
  88. }
  89. }
  90. private void calculateDurabilityLoss() {
  91. this.durabilityLoss = Misc.toolDurabilityLoss;
  92. if (blockType.equals(Material.OBSIDIAN)) {
  93. durabilityLoss = durabilityLoss * 5;
  94. }
  95. }
  96. }