cn.nukkit.event.player.PlayerLoginEvent Java Examples

The following examples show how to use cn.nukkit.event.player.PlayerLoginEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
    try {
        UUID playerUUID = event.getPlayer().getUniqueId();
        boolean operator = event.getPlayer().isOp();
        dbSystem.getDatabase().executeTransaction(new OperatorStatusTransaction(playerUUID, operator));
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #2
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLoginMonitor(PlayerLoginEvent e) {
    /* Listen to see if the event was cancelled after we initially handled the login
       If the connection was cancelled here, we need to do something to clean up the data that was loaded. */

    // Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present.
    if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) {
        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (!e.isCancelled()) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getPlayer().getUniqueId());
            e.setCancelled();
        }
    }
}
 
Example #3
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin(PlayerLoginEvent e) {
    /* Called when the player starts logging into the server.
       At this point, the users data should be present and loaded. */

    final Player player = e.getPlayer();

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
    }

    final User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());

    /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
    if (user == null) {
        this.deniedLogin.add(player.getUniqueId());

        if (!getUniqueConnections().contains(player.getUniqueId())) {
            this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
                    " doesn't have data pre-loaded, they have never been processed during pre-login in this session." +
                    " - denying login.");
        } else {
            this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
                    " doesn't currently have data pre-loaded, but they have been processed before in this session." +
                    " - denying login.");
        }

        e.setCancelled();
        e.setKickMessage(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager()));
        return;
    }

    // User instance is there, now we can inject our custom Permissible into the player.
    // Care should be taken at this stage to ensure that async tasks which manipulate nukkit data check that the player is still online.
    try {
        // Make a new permissible for the user
        LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this.plugin);

        // Inject into the player
        PermissibleInjector.inject(player, lpPermissible);

    } catch (Throwable t) {
        this.plugin.getLogger().warn("Exception thrown when setting up permissions for " +
                player.getUniqueId() + " - " + player.getName() + " - denying login.");
        t.printStackTrace();

        e.setCancelled();
        e.setKickMessage(Message.LOADING_SETUP_ERROR.asString(this.plugin.getLocaleManager()));
        return;
    }

    this.plugin.getContextManager().signalContextUpdate(player);
}