Search in sources :

Example 1 with VillageGameLeaveAttemptEvent

use of pl.plajer.villagedefense3.villagedefenseapi.VillageGameLeaveAttemptEvent in project Village_Defense by Plajer.

the class Arena method leaveAttempt.

/**
 * Attempts player to leave arena.
 * Calls VillageGameLeaveAttemptEvent event.
 *
 * @param p player to join
 * @see VillageGameLeaveAttemptEvent
 */
public void leaveAttempt(Player p) {
    VillageGameLeaveAttemptEvent villageGameLeaveAttemptEvent = new VillageGameLeaveAttemptEvent(p, this);
    Bukkit.getPluginManager().callEvent(villageGameLeaveAttemptEvent);
    if (Main.isDebugged()) {
        System.out.println("[Village Debugger] Player " + p.getName() + " is attemping to leave arena!");
    }
    User user = UserManager.getUser(p.getUniqueId());
    user.setInt("orbs", 0);
    p.getInventory().clear();
    ArmorHelper.clearArmor(p);
    this.removePlayer(p);
    if (!user.isSpectator()) {
        ChatManager.broadcastLeaveMessage(this, p);
    }
    user.setFakeDead(false);
    user.setSpectator(false);
    user.removeScoreboard();
    if (user.getKit() instanceof GolemFriendKit) {
        for (IronGolem ironGolem : getIronGolems()) {
            if (ironGolem.getCustomName().contains(user.toPlayer().getName()))
                ironGolem.remove();
        }
    }
    if (plugin.isBossbarEnabled()) {
        gameBar.removePlayer(p);
    }
    p.setMaxHealth(20.0);
    p.setHealth(p.getMaxHealth());
    p.setFoodLevel(20);
    p.setFlying(false);
    p.setAllowFlight(false);
    for (PotionEffect effect : p.getActivePotionEffects()) {
        p.removePotionEffect(effect.getType());
    }
    p.setFireTicks(0);
    if (getPlayers().size() == 0) {
        this.setArenaState(ArenaState.RESTARTING);
    }
    p.setGameMode(GameMode.SURVIVAL);
    for (Player players : plugin.getServer().getOnlinePlayers()) {
        if (ArenaRegistry.getArena(players) != null)
            players.showPlayer(p);
        p.showPlayer(players);
    }
    this.teleportToEndLocation(p);
    if (!plugin.isBungeeActivated() && plugin.isInventoryManagerEnabled()) {
        plugin.getInventoryManager().loadInventory(p);
    }
}
Also used : Player(org.bukkit.entity.Player) User(pl.plajer.villagedefense3.User) PotionEffect(org.bukkit.potion.PotionEffect) GolemFriendKit(pl.plajer.villagedefense3.kits.GolemFriendKit) IronGolem(org.bukkit.entity.IronGolem) VillageGameLeaveAttemptEvent(pl.plajer.villagedefense3.villagedefenseapi.VillageGameLeaveAttemptEvent)

Aggregations

IronGolem (org.bukkit.entity.IronGolem)1 Player (org.bukkit.entity.Player)1 PotionEffect (org.bukkit.potion.PotionEffect)1 User (pl.plajer.villagedefense3.User)1 GolemFriendKit (pl.plajer.villagedefense3.kits.GolemFriendKit)1 VillageGameLeaveAttemptEvent (pl.plajer.villagedefense3.villagedefenseapi.VillageGameLeaveAttemptEvent)1