LuckPerms

LuckPerms

41.4k Downloads

Getting permissions of offline UUID

BenHall-1 opened this issue ยท 5 comments

commented

Hi,

I'm trying to get the permissions of a UUID that is currently offline. I wrote the following code but it always returns false. Can you please advise whether I'm doing something wrong with the code? or whether it is a genuine bug

    public CompletableFuture<Boolean> hasPermission(String permission) {
        return Main.getLuckPermsAPI().getUserManager().loadUser(uuid)
                .thenApplyAsync(user -> {
                    ContextManager contextManager = Main.getLuckPermsAPI().getContextManager();
                    ImmutableContextSet contextSet = contextManager.getContext(user).orElseGet(contextManager::getStaticContext);
                    CachedPermissionData permissionData = user.getCachedData().getPermissionData(QueryOptions.contextual(contextSet));
                    return permissionData.checkPermission(permission).asBoolean();
                });
    }
commented

Does it work if the same player is online?

commented

No, still returns false

commented

Instead of getting the Contexts, try the query options:

contextManager.getQueryOptions(user).orElseGet(contextManager::getStaticQueryOptions);
commented

This now works.

Thank you so much :)

commented

You're very welcome.