ChimaeraWing.java 6.0 KB

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