package me.zoibox.kitpvp.kits; import me.zoibox.kitpvp.KitPvP; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.HashMap; public class Phantom implements Listener { private static KitPvP plugin; public Phantom(KitPvP plugin) { this.plugin = plugin; } private HashMap cooldown = new HashMap<>(); private HashMap cooldownFlight = new HashMap<>(); int cooldownTime = 30; int cooldownFlightI = 10; public void PhantomKit(Player player) { ItemStack helmet = new ItemStack(Material.IRON_HELMET); ItemMeta helmetM = helmet.getItemMeta(); helmetM.setDisplayName(ChatColor.DARK_GRAY + "Phantom Helmet"); helmetM.spigot().setUnbreakable(true); helmet.setItemMeta(helmetM); ItemStack chestplate = new ItemStack(Material.IRON_CHESTPLATE); ItemMeta chestM = chestplate.getItemMeta(); chestM.setDisplayName(ChatColor.DARK_GRAY + "Phantom Chestplate"); chestM.spigot().setUnbreakable(true); chestplate.setItemMeta(chestM); ItemStack leggings = new ItemStack(Material.IRON_LEGGINGS); ItemMeta leggingsM = leggings.getItemMeta(); leggingsM.setDisplayName(ChatColor.DARK_GRAY + "Phantom Leggings"); leggingsM.spigot().setUnbreakable(true); leggings.setItemMeta(leggingsM); ItemStack boots = new ItemStack(Material.IRON_BOOTS); ItemMeta bootsM = boots.getItemMeta(); bootsM.setDisplayName(ChatColor.DARK_GRAY + "Phantom Boots"); bootsM.spigot().setUnbreakable(true); boots.setItemMeta(bootsM); ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); ItemMeta swordM = sword.getItemMeta(); swordM.setDisplayName(ChatColor.DARK_GRAY + "Phantom Sword"); swordM.spigot().setUnbreakable(true); sword.setItemMeta(swordM); ItemStack ability = new ItemStack(Material.BOOK); ItemMeta abilityM = ability.getItemMeta(); abilityM.setDisplayName(ChatColor.BLUE + "Fly!"); abilityM.spigot().setUnbreakable(true); ability.setItemMeta(abilityM); player.getInventory().setHelmet(helmet); player.getInventory().setChestplate(chestplate); player.getInventory().setLeggings(leggings); player.getInventory().setBoots(boots); player.getInventory().setItem(1, ability); player.getInventory().setItem(0, sword); if (!plugin.souporport.contains(player)) { ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP); ItemMeta soupM = soup.getItemMeta(); soupM.setDisplayName(ChatColor.BLUE + "Soup"); soup.setItemMeta(soupM); //add soup for (int i = 0; i < 34; ++i) { player.getInventory().addItem(soup); } } else { ItemStack potion = new ItemStack(Material.POTION, 1, (short) 16421); for (int i = 0; i < 34; ++i) { player.getInventory().addItem(potion); } } } @EventHandler public void onPlayerClicks(PlayerInteractEvent event) { Player player = event.getPlayer(); Action action = event.getAction(); ItemStack ability = new ItemStack(Material.BOOK); ItemMeta abilityM = ability.getItemMeta(); abilityM.setDisplayName(ChatColor.BLUE + "Fly!"); abilityM.spigot().setUnbreakable(true); ability.setItemMeta(abilityM); if (action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)) { if (player.getItemInHand().getType().equals(ability)) { if (cooldown.containsKey(player) && cooldown.get(player) > System.currentTimeMillis()) { long timeRemaining = cooldown.get(player) - System.currentTimeMillis(); int remaining = (int) (timeRemaining / 1000); player.sendMessage(ChatColor.RED + plugin.prefix + "You must wait " + remaining + "s before doing this again!"); } else { long timeRemainingFl = cooldownFlight.get(player) - System.currentTimeMillis(); int remainingFl = (int) (timeRemainingFl / 1000); player.sendMessage(ChatColor.GREEN + plugin.prefix + "You have enabled your flight for 10 seconds!"); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { player.sendMessage(ChatColor.RED + plugin.prefix + "Your flight expires in " + remainingFl + "!"); } }, 100); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { player.sendMessage(ChatColor.RED + plugin.prefix + "Your flight expires in " + remainingFl + "!"); } }, 80); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { player.sendMessage(ChatColor.RED + plugin.prefix + "Your flight expires in " + remainingFl + "!"); } }, 60); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { player.sendMessage(ChatColor.RED + plugin.prefix + "Your flight expires in " + remainingFl + "!"); } }, 40); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { player.sendMessage(ChatColor.RED + plugin.prefix + "Your flight expires in " + cooldownFlightI + "!"); } }, 20); player.sendMessage(ChatColor.RED + KitPvP.prefix + "Your Flight has expired!"); player.teleport(player.getLocation().add(0, 6, 0)); cooldown.put(player, System.currentTimeMillis() + (cooldownTime * 1000)); } } } } }