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);
}
Aggregations