Search in sources :

Example 1 with PendingConnection

use of net.md_5.bungee.api.connection.PendingConnection in project LuckPerms by lucko.

the class BungeeConnectionListener method onPlayerLogin.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(LoginEvent e) {
    /* Called when the player first attempts a connection with the server.
           Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins)

           Delay the login here, as we want to cache UUID data before the player is connected to a backend bukkit server.
           This means that a player will have the same UUID across the network, even if parts of the network are running in
           Offline mode. */
    /* registers the plugins intent to modify this events state going forward.
           this will prevent the event from completing until we're finished handling. */
    e.registerIntent(this.plugin.getBootstrap());
    final PendingConnection c = e.getConnection();
    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing pre-login for " + c.getUniqueId() + " - " + c.getName());
    }
    this.plugin.getBootstrap().getScheduler().doAsync(() -> {
        recordConnection(c.getUniqueId());
        /* Actually process the login for the connection.
               We do this here to delay the login until the data is ready.
               If the login gets cancelled later on, then this will be cleaned up.

               This includes:
               - loading uuid data
               - loading permissions
               - creating a user instance in the UserManager for this connection.
               - setting up cached data. */
        try {
            User user = loadUser(c.getUniqueId(), c.getName());
            this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
        } catch (Exception ex) {
            this.plugin.getLogger().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName());
            ex.printStackTrace();
            // there was some error loading
            if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
                // cancel the login attempt
                e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
                e.setCancelled(true);
            }
        }
        // finally, complete our intent to modify state, so the proxy can continue handling the connection.
        e.completeIntent(this.plugin.getBootstrap());
    });
}
Also used : User(me.lucko.luckperms.common.model.User) PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with PendingConnection

use of net.md_5.bungee.api.connection.PendingConnection in project ChangeSkin by games647.

the class ConnectListener method onPostLogin.

@EventHandler(priority = EventPriority.HIGH)
public void onPostLogin(LoginEvent loginEvent) {
    if (loginEvent.isCancelled() || isBlacklistEnabled()) {
        return;
    }
    PendingConnection connection = loginEvent.getConnection();
    String playerName = connection.getName().toLowerCase();
    loginEvent.registerIntent(plugin);
    Runnable task = () -> loadProfile(loginEvent, connection, playerName);
    ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
}
Also used : PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with PendingConnection

use of net.md_5.bungee.api.connection.PendingConnection in project ChangeSkin by games647.

the class ConnectListener method onDisconnect.

@EventHandler
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
    PendingConnection pendingConnection = disconnectEvent.getPlayer().getPendingConnection();
    UserPreference preference = plugin.endSession(pendingConnection);
    if (preference != null) {
        save(preference);
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 4 with PendingConnection

use of net.md_5.bungee.api.connection.PendingConnection in project ChangeSkin by games647.

the class InfoCommand method execute.

@Override
public void execute(CommandSender sender, String[] strings) {
    if (!(sender instanceof ProxiedPlayer)) {
        plugin.sendMessage(sender, "no-console");
        return;
    }
    ProxiedPlayer player = (ProxiedPlayer) sender;
    UserPreference preference = plugin.getLoginSession((PendingConnection) player);
    Optional<SkinModel> optSkin = preference.getTargetSkin();
    if (optSkin.isPresent()) {
        String template = plugin.getCore().getMessage("skin-info");
        sender.sendMessage(TextComponent.fromLegacyText(formatter.apply(template, optSkin.get())));
    } else {
        plugin.sendMessage(sender, "skin-not-found");
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) UserPreference(com.github.games647.changeskin.core.model.UserPreference) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Aggregations

PendingConnection (net.md_5.bungee.api.connection.PendingConnection)3 EventHandler (net.md_5.bungee.event.EventHandler)3 UserPreference (com.github.games647.changeskin.core.model.UserPreference)2 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)1 User (me.lucko.luckperms.common.model.User)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1