Search in sources :

Example 1 with MinecraftConnection

use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.

the class LimboImpl method respawnPlayer.

@Override
public void respawnPlayer(Player player) {
    MinecraftConnection connection = ((ConnectedPlayer) player).getConnection();
    connection.write(this.spawnPosition);
    if (this.chunks != null) {
        connection.write(this.chunks);
    }
}
Also used : MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer)

Example 2 with MinecraftConnection

use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.

the class LimboSessionHandlerImpl method disconnected.

@Override
public void disconnected() {
    this.callback.onDisconnect();
    if (this.keepAliveTask != null) {
        this.keepAliveTask.cancel();
    }
    if (Settings.IMP.MAIN.LOGGING_ENABLED) {
        this.plugin.getLogger().info(this.player.getUsername() + " (" + this.player.getRemoteAddress() + ") has disconnected from the " + this.limboName.get() + " Limbo");
    }
    MinecraftConnection connection = this.player.getConnection();
    if (connection.isClosed()) {
        try {
            teardown.invoke(this.player);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return;
    }
    if (!(this.originalHandler instanceof LoginSessionHandler) && !(this.originalHandler instanceof LimboSessionHandlerImpl)) {
        connection.eventLoop().execute(() -> connection.setSessionHandler(this.originalHandler));
    }
    ChannelPipeline pipeline = connection.getChannel().pipeline();
    if (pipeline.names().contains("prepared-encoder")) {
        pipeline.remove(PreparedPacketEncoder.class);
    }
}
Also used : LoginSessionHandler(com.velocitypowered.proxy.connection.client.LoginSessionHandler) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 3 with MinecraftConnection

use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.

the class LoginTasksQueue method finish.

private void finish() {
    this.plugin.removeLoginQueue(this.player);
    MinecraftConnection connection = this.player.getConnection();
    this.server.getEventManager().fire(new GameProfileRequestEvent(this.inbound, this.player.getGameProfile(), this.player.isOnlineMode())).thenAcceptAsync(gameProfile -> this.server.getEventManager().fire(new SafeGameProfileRequestEvent(gameProfile.getGameProfile(), gameProfile.isOnlineMode())).thenAcceptAsync(safeGameProfile -> {
        try {
            profile.set(this.player, safeGameProfile.getGameProfile());
            // From Velocity.
            this.server.getEventManager().fire(new PermissionsSetupEvent(this.player, (PermissionProvider) defaultPermissions.get(null))).thenAcceptAsync(event -> {
                if (!connection.isClosed()) {
                    // Wait for permissions to load, then set the players' permission function.
                    final PermissionFunction function = event.createFunction(this.player);
                    if (function == null) {
                        this.plugin.getLogger().error("A plugin permission provider {} provided an invalid permission function" + " for player {}. This is a bug in the plugin, not in Velocity. Falling" + " back to the default permission function.", event.getProvider().getClass().getName(), this.player.getUsername());
                    } else {
                        try {
                            setPermissionFunction.invoke(this.player, function);
                        } catch (IllegalAccessException | InvocationTargetException ex) {
                            this.plugin.getLogger().error("Exception while completing injection to {}", this.player, ex);
                        }
                    }
                    try {
                        this.initialize(connection);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            });
        } catch (IllegalAccessException ex) {
            this.plugin.getLogger().error("Exception while completing injection to {}", this.player, ex);
        }
    }, connection.eventLoop()), connection.eventLoop());
}
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) PermissionsSetupEvent(com.velocitypowered.api.event.permission.PermissionsSetupEvent) PermissionFunction(com.velocitypowered.api.permission.PermissionFunction) PermissionProvider(com.velocitypowered.api.permission.PermissionProvider) SafeGameProfileRequestEvent(net.elytrium.limboapi.api.event.SafeGameProfileRequestEvent) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) SafeGameProfileRequestEvent(net.elytrium.limboapi.api.event.SafeGameProfileRequestEvent) GameProfileRequestEvent(com.velocitypowered.api.event.player.GameProfileRequestEvent)

Example 4 with MinecraftConnection

use of com.velocitypowered.proxy.connection.MinecraftConnection 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)

Example 5 with MinecraftConnection

use of com.velocitypowered.proxy.connection.MinecraftConnection in project LimboAPI by Elytrium.

the class LoginListener method hookPlaySession.

@Subscribe
public void hookPlaySession(ServerConnectedEvent event) {
    ConnectedPlayer player = (ConnectedPlayer) event.getPlayer();
    MinecraftConnection connection = player.getConnection();
    connection.eventLoop().execute(() -> {
        if (!(connection.getSessionHandler() instanceof ClientPlaySessionHandler)) {
            ClientPlaySessionHandler playHandler = new ClientPlaySessionHandler(this.server, player);
            try {
                spawned.set(playHandler, this.plugin.isLimboJoined(player));
            } catch (IllegalAccessException ex) {
                this.plugin.getLogger().error("Exception while hooking into ClientPlaySessionHandler of {}", player, ex);
            }
            connection.setSessionHandler(playHandler);
        }
    });
}
Also used : ClientPlaySessionHandler(com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler) ClosedMinecraftConnection(net.elytrium.limboapi.injection.dummy.ClosedMinecraftConnection) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

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