ChimaeraWing.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package com.gmail.nossr50.util;
  2. import com.gmail.nossr50.datatypes.interactions.NotificationType;
  3. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  4. import com.gmail.nossr50.mcMMO;
  5. import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup;
  6. import com.gmail.nossr50.util.sounds.SoundManager;
  7. import com.gmail.nossr50.util.sounds.SoundType;
  8. import org.bukkit.Location;
  9. import org.bukkit.Material;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.inventory.ItemStack;
  12. import org.bukkit.util.Vector;
  13. public final class ChimaeraWing {
  14. private final mcMMO pluginRef;
  15. private final McMMOPlayer mcMMOPlayer;
  16. private final Player player;
  17. private final Location location;
  18. public ChimaeraWing(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
  19. this.pluginRef = pluginRef;
  20. this.mcMMOPlayer = mcMMOPlayer;
  21. this.player = mcMMOPlayer.getPlayer();
  22. this.location = player.getLocation();
  23. }
  24. /**
  25. * Check for item usage.
  26. *
  27. */
  28. public void activationCheck() {
  29. ItemStack inHand = player.getInventory().getItemInMainHand();
  30. if (!pluginRef.getItemTools().isChimaeraWing(inHand)) {
  31. return;
  32. }
  33. if (!Permissions.chimaeraWing(player)) {
  34. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
  35. return;
  36. }
  37. if (mcMMOPlayer.getTeleportCommenceLocation() != null) {
  38. return;
  39. }
  40. int amount = inHand.getAmount();
  41. if (amount < pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost()) {
  42. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.NotEnough",
  43. String.valueOf(pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost() - amount), "Item.ChimaeraWing.Name");
  44. return;
  45. }
  46. long lastTeleport = mcMMOPlayer.getChimeraWingLastUse();
  47. int cooldown = pluginRef.getConfigManager().getConfigItems().getCooldown();
  48. if (cooldown > 0) {
  49. int timeRemaining = pluginRef.getSkillTools().calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, cooldown, player);
  50. if (timeRemaining > 0) {
  51. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Item.Generic.Wait", String.valueOf(timeRemaining));
  52. return;
  53. }
  54. }
  55. long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
  56. int hurtCooldown = pluginRef.getConfigManager().getConfigItems().getRecentlyHurtCooldown();
  57. if (hurtCooldown > 0) {
  58. int timeRemaining = pluginRef.getSkillTools().calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
  59. if (timeRemaining > 0) {
  60. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.Injured.Wait", String.valueOf(timeRemaining));
  61. return;
  62. }
  63. }
  64. if (pluginRef.getConfigManager().getConfigItems().isPreventUndergroundUse()) {
  65. if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
  66. player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost());
  67. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.Fail");
  68. player.updateInventory();
  69. player.setVelocity(new Vector(0, 0.5D, 0));
  70. pluginRef.getCombatTools().dealDamage(player, Misc.getRandom().nextInt((int) (player.getHealth() - 10)));
  71. mcMMOPlayer.actualizeChimeraWingLastUse();
  72. return;
  73. }
  74. }
  75. mcMMOPlayer.actualizeTeleportCommenceLocation(player);
  76. long warmup = pluginRef.getConfigManager().getConfigItems().getChimaeraWingWarmup();
  77. if (warmup > 0) {
  78. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(warmup));
  79. new ChimaeraWingWarmup(pluginRef, mcMMOPlayer).runTaskLater(pluginRef, 20 * warmup);
  80. } else {
  81. chimaeraExecuteTeleport();
  82. }
  83. }
  84. public void chimaeraExecuteTeleport() {
  85. Player player = mcMMOPlayer.getPlayer();
  86. if (pluginRef.getConfigManager().getConfigItems().doesChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) {
  87. player.teleport(player.getBedSpawnLocation());
  88. } else {
  89. Location spawnLocation = player.getWorld().getSpawnLocation();
  90. if (spawnLocation.getBlock().getType() == Material.AIR) {
  91. player.teleport(spawnLocation);
  92. } else {
  93. player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
  94. }
  95. }
  96. player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost());
  97. player.updateInventory();
  98. mcMMOPlayer.actualizeChimeraWingLastUse();
  99. mcMMOPlayer.setTeleportCommenceLocation(null);
  100. if (pluginRef.getConfigManager().getConfigItems().isChimaeraWingSoundEnabled()) {
  101. SoundManager.sendSound(player, location, SoundType.CHIMAERA_WING);
  102. }
  103. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass");
  104. }
  105. }