Search in sources :

Example 91 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Village_Defense by Plajer.

the class ArenaEvents method onDeath.

private void onDeath(final Player player, Arena arena) {
    if (arena.getArenaState() == ArenaState.STARTING) {
        player.teleport(arena.getStartLocation());
        return;
    }
    if (arena.getArenaState() == ArenaState.ENDING || arena.getArenaState() == ArenaState.RESTARTING) {
        player.getInventory().clear();
        player.setFlying(false);
        player.setAllowFlight(false);
        User user = UserManager.getUser(player.getUniqueId());
        user.setInt("orbs", 0);
        player.teleport(arena.getEndLocation());
        return;
    }
    User user = UserManager.getUser(player.getUniqueId());
    arena.addStat(player, "deaths");
    arena.teleportToStartLocation(player);
    user.setSpectator(true);
    player.setGameMode(GameMode.SURVIVAL);
    user.setFakeDead(true);
    user.setInt("orbs", 0);
    ArenaUtils.hidePlayer(player, arena);
    player.setAllowFlight(true);
    player.getInventory().clear();
    MessageHandler.sendTitle(player, ChatColor.stripColor(ChatManager.formatMessage(arena, "In-Game.Death-Screen")), 0, 5 * 20, 0, ChatColor.RED);
    if (plugin.is1_9_R1() || plugin.is1_11_R1() || plugin.is1_12_R1()) {
        new BukkitRunnable() {

            @Override
            public void run() {
                if (user.isSpectator())
                    player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatManager.formatMessage(arena, ChatManager.colorMessage("In-Game.Died-Respawn-In-Next-Wave"))));
                else
                    this.cancel();
            }
        }.runTaskTimer(plugin, 20, 20);
    }
    ChatManager.broadcastDeathMessage(arena, player);
    arena.teleportToStartLocation(player);
    player.setAllowFlight(true);
    player.setFlying(true);
    ItemStack spectatorItem = new ItemStack(Material.COMPASS, 1);
    ItemMeta spectatorMeta = spectatorItem.getItemMeta();
    spectatorMeta.setDisplayName(ChatManager.colorMessage("In-Game.Spectator.Spectator-Item-Name"));
    spectatorItem.setItemMeta(spectatorMeta);
    player.getInventory().setItem(0, spectatorItem);
    player.getInventory().setItem(8, SpecialItemManager.getSpecialItem("Leave").getItemStack());
    // tryin to untarget dead player bcuz they will still target him
    for (Zombie zombie : arena.getZombies()) {
        if (zombie.getTarget() != null) {
            if (zombie.getTarget().equals(player)) {
                // set new target as villager so zombies won't stay still waiting for nothing
                for (Villager villager : arena.getVillagers()) {
                    zombie.setTarget(villager);
                }
            }
        }
    }
}
Also used : User(pl.plajer.villagedefense3.User) Zombie(org.bukkit.entity.Zombie) Villager(org.bukkit.entity.Villager) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 92 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Village_Defense by Plajer.

the class Arena method joinAttempt.

/**
 * Attempts player to join arena.
 * Calls VillageGameJoinAttemptEvent.
 * Can be cancelled only via above-mentioned event
 *
 * @param p player to join
 * @see VillageGameJoinAttemptEvent
 */
