Search in sources :

Example 1 with GamePostLeaveEvent

use of com.voxelgameslib.voxelgameslib.api.event.events.game.GamePostLeaveEvent in project VoxelGamesLibv2 by VoxelGamesLib.

the class AbstractGame method leave.

@Override
public void leave(@Nonnull User user, boolean shouldTeleportToSpawn) {
    Bukkit.getPluginManager().callEvent(new GamePreLeaveEvent(this, user));
    players.remove(user);
    spectators.remove(user);
    allUsers.remove(user);
    Optional.ofNullable(playerStates.remove(user.getUuid())).ifPresent(state -> state.apply(user));
    broadcastMessage(LangKey.GAME_PLAYER_LEAVE, (Object) user.getDisplayName());
    GamePostLeaveEvent event = new GamePostLeaveEvent(this, user, Bukkit.getWorlds().get(0).getSpawnLocation(), shouldTeleportToSpawn);
    event.callEvent();
    if (event.shouldTeleportToSpawn()) {
        user.getPlayer().teleportAsync(event.getSpawnLocation());
    }
    user.removeListeningChannel(chatChannel.getIdentifier());
    user.addListeningChannel(chatHandler.defaultChannel.getIdentifier());
    user.setActiveChannel(chatHandler.defaultChannel.getIdentifier());
    if (players.size() < minPlayers && !ending && !aborted) {
        broadcastMessage(LangKey.GAME_TOO_FEW_PLAYERS);
        abortGame();
    }
}
Also used : GamePostLeaveEvent(com.voxelgameslib.voxelgameslib.api.event.events.game.GamePostLeaveEvent) GamePreLeaveEvent(com.voxelgameslib.voxelgameslib.api.event.events.game.GamePreLeaveEvent)

Aggregations

GamePostLeaveEvent (com.voxelgameslib.voxelgameslib.api.event.events.game.GamePostLeaveEvent)1 GamePreLeaveEvent (com.voxelgameslib.voxelgameslib.api.event.events.game.GamePreLeaveEvent)1