Add server-id hash to LoginEvent (#1027)

This commit is contained in:
Rocco
2026-02-10 18:59:34 +00:00
committed by GitHub
parent 7e01491e2f
commit 2535751cd9
3 changed files with 33 additions and 5 deletions

View File

@@ -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<ResultedEvent.ComponentResult> {
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<ResultedEvent.ComponentRe
return player;
}
/**
* Returns the server ID hash that was sent to Mojang to authenticate the player.
* If the connection was in offline-mode, this returns {@code null}.
*
* @return the server ID hash that was sent to Mojang to authenticate the player
*/
public @Nullable String getServerIdHash() {
return serverIdHash;
}
@Override
public ComponentResult getResult() {
return result;