diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java index 3ec012649..29997670f 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java @@ -11,6 +11,7 @@ import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.annotation.AwaitingEvent; import com.velocitypowered.api.proxy.Player; +import org.checkerframework.checker.nullness.qual.Nullable; /** * This event is fired once the player has been authenticated, but before they connect to a server. @@ -22,18 +23,33 @@ import com.velocitypowered.api.proxy.Player; public final class LoginEvent implements ResultedEvent { private final Player player; + private final String serverIdHash; private ComponentResult result; /** * Constructs a new {@link LoginEvent}. * * @param player the player who has completed authentication + * @param serverIdHash the server ID hash sent to Mojang for authentication, + * or {@code null} if the connection is in offline-mode */ - public LoginEvent(Player player) { + public LoginEvent(Player player, @Nullable String serverIdHash) { this.player = Preconditions.checkNotNull(player, "player"); + this.serverIdHash = serverIdHash; this.result = ComponentResult.allowed(); } + /** + * Constructs a new {@link LoginEvent}. + * + * @param player the player who has completed authentication + * @deprecated Use {@link #LoginEvent(Player, String)}. + */ + @Deprecated(forRemoval = true) + public LoginEvent(Player player) { + this(player, null); + } + /** * Returns the player who has completed authentication. * @@ -43,6 +59,16 @@ public final class LoginEvent implements ResultedEvent { + server.getEventManager().fire(new LoginEvent(player, serverIdHash)).thenAcceptAsync(event -> { if (mcConnection.isClosed()) { // The player was disconnected server.getEventManager().fireAndForget(new DisconnectEvent(player, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java index 92f14191c..482fb76e6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java @@ -152,7 +152,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler { } else { mcConnection.setActiveSessionHandler(StateRegistry.LOGIN, new AuthSessionHandler(server, inbound, - GameProfile.forOfflinePlayer(login.getUsername()), false)); + GameProfile.forOfflinePlayer(login.getUsername()), false, null)); } }); }); @@ -255,7 +255,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler { } // All went well, initialize the session. mcConnection.setActiveSessionHandler(StateRegistry.LOGIN, - new AuthSessionHandler(server, inbound, profile, true)); + new AuthSessionHandler(server, inbound, profile, true, serverId)); } else if (response.statusCode() == 204) { // Apparently an offline-mode user logged onto this online-mode proxy. inbound.disconnect(