ChimaeraWing.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package com.gmail.nossr50.util;
  2. import com.gmail.nossr50.config.Config;
  3. import com.gmail.nossr50.datatypes.interactions.NotificationType;
  4. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  5. import com.gmail.nossr50.locale.LocaleLoader;
  6. import com.gmail.nossr50.mcMMO;
  7. import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup;
  8. import com.gmail.nossr50.util.player.NotificationManager;
  9. import com.gmail.nossr50.util.player.UserManager;
  10. import com.gmail.nossr50.util.skills.CombatUtils;
  11. import com.gmail.nossr50.util.skills.SkillUtils;
  12. import com.gmail.nossr50.util.sounds.SoundManager;
  13. import com.gmail.nossr50.util.sounds.SoundType;
  14. import org.bukkit.*;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.inventory.ItemStack;
  17. import org.bukkit.inventory.ShapelessRecipe;
  18. import org.bukkit.inventory.meta.ItemMeta;
  19. import org.bukkit.util.Vector;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. public final class ChimaeraWing {
  23. private static McMMOPlayer mcMMOPlayer;
  24. private static Location location;
  25. private ChimaeraWing() {}
  26. /**
  27. * Check for item usage.
  28. *
  29. * @param player Player whose item usage to check
  30. */
  31. public static void activationCheck(Player player) {
  32. if (!Config.getInstance().getChimaeraEnabled()) {
  33. return;
  34. }
  35. ItemStack inHand = player.getInventory().getItemInMainHand();
  36. if (!ItemUtils.isChimaeraWing(inHand)) {
  37. return;
  38. }
  39. if (!Permissions.chimaeraWing(player)) {
  40. NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
  41. return;
  42. }
  43. mcMMOPlayer = UserManager.getPlayer(player);
  44. if (mcMMOPlayer.getTeleportCommenceLocation() != null) {
  45. return;
  46. }
  47. int amount = inHand.getAmount();
  48. if (amount < Config.getInstance().getChimaeraUseCost()) {
  49. NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.NotEnough",String.valueOf(Config.getInstance().getChimaeraUseCost() - amount), "Item.ChimaeraWing.Name");
  50. return;
  51. }
  52. long lastTeleport = mcMMOPlayer.getChimeraWingLastUse();
  53. int cooldown = Config.getInstance().getChimaeraCooldown();
  54. if (cooldown > 0) {
  55. int timeRemaining = SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, cooldown, player);
  56. if (timeRemaining > 0) {
  57. NotificationManager.sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Item.Generic.Wait", String.valueOf(timeRemaining));
  58. return;
  59. }
  60. }
  61. long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
  62. int hurtCooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
  63. if (hurtCooldown > 0) {
  64. int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
  65. if (timeRemaining > 0) {
  66. NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.Injured.Wait", String.valueOf(timeRemaining));
  67. return;
  68. }
  69. }
  70. location = player.getLocation();
  71. if (Config.getInstance().getChimaeraPreventUseUnderground()) {
  72. if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
  73. player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
  74. NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.Fail");
  75. player.updateInventory();
  76. player.setVelocity(new Vector(0, 0.5D, 0));
  77. CombatUtils.dealDamage(player, Misc.getRandom().nextInt((int) (player.getHealth() - 10)));
  78. mcMMOPlayer.actualizeChimeraWingLastUse();
  79. return;
  80. }
  81. }
  82. mcMMOPlayer.actualizeTeleportCommenceLocation(player);
  83. long warmup = Config.getInstance().getChimaeraWarmup();
  84. if (warmup > 0) {
  85. NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(warmup));
  86. new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(mcMMO.p, 20 * warmup);
  87. }
  88. else {
  89. chimaeraExecuteTeleport();
  90. }
  91. }
  92. public static void chimaeraExecuteTeleport() {
  93. Player player = mcMMOPlayer.getPlayer();
  94. if (Config.getInstance().getChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) {
  95. player.teleport(player.getBedSpawnLocation());
  96. }
  97. else {
  98. Location spawnLocation = player.getWorld().getSpawnLocation();
  99. if (spawnLocation.getBlock().getType() == Material.AIR) {
  100. player.teleport(spawnLocation);
  101. }
  102. else {
  103. player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
  104. }
  105. }
  106. player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(player.getInventory().getItemInMainHand().getAmount() - Config.getInstance().getChimaeraUseCost())));
  107. player.updateInventory();
  108. mcMMOPlayer.actualizeChimeraWingLastUse();
  109. mcMMOPlayer.setTeleportCommenceLocation(null);
  110. if (Config.getInstance().getChimaeraSoundEnabled()) {
  111. SoundManager.sendSound(player, location, SoundType.CHIMAERA_WING);
  112. }
  113. NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass");
  114. }
  115. public static ItemStack getChimaeraWing(int amount) {
  116. ItemStack itemStack = new ItemStack(Config.getInstance().getChimaeraItem(), amount);
  117. ItemMeta itemMeta = itemStack.getItemMeta();
  118. itemMeta.setDisplayName(ChatColor.GOLD + LocaleLoader.getString("Item.ChimaeraWing.Name"));
  119. List<String> itemLore = new ArrayList<String>();
  120. itemLore.add("mcMMO Item");
  121. itemLore.add(LocaleLoader.getString("Item.ChimaeraWing.Lore"));
  122. itemMeta.setLore(itemLore);
  123. itemStack.setItemMeta(itemMeta);
  124. return itemStack;
  125. }
  126. public static ShapelessRecipe getChimaeraWingRecipe() {
  127. Material ingredient = Config.getInstance().getChimaeraItem();
  128. int amount = Config.getInstance().getChimaeraRecipeCost();
  129. ShapelessRecipe chimeraWing = new ShapelessRecipe(new NamespacedKey(mcMMO.p, "Chimera"), getChimaeraWing(1));
  130. chimeraWing.addIngredient(amount, ingredient);
  131. return chimeraWing;
  132. }
  133. }