com.velocitypowered.api.event.connection.LoginEvent Java Examples
The following examples show how to use
com.velocitypowered.api.event.connection.LoginEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VelocityConnectionListener.java From LuckPerms with MIT License | 5 votes |
@Subscribe public void onPlayerPostLogin(LoginEvent e) { final Player player = e.getPlayer(); final User user = this.plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()); if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) { this.plugin.getLogger().info("Processing post-login for " + player.getUniqueId() + " - " + player.getUsername()); } if (!e.getResult().isAllowed()) { return; } if (user == null) { if (!getUniqueConnections().contains(player.getUniqueId())) { this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getUsername() + " doesn't have data pre-loaded, they have never been processed during pre-login in this session."); } else { this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getUsername() + " doesn't currently have data pre-loaded, but they have been processed before in this session."); } if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) { // disconnect the user e.setResult(ResultedEvent.ComponentResult.denied(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager()))); } else { // just send a message this.plugin.getBootstrap().getScheduler().asyncLater(() -> { if (!player.isActive()) { return; } this.plugin.getSenderFactory().wrap(player).sendMessage(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager())); }, 1, TimeUnit.SECONDS); } } }
Example #2
Source File: LoginSessionHandler.java From Velocity with MIT License | 4 votes |
private void finishLogin(ConnectedPlayer player) { Optional<RegisteredServer> toTry = player.getNextServerToTry(); if (!toTry.isPresent()) { player.disconnect(VelocityMessages.NO_AVAILABLE_SERVERS); return; } int threshold = server.getConfiguration().getCompressionThreshold(); if (threshold >= 0) { mcConnection.write(new SetCompression(threshold)); mcConnection.setCompressionThreshold(threshold); } VelocityConfiguration configuration = server.getConfiguration(); UUID playerUniqueId = player.getUniqueId(); if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) { playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername()); } ServerLoginSuccess success = new ServerLoginSuccess(); success.setUsername(player.getUsername()); success.setUuid(playerUniqueId); mcConnection.write(success); mcConnection.setAssociation(player); mcConnection.setState(StateRegistry.PLAY); server.getEventManager().fire(new LoginEvent(player)) .thenAcceptAsync(event -> { if (mcConnection.isClosed()) { // The player was disconnected return; } Optional<Component> reason = event.getResult().getReason(); if (reason.isPresent()) { player.disconnect(reason.get()); } else { if (!server.registerConnection(player)) { player.disconnect(VelocityMessages.ALREADY_CONNECTED); return; } mcConnection.setSessionHandler(new InitialConnectSessionHandler(player)); server.getEventManager().fire(new PostLoginEvent(player)) .thenRun(() -> player.createConnectionRequest(toTry.get()).fireAndForget()); } }, mcConnection.eventLoop()); }
Example #3
Source File: VelocityConnectionListener.java From LuckPerms with MIT License | 4 votes |
@Subscribe(order = PostOrder.FIRST) public void onPlayerLogin(LoginEvent e) { if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) { e.setResult(ResultedEvent.ComponentResult.denied(Message.LOADING_DATABASE_ERROR.asComponent(this.plugin.getLocaleManager()))); } }
Example #4
Source File: VelocityPlugin.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onPlayerLogin(LoginEvent event) { handleConnection(event.getPlayer()); }