Search in sources :

Example 1 with EventHandler

use of cn.nukkit.event.EventHandler in project LuckPerms by lucko.

the class NukkitConnectionListener method onPlayerPreLogin.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerPreLogin(PlayerAsyncPreLoginEvent e) {
    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing pre-login for " + e.getUuid() + " - " + e.getName());
    }
    recordConnection(e.getUuid());
    /* 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(e.getUuid(), e.getName());
        this.plugin.getEventFactory().handleUserLoginProcess(e.getUuid(), e.getName(), user);
    } catch (Exception ex) {
        this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUuid() + " - " + e.getName());
        ex.printStackTrace();
        // deny the connection
        this.deniedAsyncLogin.add(e.getUuid());
        e.disAllow(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
    }
}
Also used : User(me.lucko.luckperms.common.model.User) EventHandler(cn.nukkit.event.EventHandler)

Example 2 with EventHandler

use of cn.nukkit.event.EventHandler in project LuckPerms by lucko.

the class NukkitConnectionListener method onPlayerQuit.

// Wait until the last priority to unload, so plugins can still perform permission checks on this event
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) {
    final Player player = e.getPlayer();
    // Remove the custom permissible
    try {
        PermissibleInjector.unInject(player, true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // Handle auto op
    if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
        player.setOp(false);
    }
    // Register with the housekeeper, so the User's instance will stick
    // around for a bit after they disconnect
    this.plugin.getUserManager().getHouseKeeper().registerUsage(player.getUniqueId());
    // force a clear of transient nodes
    this.plugin.getBootstrap().getScheduler().doAsync(() -> {
        User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
        if (user != null) {
            user.clearTransientNodes();
        }
    });
}
Also used : Player(cn.nukkit.Player) User(me.lucko.luckperms.common.model.User) EventHandler(cn.nukkit.event.EventHandler)

Example 3 with EventHandler

use of cn.nukkit.event.EventHandler in project LuckPerms by lucko.

the class NukkitPlatformListener method onWorldChange.

@EventHandler(priority = EventPriority.LOWEST)
public void onWorldChange(EntityLevelChangeEvent e) {
    if (e.getEntity() instanceof Player) {
        Player player = (Player) e.getEntity();
        this.plugin.getContextManager().invalidateCache(player);
        this.plugin.refreshAutoOp(this.plugin.getUserManager().getIfLoaded(player.getUniqueId()), player);
    }
}
Also used : Player(cn.nukkit.Player) EventHandler(cn.nukkit.event.EventHandler)

Example 4 with EventHandler

use of cn.nukkit.event.EventHandler in project LuckPerms by lucko.

the class NukkitConnectionListener method onPlayerLogin.

@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(e.getPlayer().getUniqueId());
        this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
        e.setCancelled();
        e.setKickMessage(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
        return;
    }
    // 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
        LPPermissible lpPermissible = new LPPermissible(player, user, this.plugin);
        // Inject into the player
        PermissibleInjector.inject(player, lpPermissible);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    this.plugin.refreshAutoOp(user, player);
}
Also used : LPPermissible(me.lucko.luckperms.nukkit.model.permissible.LPPermissible) Player(cn.nukkit.Player) User(me.lucko.luckperms.common.model.User) EventHandler(cn.nukkit.event.EventHandler)

Aggregations

EventHandler (cn.nukkit.event.EventHandler)4 Player (cn.nukkit.Player)3 User (me.lucko.luckperms.common.model.User)3 LPPermissible (me.lucko.luckperms.nukkit.model.permissible.LPPermissible)1