ChimaeraWing.java 6.7 KB

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