com.velocitypowered.api.event.player.ServerConnectedEvent Java Examples
The following examples show how to use
com.velocitypowered.api.event.player.ServerConnectedEvent.
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: PlayerOnlineListener.java From Plan with GNU Lesser General Public License v3.0 | 6 votes |
public void actOnServerSwitch(ServerConnectedEvent event) { Player player = event.getPlayer(); String playerName = player.getUsername(); UUID playerUUID = player.getUniqueId(); long time = System.currentTimeMillis(); // Replaces the current session in the cache. Session session = new Session(playerUUID, serverInfo.getServerUUID(), time, null, null); session.putRawData(SessionKeys.NAME, playerName); session.putRawData(SessionKeys.SERVER_NAME, "Proxy Server"); sessionCache.cacheSession(playerUUID, session); if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) { processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName)); } JSONCache.invalidate(DataID.SERVERS); }
Example #2
Source File: VelocityPingCounter.java From Plan with GNU Lesser General Public License v3.0 | 6 votes |
@Subscribe public void onPlayerJoin(ServerConnectedEvent joinEvent) { Player player = joinEvent.getPlayer(); Long pingDelay = config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY); if (pingDelay >= TimeUnit.HOURS.toMillis(2L)) { return; } runnableFactory.create("Add Player to Ping list", new AbsRunnable() { @Override public void run() { if (player.isActive()) { addPlayer(player); } } }).runTaskLater(TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS)); }
Example #3
Source File: ElytraPatch.java From ViaVersion with MIT License | 6 votes |
@Subscribe(order = PostOrder.LAST) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); wrapper.send(Protocol1_9To1_8.class); } } catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: PlayerOnlineListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
@Subscribe(order = PostOrder.LAST) public void onServerSwitch(ServerConnectedEvent event) { try { actOnServerSwitch(event); } catch (Exception e) { errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build()); } }
Example #5
Source File: VelocityServerHandler.java From ViaVersion with MIT License | 5 votes |
@Subscribe(order = PostOrder.LATE) public void connectedEvent(ServerConnectedEvent e) { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); CompletableFuture.runAsync(() -> { try { checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); } catch (Exception e1) { e1.printStackTrace(); } }, user.getChannel().eventLoop()).join(); }
Example #6
Source File: TransitionSessionHandler.java From Velocity with MIT License | 4 votes |
@Override public boolean handle(JoinGame packet) { MinecraftConnection smc = serverConn.ensureConnected(); VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); if (existingConnection != null) { // Shut down the existing server connection. serverConn.getPlayer().setConnectedServer(null); existingConnection.disconnect(); // Send keep alive to try to avoid timeouts serverConn.getPlayer().sendKeepAlive(); } // The goods are in hand! We got JoinGame. Let's transition completely to the new state. smc.setAutoReading(false); server.getEventManager() .fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer())) .whenCompleteAsync((x, error) -> { // Make sure we can still transition (player might have disconnected here). if (!serverConn.isActive()) { // Connection is obsolete. serverConn.disconnect(); return; } // Strap on the ClientPlaySessionHandler if required. ClientPlaySessionHandler playHandler; if (serverConn.getPlayer().getMinecraftConnection().getSessionHandler() instanceof ClientPlaySessionHandler) { playHandler = (ClientPlaySessionHandler) serverConn.getPlayer().getMinecraftConnection() .getSessionHandler(); } else { playHandler = new ClientPlaySessionHandler(server, serverConn.getPlayer()); serverConn.getPlayer().getMinecraftConnection().setSessionHandler(playHandler); } playHandler.handleBackendJoinGame(packet, serverConn); // Strap on the correct session handler for the server. We will have nothing more to do // with this connection once this task finishes up. smc.setSessionHandler(new BackendPlaySessionHandler(server, serverConn)); // Clean up disabling auto-read while the connected event was being processed. smc.setAutoReading(true); // Now set the connected server. serverConn.getPlayer().setConnectedServer(serverConn); // We're done! :) resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer())); }, smc.eventLoop()) .exceptionally(exc -> { logger.error("Unable to switch to new server {} for {}", serverConn.getServerInfo().getName(), serverConn.getPlayer().getUsername(), exc); serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); resultFuture.completeExceptionally(exc); return null; }); return true; }
Example #7
Source File: BackendServerCalculator.java From LuckPerms with MIT License | 4 votes |
@Subscribe public void onServerConnect(ServerConnectedEvent e) { this.plugin.getContextManager().signalContextUpdate(e.getPlayer()); }
Example #8
Source File: OnlineForwardPluginMessagingForwardingSource.java From NuVotifier with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onServerConnected(final ServerConnectedEvent e) { //Attempt to resend any votes that were previously cached. BackendServer server = new VelocityBackendServer(plugin.getServer(), e.getServer()); onServerConnect(server); handlePlayerSwitch(server, e.getPlayer().getUsername()); }
Example #9
Source File: PluginMessagingForwardingSource.java From NuVotifier with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onServerConnected(final ServerConnectedEvent e) { //Attempt to resend any votes that were previously cached. onServerConnect(new VelocityBackendServer(plugin.getServer(), e.getServer())); }