RemoteDetonationEventHandler.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.gmail.nossr50.skills.mining;
  2. import java.util.HashSet;
  3. import org.bukkit.Material;
  4. import org.bukkit.block.Block;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.entity.TNTPrimed;
  7. import org.bukkit.event.player.PlayerInteractEvent;
  8. import com.gmail.nossr50.mcMMO;
  9. import com.gmail.nossr50.datatypes.PlayerProfile;
  10. import com.gmail.nossr50.locale.LocaleLoader;
  11. import com.gmail.nossr50.skills.utilities.AbilityType;
  12. import com.gmail.nossr50.skills.utilities.SkillTools;
  13. import com.gmail.nossr50.util.Misc;
  14. public class RemoteDetonationEventHandler {
  15. private Player player;
  16. private PlayerProfile profile;
  17. private PlayerInteractEvent event;
  18. protected Block block;
  19. private HashSet<Byte> transparentBlocks = new HashSet<Byte>();
  20. public RemoteDetonationEventHandler(MiningManager manager, PlayerInteractEvent event) {
  21. this.player = manager.getPlayer();
  22. this.profile = manager.getProfile();
  23. this.event = event;
  24. this.block = event.getClickedBlock();
  25. }
  26. protected void targetTNT() {
  27. if (block == null || block.getType() != Material.TNT) {
  28. generateTransparentBlockList();
  29. block = player.getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
  30. }
  31. else {
  32. event.setCancelled(true); // This is the only way I know to avoid the original TNT to be triggered (in case the player is close to it)
  33. }
  34. }
  35. protected boolean cooldownOver() {
  36. if (!SkillTools.cooldownOver(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)) {
  37. player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { SkillTools.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player) }));
  38. return false;
  39. }
  40. return true;
  41. }
  42. protected void sendMessages() {
  43. Misc.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
  44. player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
  45. }
  46. protected void handleDetonation() {
  47. TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
  48. mcMMO.p.addToTNTTracker(tnt.getEntityId(), player.getName());
  49. tnt.setFuseTicks(0);
  50. block.setType(Material.AIR);
  51. }
  52. protected void setProfileData() {
  53. profile.setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
  54. profile.setAbilityInformed(AbilityType.BLAST_MINING, false);
  55. }
  56. private void generateTransparentBlockList() {
  57. for (Material material : Material.values()) {
  58. if (material.isTransparent()) {
  59. transparentBlocks.add((byte) material.getId());
  60. }
  61. }
  62. }
  63. }