Search in sources :

Example 1 with DisconnectEvent

use of com.velocitypowered.api.event.connection.DisconnectEvent in project LimboAPI by Elytrium.

the class LoginTasksQueue method initialize.

// Ported from Velocity.
// TODO: Пофиксить ситуацию когда при подключении после лимбы внутренний сервер кикает и причину не пишет клиенту
private void initialize(MinecraftConnection connection) throws IllegalAccessException {
    association.set(connection, this.player);
    state.set(connection, StateRegistry.PLAY);
    connection.getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.PLAY);
    connection.getChannel().pipeline().get(MinecraftDecoder.class).setState(StateRegistry.PLAY);
    this.server.getEventManager().fire(new LoginEvent(this.player)).thenAcceptAsync(event -> {
        if (connection.isClosed()) {
            // The player was disconnected
            this.server.getEventManager().fireAndForget(new DisconnectEvent(this.player, DisconnectEvent.LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE));
            return;
        }
        Optional<Component> reason = event.getResult().getReasonComponent();
        if (reason.isPresent()) {
            this.player.disconnect0(reason.get(), true);
        } else {
            if (!this.server.registerConnection(this.player)) {
                this.player.disconnect0(Component.translatable("velocity.error.already-connected-proxy"), true);
                return;
            }
            try {
                connection.setSessionHandler(initialCtor.newInstance(this.player));
                this.server.getEventManager().fire(new PostLoginEvent(this.player)).thenAccept((ignored) -> {
                    try {
                        // go back i want to be ~~monke~~ original mcConnection
                        loginConnectionField.set(this.handler, connection);
                        connectToInitialServer.invoke(this.handler, this.player);
                    } catch (IllegalAccessException | InvocationTargetException ex) {
                        this.plugin.getLogger().error("Exception while connecting {} to initial server", this.player, ex);
                    }
                });
            } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }, connection.eventLoop()).exceptionally((ex) -> {
        this.plugin.getLogger().error("Exception while completing login initialisation phase for {}", this.player, ex);
        return null;
    });
}
Also used : DisconnectEvent(com.velocitypowered.api.event.connection.DisconnectEvent) LimboAPI(net.elytrium.limboapi.LimboAPI) InboundConnection(com.velocitypowered.api.proxy.InboundConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) Constructor(java.lang.reflect.Constructor) InitialConnectSessionHandler(com.velocitypowered.proxy.connection.client.InitialConnectSessionHandler) StateRegistry(com.velocitypowered.proxy.protocol.StateRegistry) Component(net.kyori.adventure.text.Component) LoginEvent(com.velocitypowered.api.event.connection.LoginEvent) PostLoginEvent(com.velocitypowered.api.event.connection.PostLoginEvent) SafeGameProfileRequestEvent(net.elytrium.limboapi.api.event.SafeGameProfileRequestEvent) Method(java.lang.reflect.Method) MinecraftDecoder(com.velocitypowered.proxy.protocol.netty.MinecraftDecoder) PermissionsSetupEvent(com.velocitypowered.api.event.permission.PermissionsSetupEvent) LoginSessionHandler(com.velocitypowered.proxy.connection.client.LoginSessionHandler) Field(java.lang.reflect.Field) PermissionFunction(com.velocitypowered.api.permission.PermissionFunction) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) PermissionProvider(com.velocitypowered.api.permission.PermissionProvider) Objects(java.util.Objects) GameProfileRequestEvent(com.velocitypowered.api.event.player.GameProfileRequestEvent) MinecraftEncoder(com.velocitypowered.proxy.protocol.netty.MinecraftEncoder) Optional(java.util.Optional) VelocityServer(com.velocitypowered.proxy.VelocityServer) Queue(java.util.Queue) Optional(java.util.Optional) PostLoginEvent(com.velocitypowered.api.event.connection.PostLoginEvent) MinecraftDecoder(com.velocitypowered.proxy.protocol.netty.MinecraftDecoder) LoginEvent(com.velocitypowered.api.event.connection.LoginEvent) PostLoginEvent(com.velocitypowered.api.event.connection.PostLoginEvent) DisconnectEvent(com.velocitypowered.api.event.connection.DisconnectEvent) MinecraftEncoder(com.velocitypowered.proxy.protocol.netty.MinecraftEncoder)

Aggregations

DisconnectEvent (com.velocitypowered.api.event.connection.DisconnectEvent)1 LoginEvent (com.velocitypowered.api.event.connection.LoginEvent)1 PostLoginEvent (com.velocitypowered.api.event.connection.PostLoginEvent)1 PermissionsSetupEvent (com.velocitypowered.api.event.permission.PermissionsSetupEvent)1 GameProfileRequestEvent (com.velocitypowered.api.event.player.GameProfileRequestEvent)1 PermissionFunction (com.velocitypowered.api.permission.PermissionFunction)1 PermissionProvider (com.velocitypowered.api.permission.PermissionProvider)1 InboundConnection (com.velocitypowered.api.proxy.InboundConnection)1 VelocityServer (com.velocitypowered.proxy.VelocityServer)1 MinecraftConnection (com.velocitypowered.proxy.connection.MinecraftConnection)1 ConnectedPlayer (com.velocitypowered.proxy.connection.client.ConnectedPlayer)1 InitialConnectSessionHandler (com.velocitypowered.proxy.connection.client.InitialConnectSessionHandler)1 LoginSessionHandler (com.velocitypowered.proxy.connection.client.LoginSessionHandler)1 StateRegistry (com.velocitypowered.proxy.protocol.StateRegistry)1 MinecraftDecoder (com.velocitypowered.proxy.protocol.netty.MinecraftDecoder)1 MinecraftEncoder (com.velocitypowered.proxy.protocol.netty.MinecraftEncoder)1 Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1