Search in sources :

Example 1 with GameJoinEvent

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

the class AbstractGame method spectate.

@Override
public boolean spectate(@Nonnull User user) {
    if (!getActivePhase().allowSpectate()) {
        Lang.msg(user, LangKey.GAME_CANT_SPECTATE);
        return false;
    }
    if (!isPlaying(user.getUuid()) && !isSpectating(user.getUuid())) {
        spectators.add(user);
        allUsers.add(user);
        playerStates.put(user.getUuid(), PlayerState.of(user));
        GameJoinEvent event = new GameJoinEvent(this, user);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            players.remove(user);
            allUsers.remove(user);
            return false;
        }
        // todo: perhaps consider having this handled by phases instead
        // disable listening to global messages
        user.removeListeningChannel(chatHandler.defaultChannel.getIdentifier());
        // local channel
        user.addListeningChannel(chatChannel.getIdentifier());
        user.setActiveChannel(chatChannel.getIdentifier());
        return true;
    }
    return false;
}
Also used : GameJoinEvent(com.voxelgameslib.voxelgameslib.api.event.events.game.GameJoinEvent)

Example 2 with GameJoinEvent

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

the class AbstractGame method join.

@Override
public boolean join(@Nonnull User user) {
    if (!getActivePhase().allowJoin() || getMaxPlayers() == players.size()) {
        return spectate(user);
    }
    if (!isPlaying(user.getUuid())) {
        players.add(user);
        allUsers.add(user);
        playerStates.put(user.getUuid(), PlayerState.of(user));
        GameJoinEvent event = new GameJoinEvent(this, user);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            players.remove(user);
            allUsers.remove(user);
            return false;
        }
        broadcastMessage(LangKey.GAME_PLAYER_JOIN, (Object) user.getDisplayName());
    }
    // todo: perhaps consider having this handled by phases instead
    // disable listening to global messages
    user.removeListeningChannel(chatHandler.defaultChannel.getIdentifier());
    // local channel
    user.addListeningChannel(chatChannel.getIdentifier());
    user.setActiveChannel(chatChannel.getIdentifier());
    return true;
}
Also used : GameJoinEvent(com.voxelgameslib.voxelgameslib.api.event.events.game.GameJoinEvent)

Aggregations

GameJoinEvent (com.voxelgameslib.voxelgameslib.api.event.events.game.GameJoinEvent)2