Search in sources :

Example 1 with VillageGameJoinAttemptEvent

use of pl.plajer.villagedefense3.villagedefenseapi.VillageGameJoinAttemptEvent 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)

Aggregations

Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 PotionEffect (org.bukkit.potion.PotionEffect)1 User (pl.plajer.villagedefense3.User)1 VillageGameJoinAttemptEvent (pl.plajer.villagedefense3.villagedefenseapi.VillageGameJoinAttemptEvent)1