Search in sources :

Example 11 with User

use of me.lucko.luckperms.common.model.User 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 12 with User

use of me.lucko.luckperms.common.model.User 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 13 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class LuckPermsMessagingService method consumeIncomingMessage.

@Override
public boolean consumeIncomingMessage(@Nonnull Message message) {
    Objects.requireNonNull(message, "message");
    if (message instanceof UpdateMessage) {
        UpdateMessage msg = (UpdateMessage) message;
        if (!this.receivedMessages.add(msg.getId())) {
            return false;
        }
        this.plugin.getLogger().info("[" + getName() + " Messaging] Received update ping with id: " + msg.getId());
        if (this.plugin.getEventFactory().handleNetworkPreSync(false, msg.getId())) {
            return true;
        }
        this.plugin.getUpdateTaskBuffer().request();
        return true;
    } else if (message instanceof UserUpdateMessage) {
        UserUpdateMessage msg = (UserUpdateMessage) message;
        if (!this.receivedMessages.add(msg.getId())) {
            return false;
        }
        User user = this.plugin.getUserManager().getIfLoaded(msg.getUser());
        if (user == null) {
            return true;
        }
        this.plugin.getLogger().info("[" + getName() + " Messaging] Received user update ping for '" + user.getFriendlyName() + "' with id: " + msg.getId());
        if (this.plugin.getEventFactory().handleNetworkPreSync(false, msg.getId())) {
            return true;
        }
        this.plugin.getStorage().loadUser(user.getUuid(), null);
        return true;
    } else if (message instanceof LogMessage) {
        LogMessage msg = (LogMessage) message;
        if (!this.receivedMessages.add(msg.getId())) {
            return false;
        }
        this.plugin.getEventFactory().handleLogReceive(msg.getId(), msg.getLogEntry());
        this.plugin.getLogDispatcher().dispatchFromRemote((ExtendedLogEntry) msg.getLogEntry());
        return true;
    } else {
        this.plugin.getLogger().warn("Unable to decode incoming message: " + message + " (" + message.getClass().getName() + ")");
        return false;
    }
}
Also used : UserUpdateMessage(me.lucko.luckperms.api.messenger.message.type.UserUpdateMessage) UpdateMessage(me.lucko.luckperms.api.messenger.message.type.UpdateMessage) UserUpdateMessage(me.lucko.luckperms.api.messenger.message.type.UserUpdateMessage) User(me.lucko.luckperms.common.model.User) LogMessage(me.lucko.luckperms.api.messenger.message.type.LogMessage)

Example 14 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class TreeCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    String selection = ".";
    String player = null;
    if (!args.isEmpty()) {
        selection = args.get(0);
    }
    if (args.size() > 1) {
        player = args.get(1);
    }
    User user;
    if (player != null) {
        UUID u = Uuids.parseNullable(player);
        if (u != null) {
            user = plugin.getUserManager().getIfLoaded(u);
        } else {
            user = plugin.getUserManager().getByUsername(player);
        }
        if (user == null) {
            Message.USER_NOT_ONLINE.send(sender, player);
            return CommandResult.STATE_ERROR;
        }
    } else {
        user = null;
    }
    TreeView view = new TreeView(plugin.getPermissionVault(), selection);
    if (!view.hasData()) {
        Message.TREE_EMPTY.send(sender);
        return CommandResult.FAILURE;
    }
    Message.TREE_UPLOAD_START.send(sender);
    PermissionCache permissionData = user == null ? null : user.getCachedData().getPermissionData(plugin.getContextForUser(user).orElse(plugin.getContextManager().getStaticContexts()));
    String id = view.uploadPasteData(sender, user, permissionData);
    String url = plugin.getConfiguration().get(ConfigKeys.TREE_VIEWER_URL_PATTERN) + "?" + id;
    Message.TREE_URL.send(sender);
    Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(url))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the tree view.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) User(me.lucko.luckperms.common.model.User) ClickEvent(net.kyori.text.event.ClickEvent) TreeView(me.lucko.luckperms.common.treeview.TreeView) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) UUID(java.util.UUID) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component)

Example 15 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class LPBukkitPlugin method removePlatformHooks.

@Override
protected void removePlatformHooks() {
    // uninject from players
    for (Player player : this.bootstrap.getServer().getOnlinePlayers()) {
        try {
            PermissibleInjector.unInject(player, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
            player.setOp(false);
        }
        final User user = getUserManager().getIfLoaded(player.getUniqueId());
        if (user != null) {
            user.getCachedData().invalidateCaches();
            getUserManager().unload(user);
        }
    }
    // uninject custom maps
    InjectorSubscriptionMap.uninject();
    InjectorPermissionMap.uninject();
    InjectorDefaultsMap.uninject();
    // unhook vault
    if (this.vaultHookManager != null) {
        this.vaultHookManager.unhook(this);
    }
}
Also used : Player(org.bukkit.entity.Player) User(me.lucko.luckperms.common.model.User)

Aggregations

User (me.lucko.luckperms.common.model.User)67 Group (me.lucko.luckperms.common.model.Group)20 UUID (java.util.UUID)16 Node (me.lucko.luckperms.api.Node)14 Contexts (me.lucko.luckperms.api.Contexts)10 List (java.util.List)9 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)9 Tristate (me.lucko.luckperms.api.Tristate)8 Track (me.lucko.luckperms.common.model.Track)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)7 ProgressLogger (me.lucko.luckperms.common.logging.ProgressLogger)7 Sender (me.lucko.luckperms.common.sender.Sender)7 Map (java.util.Map)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)6 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)5 CommandResult (me.lucko.luckperms.common.command.CommandResult)5 SubCommand (me.lucko.luckperms.common.command.abstraction.SubCommand)5