Search in sources :

Example 1 with PlayerLoginEvent

use of io.xol.chunkstories.api.events.player.PlayerLoginEvent in project chunkstories by Hugobros3.

the class PlayerLoginHelper method afterLoginValidation.

/**
 * Called after the login token has been validated, or in the case of an
 * offline-mode server, after the client requested to login.
 */
private void afterLoginValidation() {
    // Disallow users from logging in from two places
    Player contender = connection.clientsManager.getPlayerByName(name);
    if (contender != null) {
        connection.disconnect("You are already logged in. (" + contender + "). ");
        return;
    }
    // Creates a player based on the thrusted login information
    ServerPlayer player = new ServerPlayer(connection, name);
    // Fire the login event
    PlayerLoginEvent playerConnectionEvent = new PlayerLoginEvent(player);
    connection.clientsManager.getServer().getPluginManager().fireEvent(playerConnectionEvent);
    if (playerConnectionEvent.isCancelled()) {
        connection.disconnect(playerConnectionEvent.getRefusedConnectionMessage());
        return;
    }
    // Announce player login
    connection.clientsManager.getServer().broadcastMessage(playerConnectionEvent.getConnectionMessage());
    // Aknowledge the login
    logged_in = true;
    connection.sendTextMessage("login/ok");
    connection.flush();
    connection.setPlayer(player);
}
Also used : Player(io.xol.chunkstories.api.player.Player) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) PlayerLoginEvent(io.xol.chunkstories.api.events.player.PlayerLoginEvent)

Aggregations

PlayerLoginEvent (io.xol.chunkstories.api.events.player.PlayerLoginEvent)1 Player (io.xol.chunkstories.api.player.Player)1 ServerPlayer (io.xol.chunkstories.server.player.ServerPlayer)1