LuckPerms

LuckPerms

41.4k Downloads

API hasPermission and temp groups

Sir-Will opened this issue ยท 6 comments

commented

Using the method below the hasPermission() method does always return false if the user does have the group as temp group.

LuckPerms-Sponge-4.0.143

getUserAndApply(uuid, user -> {
    Node tempGroup = api.getNodeFactory().makeGroupNode(api.getGroup("tempGroup")).build();
    user.hasPermission(tempGroup).asBoolean()
});

public void getUserAndApply(UUID playerUuid, Consumer<User> action) {
    User user = api.getUser(playerUuid);
    if (user != null) {
        // user is already loaded, just apply the action
        action.accept(user);
        return;
    }

    // ok, user isn't online, so we need to load them.
    // once the user is loaded, this callback will be executed on the main thread.
    api.getStorage().loadUser(playerUuid)
            .thenAcceptAsync(wasSuccessful -> {

                // for whatever reason, the user could not be loaded.
                // this might be because the database is not accessible, or because
                // there was some other unexpected error.
                if (!wasSuccessful) {
                    return;
                }

                // ok, so the user *should* be loaded now!
                User loadedUser = api.getUser(playerUuid);
                if (loadedUser == null) {
                    // nope, still not loaded.
                    return;
                }

                // apply the action now they're loaded.
                action.accept(loadedUser);

                // tell LuckPerms that you're finished with the user, and that
                // it can unload them.

                api.cleanupUser(loadedUser);
            }, api.getStorage().getSyncExecutor());
}
commented

Temp fix, use:

 Node tempGroup = api.getNodeFactory().makeGroupNode(api.getGroup("tempGroup")).setExpiry(10L).build();

Will keep this ticket open and implement more appropriate behaviour.

commented

The setExpiry() makes the group to a temp node and the value (10L) doesn't matter?
I assume if I want to check for a normal group and temp group I need to create a node with setExpiry and one without?

commented

Yes, at the moment you do.

I'll change that.

commented

@lucko does API 5 have a better way to do this now without having to build a normal and temp node?

commented

Yeah, although you could do it in 4.4 as well.

User user = ...;
InheritanceNode groupNode = InheritanceNode.builder("group-name-here").build();
Tristate hasGroup = user.data().contains(groupNode, NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY);