AsyncPlayerPreLoginEvent getConnection (#2446)

* AsyncPlayerPreLoginEvent getConnection

* reorder fields
This commit is contained in:
MelonHell 2024-10-23 16:20:45 +03:00 committed by Matt Worzala
parent 5e17487155
commit 85ae6ea821
2 changed files with 10 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package net.minestom.server.event.player;
import net.minestom.server.event.Event;
import net.minestom.server.network.player.GameProfile;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.network.plugin.LoginPlugin;
import net.minestom.server.network.plugin.LoginPluginMessageProcessor;
import org.jetbrains.annotations.NotNull;
@ -15,15 +16,22 @@ import java.util.concurrent.CompletableFuture;
*/
public class AsyncPlayerPreLoginEvent implements Event {
private final PlayerConnection connection;
private GameProfile gameProfile;
private final LoginPluginMessageProcessor pluginMessageProcessor;
public AsyncPlayerPreLoginEvent(@NotNull GameProfile gameProfile,
public AsyncPlayerPreLoginEvent(@NotNull PlayerConnection connection,
@NotNull GameProfile gameProfile,
@NotNull LoginPluginMessageProcessor pluginMessageProcessor) {
this.connection = connection;
this.gameProfile = gameProfile;
this.pluginMessageProcessor = pluginMessageProcessor;
}
public @NotNull PlayerConnection getConnection() {
return connection;
}
public GameProfile getGameProfile() {
return gameProfile;
}

View File

@ -189,7 +189,7 @@ public final class ConnectionManager {
}
// Call pre login event
LoginPluginMessageProcessor pluginMessageProcessor = connection.loginPluginMessageProcessor();
AsyncPlayerPreLoginEvent asyncPlayerPreLoginEvent = new AsyncPlayerPreLoginEvent(gameProfile, pluginMessageProcessor);
AsyncPlayerPreLoginEvent asyncPlayerPreLoginEvent = new AsyncPlayerPreLoginEvent(connection, gameProfile, pluginMessageProcessor);
EventDispatcher.call(asyncPlayerPreLoginEvent);
if (!connection.isOnline()) return gameProfile; // Player has been kicked
// Change UUID/Username based on the event