2013-02-15 16:36:14 +01:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.config.Config;
|
2019-01-14 07:09:54 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
2013-03-22 00:38:15 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-02-15 16:36:14 +01:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2018-07-26 02:29:40 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-22 00:38:15 +01:00
|
|
|
import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup;
|
2019-01-14 07:09:54 +01:00
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2013-03-14 22:31:44 +01:00
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
2019-01-13 04:08:54 +01:00
|
|
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
|
|
|
import com.gmail.nossr50.util.sounds.SoundType;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.NamespacedKey;
|
2018-07-26 02:29:40 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.ShapelessRecipe;
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2013-02-15 16:36:14 +01:00
|
|
|
|
|
|
|
public final class ChimaeraWing {
|
2013-03-22 00:38:15 +01:00
|
|
|
private static McMMOPlayer mcMMOPlayer;
|
|
|
|
private static Location location;
|
|
|
|
|
2013-02-15 16:36:14 +01:00
|
|
|
private ChimaeraWing() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for item usage.
|
|
|
|
*
|
|
|
|
* @param player Player whose item usage to check
|
|
|
|
*/
|
|
|
|
public static void activationCheck(Player player) {
|
2013-05-21 17:41:39 +02:00
|
|
|
if (!Config.getInstance().getChimaeraEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
ItemStack inHand = player.getInventory().getItemInMainHand();
|
2013-02-15 16:36:14 +01:00
|
|
|
|
2013-05-21 17:41:39 +02:00
|
|
|
if (!ItemUtils.isChimaeraWing(inHand)) {
|
2013-02-15 16:36:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-21 21:48:42 +02:00
|
|
|
if (!Permissions.chimaeraWing(player)) {
|
2019-01-14 07:09:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
|
2013-04-21 21:48:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-22 00:38:15 +01:00
|
|
|
mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
|
2019-04-13 00:17:05 +02:00
|
|
|
//Not loaded
|
|
|
|
if(mcMMOPlayer == null)
|
|
|
|
return;
|
|
|
|
|
2013-04-21 21:50:08 +02:00
|
|
|
if (mcMMOPlayer.getTeleportCommenceLocation() != null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-22 00:38:15 +01:00
|
|
|
|
2013-05-21 17:41:39 +02:00
|
|
|
int amount = inHand.getAmount();
|
|
|
|
|
|
|
|
if (amount < Config.getInstance().getChimaeraUseCost()) {
|
2019-01-14 07:09:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.NotEnough",String.valueOf(Config.getInstance().getChimaeraUseCost() - amount), "Item.ChimaeraWing.Name");
|
2013-04-21 21:50:08 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-02-15 16:36:14 +01:00
|
|
|
|
2013-07-24 19:50:33 +02:00
|
|
|
long lastTeleport = mcMMOPlayer.getChimeraWingLastUse();
|
2013-05-21 17:41:39 +02:00
|
|
|
int cooldown = Config.getInstance().getChimaeraCooldown();
|
2013-04-10 17:08:27 +02:00
|
|
|
|
2014-05-11 15:14:46 +02:00
|
|
|
if (cooldown > 0) {
|
2013-05-21 17:41:39 +02:00
|
|
|
int timeRemaining = SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, cooldown, player);
|
|
|
|
|
|
|
|
if (timeRemaining > 0) {
|
2019-01-14 07:09:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.ABILITY_COOLDOWN, "Item.Generic.Wait", String.valueOf(timeRemaining));
|
2013-05-21 17:41:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-04-21 21:50:08 +02:00
|
|
|
}
|
2013-03-14 22:24:38 +01:00
|
|
|
|
2013-05-21 17:41:39 +02:00
|
|
|
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
|
|
|
int hurtCooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
|
|
|
|
|
|
|
|
if (hurtCooldown > 0) {
|
|
|
|
int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
|
|
|
|
|
|
|
|
if (timeRemaining > 0) {
|
2019-01-14 07:09:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.Injured.Wait", String.valueOf(timeRemaining));
|
2013-05-21 17:41:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-04-21 21:50:08 +02:00
|
|
|
}
|
2013-03-14 22:24:38 +01:00
|
|
|
|
2013-05-21 17:41:39 +02:00
|
|
|
location = player.getLocation();
|
|
|
|
|
2013-04-21 21:50:08 +02:00
|
|
|
if (Config.getInstance().getChimaeraPreventUseUnderground()) {
|
|
|
|
if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
|
2016-03-11 15:20:23 +01:00
|
|
|
player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
|
2019-01-14 07:09:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.Fail");
|
2013-05-19 22:13:19 +02:00
|
|
|
player.updateInventory();
|
2013-04-21 21:50:08 +02:00
|
|
|
player.setVelocity(new Vector(0, 0.5D, 0));
|
2013-07-11 18:43:36 +02:00
|
|
|
CombatUtils.dealDamage(player, Misc.getRandom().nextInt((int) (player.getHealth() - 10)));
|
2013-07-24 19:50:33 +02:00
|
|
|
mcMMOPlayer.actualizeChimeraWingLastUse();
|
2013-04-21 21:50:08 +02:00
|
|
|
return;
|
2013-03-14 22:24:38 +01:00
|
|
|
}
|
2013-04-21 21:50:08 +02:00
|
|
|
}
|
2013-04-04 15:59:10 +02:00
|
|
|
|
2013-04-21 21:50:08 +02:00
|
|
|
mcMMOPlayer.actualizeTeleportCommenceLocation(player);
|
2013-02-15 16:36:14 +01:00
|
|
|
|
2013-04-21 21:50:08 +02:00
|
|
|
long warmup = Config.getInstance().getChimaeraWarmup();
|
2013-04-04 15:59:10 +02:00
|
|
|
|
2013-04-21 21:50:08 +02:00
|
|
|
if (warmup > 0) {
|
2019-01-14 07:09:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(warmup));
|
2013-04-21 21:50:08 +02:00
|
|
|
new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(mcMMO.p, 20 * warmup);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
chimaeraExecuteTeleport();
|
2013-03-22 00:38:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void chimaeraExecuteTeleport() {
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
|
2014-12-18 23:04:38 +01:00
|
|
|
if (Config.getInstance().getChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) {
|
2013-03-22 00:38:15 +01:00
|
|
|
player.teleport(player.getBedSpawnLocation());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Location spawnLocation = player.getWorld().getSpawnLocation();
|
|
|
|
if (spawnLocation.getBlock().getType() == Material.AIR) {
|
|
|
|
player.teleport(spawnLocation);
|
2013-03-14 22:24:38 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-03-22 00:38:15 +01:00
|
|
|
player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
|
2013-02-15 16:36:14 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-22 00:38:15 +01:00
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(player.getInventory().getItemInMainHand().getAmount() - Config.getInstance().getChimaeraUseCost())));
|
2013-05-19 22:13:19 +02:00
|
|
|
player.updateInventory();
|
2013-07-24 19:50:33 +02:00
|
|
|
mcMMOPlayer.actualizeChimeraWingLastUse();
|
2013-07-30 21:20:18 +02:00
|
|
|
mcMMOPlayer.setTeleportCommenceLocation(null);
|
2013-10-31 14:03:29 +01:00
|
|
|
|
|
|
|
if (Config.getInstance().getChimaeraSoundEnabled()) {
|
2019-01-13 04:08:54 +01:00
|
|
|
SoundManager.sendSound(player, location, SoundType.CHIMAERA_WING);
|
2013-10-31 14:03:29 +01:00
|
|
|
}
|
2014-05-11 15:14:46 +02:00
|
|
|
|
2019-01-14 07:09:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass");
|
2013-02-15 16:36:14 +01:00
|
|
|
}
|
2013-03-08 21:46:05 +01:00
|
|
|
|
|
|
|
public static ItemStack getChimaeraWing(int amount) {
|
2013-09-13 15:12:21 +02:00
|
|
|
ItemStack itemStack = new ItemStack(Config.getInstance().getChimaeraItem(), amount);
|
2013-04-04 21:35:09 +02:00
|
|
|
|
2013-03-08 21:46:05 +01:00
|
|
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
2020-07-13 21:31:30 +02:00
|
|
|
//noinspection ConstantConditions
|
2013-05-02 21:02:12 +02:00
|
|
|
itemMeta.setDisplayName(ChatColor.GOLD + LocaleLoader.getString("Item.ChimaeraWing.Name"));
|
2013-04-04 21:35:09 +02:00
|
|
|
|
2020-07-13 21:31:30 +02:00
|
|
|
List<String> itemLore = new ArrayList<>();
|
2013-03-08 21:46:05 +01:00
|
|
|
itemLore.add("mcMMO Item");
|
2013-05-02 21:02:12 +02:00
|
|
|
itemLore.add(LocaleLoader.getString("Item.ChimaeraWing.Lore"));
|
2013-03-08 21:46:05 +01:00
|
|
|
itemMeta.setLore(itemLore);
|
2013-04-04 21:35:09 +02:00
|
|
|
|
2013-03-08 21:46:05 +01:00
|
|
|
itemStack.setItemMeta(itemMeta);
|
|
|
|
return itemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ShapelessRecipe getChimaeraWingRecipe() {
|
2013-09-13 15:12:21 +02:00
|
|
|
Material ingredient = Config.getInstance().getChimaeraItem();
|
2013-03-08 21:46:05 +01:00
|
|
|
int amount = Config.getInstance().getChimaeraRecipeCost();
|
|
|
|
|
2017-12-17 19:31:30 +01:00
|
|
|
ShapelessRecipe chimeraWing = new ShapelessRecipe(new NamespacedKey(mcMMO.p, "Chimera"), getChimaeraWing(1));
|
2013-09-05 22:36:02 +02:00
|
|
|
chimeraWing.addIngredient(amount, ingredient);
|
|
|
|
return chimeraWing;
|
2013-03-08 21:46:05 +01:00
|
|
|
}
|
2013-02-15 16:36:14 +01:00
|
|
|
}
|