Search in sources :

Example 1 with LPPermissible

use of me.lucko.luckperms.nukkit.model.permissible.LPPermissible in project LuckPerms by lucko.

the class LPNukkitPlugin method performFinalSetup.

@Override
protected void performFinalSetup() {
    // register permissions
    try {
        PluginManager pm = this.bootstrap.getServer().getPluginManager();
        PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE;
        for (CommandPermission p : CommandPermission.values()) {
            pm.addPermission(new Permission(p.getPermission(), null, permDefault.toString()));
        }
    } catch (Exception e) {
    // this throws an exception if the plugin is /reloaded, grr
    }
    if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
        Config ops = this.bootstrap.getServer().getOps();
        ops.getKeys(false).forEach(ops::remove);
    }
    // replace the temporary executor when the Nukkit one starts
    this.bootstrap.getServer().getScheduler().scheduleTask(this.bootstrap, () -> this.bootstrap.getScheduler().setUseFallback(false), true);
    // Load any online users (in the case of a reload)
    for (Player player : this.bootstrap.getServer().getOnlinePlayers().values()) {
        this.bootstrap.getScheduler().doAsync(() -> {
            try {
                User user = this.connectionListener.loadUser(player.getUniqueId(), player.getName());
                if (user != null) {
                    this.bootstrap.getScheduler().doSync(() -> {
                        try {
                            LPPermissible lpPermissible = new LPPermissible(player, user, this);
                            PermissibleInjector.inject(player, lpPermissible);
                        } catch (Throwable t) {
                            t.printStackTrace();
                        }
                    });
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager) LPPermissible(me.lucko.luckperms.nukkit.model.permissible.LPPermissible) Player(cn.nukkit.Player) User(me.lucko.luckperms.common.model.User) PermissionDefault(me.lucko.luckperms.nukkit.model.PermissionDefault) Config(cn.nukkit.utils.Config) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Permission(cn.nukkit.permission.Permission) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission)

Example 2 with LPPermissible

use of me.lucko.luckperms.nukkit.model.permissible.LPPermissible 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

Player (cn.nukkit.Player)2 User (me.lucko.luckperms.common.model.User)2 LPPermissible (me.lucko.luckperms.nukkit.model.permissible.LPPermissible)2 EventHandler (cn.nukkit.event.EventHandler)1 Permission (cn.nukkit.permission.Permission)1 PluginManager (cn.nukkit.plugin.PluginManager)1 Config (cn.nukkit.utils.Config)1 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)1 PermissionDefault (me.lucko.luckperms.nukkit.model.PermissionDefault)1