public void joinAttempt(Player p) {
    VillageGameJoinAttemptEvent villageGameJoinAttemptEvent = new VillageGameJoinAttemptEvent(p, this);
    Bukkit.getPluginManager().callEvent(villageGameJoinAttemptEvent);
    if (!isReady) {
        p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Arena-Not-Configured"));
        return;
    }
    if (villageGameJoinAttemptEvent.isCancelled()) {
        p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Join-Cancelled-Via-API"));
        return;
    }
    if (!plugin.isBungeeActivated()) {
        if (!(p.hasPermission(PermissionsManager.getJoinPerm().replaceAll("<arena>", "*")) || p.hasPermission(PermissionsManager.getJoinPerm().replaceAll("<arena>", this.getID())))) {
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Join-No-Permission"));
            return;
        }
    }
    if (Main.isDebugged()) {
        System.out.println("[Village Debugger] Player " + p.getName() + " attemping to join arena!");
    }
    if ((getArenaState() == ArenaState.IN_GAME || (getArenaState() == ArenaState.STARTING && getTimer() <= 3) || getArenaState() == ArenaState.ENDING)) {
        if (plugin.isInventoryManagerEnabled()) {
            p.setLevel(0);
            plugin.getInventoryManager().saveInventoryToFile(p);
        }
        this.teleportToStartLocation(p);
        p.sendMessage(ChatManager.colorMessage("In-Game.You-Are-Spectator"));
        p.getInventory().clear();
        ItemStack spectatorItem = new ItemStack(Material.COMPASS, 1);
        ItemMeta spectatorMeta = spectatorItem.getItemMeta();
        spectatorMeta.setDisplayName(ChatManager.colorMessage("In-Game.Spectator.Spectator-Item-Name"));
        spectatorItem.setItemMeta(spectatorMeta);
        p.getInventory().setItem(0, spectatorItem);
        p.getInventory().setItem(8, SpecialItemManager.getSpecialItem("Leave").getItemStack());
        for (PotionEffect potionEffect : p.getActivePotionEffects()) {
            p.removePotionEffect(potionEffect.getType());
        }
        this.addPlayer(p);
        p.setMaxHealth(p.getMaxHealth() + rottenFleshLevel);
        p.setHealth(p.getMaxHealth());
        p.setFoodLevel(20);
        p.setGameMode(GameMode.SURVIVAL);
        p.setAllowFlight(true);
        p.setFlying(true);
        User user = UserManager.getUser(p.getUniqueId());
        user.setSpectator(true);
        user.setFakeDead(true);
        user.setInt("orbs", 0);
        p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1));
        ArenaUtils.hidePlayer(p, this);
        for (Player spectator : this.getPlayers()) {
            if (UserManager.getUser(spectator.getUniqueId()).isSpectator()) {
                p.hidePlayer(spectator);
            } else {
                p.showPlayer(spectator);
            }
        }
        ArenaUtils.hidePlayersOutsideTheGame(p, this);
        return;
    }
    if (plugin.isInventoryManagerEnabled()) {
        p.setLevel(0);
        plugin.getInventoryManager().saveInventoryToFile(p);
    }
    teleportToLobby(p);
    this.addPlayer(p);
    p.setHealth(p.getMaxHealth());
    p.setFoodLevel(20);
    p.getInventory().setArmorContents(new ItemStack[] { new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR) });
    p.setFlying(false);
    p.setAllowFlight(false);
    p.getInventory().clear();
    showPlayers();
    if (plugin.isBossbarEnabled()) {
        gameBar.addPlayer(p);
    }
    if (!UserManager.getUser(p.getUniqueId()).isSpectator())
        ChatManager.broadcastJoinMessage(this, p);
    User user = UserManager.getUser(p.getUniqueId());
    user.setKit(KitRegistry.getDefaultKit());
    plugin.getKitManager().giveKitMenuItem(p);
    if (getArenaState() == ArenaState.STARTING || getArenaState() == ArenaState.WAITING_FOR_PLAYERS)
        p.getInventory().setItem(SpecialItemManager.getSpecialItem("Leave").getSlot(), SpecialItemManager.getSpecialItem("Leave").getItemStack());
    p.updateInventory();
    for (Player player : getPlayers()) {
        ArenaUtils.showPlayer(player, this);
    }
    showPlayers();
}
Also used : Player(org.bukkit.entity.Player) User(pl.plajer.villagedefense3.User) VillageGameJoinAttemptEvent(pl.plajer.villagedefense3.villagedefenseapi.VillageGameJoinAttemptEvent) PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 93 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Village_Defense by Plajer.

the class SpectatorItemEvents method onSpectatorInventoryClick.

