API hasPermission and temp groups
Closed this issue ยท 6 comments
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());
}
Temp fix, use:
Node tempGroup = api.getNodeFactory().makeGroupNode(api.getGroup("tempGroup")).setExpiry(10L).build();
Will keep this ticket open and implement more appropriate behaviour.
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?
Use the same hasPermission
method, but pass https://github.com/lucko/LuckPerms/blob/master/api/src/main/java/me/lucko/luckperms/api/StandardNodeEquality.java#L67-L72
@lucko does API 5 have a better way to do this now without having to build a normal and temp node?