
Allow getting prefix for offline user (via api).
Closed this issue ยท 4 comments
Load the user in using the loadUser method in the Storage interface, and then grab the prefix as you would for an online user.
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;
}
}