@EventHandler
public void onSpectatorInventoryClick(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();
    if (ArenaRegistry.getArena(p) == null)
        return;
    Arena arena = ArenaRegistry.getArena(p);
    if (e.getCurrentItem() == null)
        return;
    if (!e.getCurrentItem().hasItemMeta())
        return;
    if (!e.getCurrentItem().getItemMeta().hasDisplayName())
        return;
    if (!e.getCurrentItem().getItemMeta().hasLore())
        return;
    if (e.getCurrentItem().hasItemMeta()) {
        if (e.getInventory().getName().equalsIgnoreCase(ChatManager.colorMessage("In-Game.Spectator.Spectator-Menu-Name"))) {
            e.setCancelled(true);
            if ((e.isLeftClick() || e.isRightClick())) {
                ItemMeta meta = e.getCurrentItem().getItemMeta();
                for (Player player : arena.getPlayers()) {
                    if (player.getName().equalsIgnoreCase(meta.getDisplayName()) || ChatColor.stripColor(meta.getDisplayName()).contains(player.getName())) {
                        p.sendMessage(ChatManager.formatMessage(arena, ChatManager.colorMessage("Kits.Teleporter.Teleported-To-Player"), player));
                        p.teleport(player);
                        p.closeInventory();
                        e.setCancelled(true);
                        return;
                    }
                }
                p.sendMessage(ChatManager.colorMessage("Kits.Teleporter.Player-Not-Found"));
            }
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Arena(pl.plajer.villagedefense3.arena.Arena) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 94 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Village_Defense by Plajer.

the class BlockerKit method reStock.

@Override
public void reStock(Player player) {
    PlayerInventory inventory = player.getInventory();
    ItemStack is = new ItemStack(Material.FENCE, 3);
    ItemMeta im = is.getItemMeta();
    im.setDisplayName(ChatManager.colorMessage("Kits.Blocker.Game-Item-Name"));
    im.setLore(Collections.singletonList(ChatManager.colorMessage("Kits.Blocker.Game-Item-Lore")));
    is.setItemMeta(im);
    inventory.addItem(is);
}
Also used : PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 95 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Village_Defense by Plajer.

the class BlockerKit method giveKitItems.

@Override
public void giveKitItems(Player player) {
    ArmorHelper.setColouredArmor(Color.RED, player);
    player.getInventory().addItem(WeaponHelper.getEnchanted(new ItemStack(Material.STONE_SWORD), new org.bukkit.enchantments.Enchantment[] { org.bukkit.enchantments.Enchantment.DURABILITY }, new int[] { 10 }));
    player.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 10));
    ItemStack is = new ItemStack(Material.FENCE, 3);
    ItemMeta im = is.getItemMeta();
    im.setDisplayName(ChatManager.colorMessage("Kits.Blocker.Game-Item-Name"));
    im.setLore(Collections.singletonList(ChatManager.colorMessage("Kits.Blocker.Game-Item-Lore")));
    is.setItemMeta(im);
    player.getInventory().addItem(is);
    player.getInventory().addItem(new ItemStack(Material.SADDLE));
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ItemMeta (org.bukkit.inventory.meta.ItemMeta)361 ItemStack (org.bukkit.inventory.ItemStack)205 ArrayList (java.util.ArrayList)87 Player (org.bukkit.entity.Player)45 Inventory (org.bukkit.inventory.Inventory)33 Map (java.util.Map)29 Enchantment (org.bukkit.enchantments.Enchantment)23 EventHandler (org.bukkit.event.EventHandler)23 SkullMeta (org.bukkit.inventory.meta.SkullMeta)22 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)20 ListTag (com.wasteofplastic.org.jnbt.ListTag)20 StringTag (com.wasteofplastic.org.jnbt.StringTag)20 Tag (com.wasteofplastic.org.jnbt.Tag)20 PlayerInventory (org.bukkit.inventory.PlayerInventory)17 IOException (java.io.IOException)15 Material (org.bukkit.Material)14 PotionMeta (org.bukkit.inventory.meta.PotionMeta)14 Mage (com.elmakers.mine.bukkit.api.magic.Mage)12 BookMeta (org.bukkit.inventory.meta.BookMeta)12 List (java.util.List)11