LuckPerms

LuckPerms

41.4k Downloads

Allow getting prefix for offline user (via api).

ssamjh opened this issue ยท 4 comments

commented

As title says.

commented

Load the user in using the loadUser method in the Storage interface, and then grab the prefix as you would for an online user.

commented

Here's an example of that.

public class Test {
    private LuckPermsApi luckPerms;
    
    public String getChatMeta(UUID uuid, ChatMetaType type) {
        if (!luckPerms.getStorage().loadUser(uuid).join()) {
            // got an error whilst loading the user
            return null;
        }

        User user = luckPerms.getUser(uuid);
        if (user == null) {
            // user not loaded, even after requesting data from storage
            return null;
        }
        
        // the contexts for the lookup. if the prefix/suffix is set in a specific server, you'll need to add that here.
        Contexts contexts = Contexts.allowAll();

        MetaData metaData = user.getCachedData().getMetaData(contexts);
        String val = type == ChatMetaType.PREFIX ? metaData.getPrefix() : metaData.getSuffix();
        
        // cleanup the user now we're finished to prevent memory leaks.
        luckPerms.cleanupUser(user);
        
        return val;
    }
}
commented

Didn't get it. What exactly should I do?

commented

He literally gave a working function...
I don't understand your problem