From 174cd4659bb6d3b29d71281217e292f6605cbb25 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 23 Oct 2018 13:49:50 -0400 Subject: [PATCH] Fire ServerConnectedEvent and delay setting the server. For ViaVersion --- .../connection/backend/BackendPlaySessionHandler.java | 1 - .../proxy/connection/backend/LoginSessionHandler.java | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index a427cb524..411f4db0f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -27,7 +27,6 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public void activated() { - server.getEventManager().fireAndForget(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer())); serverConn.getServer().addPlayer(serverConn.getPlayer()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index d8e05f3b3..44de88b9b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.connection.backend; +import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.proxy.ConnectionRequestBuilder; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.VelocityServer; @@ -103,9 +104,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { existingConnection.disconnect(); } - resultFuture.complete(ConnectionRequestResults.SUCCESSFUL); - serverConn.getConnection().setSessionHandler(new BackendPlaySessionHandler(server, serverConn)); - serverConn.getPlayer().setConnectedServer(serverConn); + server.getEventManager().fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer())) + .whenCompleteAsync((x, error) -> { + resultFuture.complete(ConnectionRequestResults.SUCCESSFUL); + serverConn.getConnection().setSessionHandler(new BackendPlaySessionHandler(server, serverConn)); + serverConn.getPlayer().setConnectedServer(serverConn); + }, serverConn.getConnection().eventLoop()); return true; }