SuperBreakerEventHandler.java 3.5 KB

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