Search in sources :

Example 1 with PermissionFunction

use of com.velocitypowered.api.permission.PermissionFunction 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)

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