Search in sources :

Example 1 with InheritanceNode

use of net.luckperms.api.node.types.InheritanceNode in project AuthMeReloaded by AuthMe.

the class LuckPermsHandler method getGroups.

@Override
public List<UserGroup> getGroups(OfflinePlayer player) {
    String playerName = player.getName();
    if (playerName == null) {
        return Collections.emptyList();
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        logger.warning("LuckPermsHandler: tried to get groups for offline user " + player.getName() + " but it isn't loaded!");
        return Collections.emptyList();
    }
    return user.getDistinctNodes().stream().filter(node -> node instanceof InheritanceNode).map(node -> (InheritanceNode) node).map(node -> {
        Group group = luckPerms.getGroupManager().getGroup(node.getGroupName());
        if (group == null) {
            return null;
        }
        return new LuckPermGroup(group, node.getContexts());
    }).filter(Objects::nonNull).sorted((o1, o2) -> sortGroups(user, o1, o2)).map(g -> new UserGroup(g.getGroup().getName(), g.getContexts().toFlattenedMap())).collect(Collectors.toList());
}
Also used : ConsoleLoggerFactory(fr.xephi.authme.output.ConsoleLoggerFactory) PermissionNode(fr.xephi.authme.permission.PermissionNode) QueryOptions(net.luckperms.api.query.QueryOptions) TimeoutException(java.util.concurrent.TimeoutException) User(net.luckperms.api.model.user.User) UserGroup(fr.xephi.authme.data.limbo.UserGroup) ContextSetFactory(net.luckperms.api.context.ContextSetFactory) CachedPermissionData(net.luckperms.api.cacheddata.CachedPermissionData) ConsoleLogger(fr.xephi.authme.ConsoleLogger) DataMutateResult(net.luckperms.api.model.data.DataMutateResult) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) PermissionsSystemType(fr.xephi.authme.permission.PermissionsSystemType) UUID(java.util.UUID) Group(net.luckperms.api.model.group.Group) QueryMode(net.luckperms.api.query.QueryMode) Collectors(java.util.stream.Collectors) LuckPermsProvider(net.luckperms.api.LuckPermsProvider) OfflinePlayer(org.bukkit.OfflinePlayer) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) LuckPerms(net.luckperms.api.LuckPerms) NodeEqualityPredicate(net.luckperms.api.node.NodeEqualityPredicate) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Group(net.luckperms.api.model.group.Group) User(net.luckperms.api.model.user.User) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) UserGroup(fr.xephi.authme.data.limbo.UserGroup)

Example 2 with InheritanceNode

use of net.luckperms.api.node.types.InheritanceNode in project AuthMeReloaded by AuthMe.

the class LuckPermsHandler method buildGroupNode.

@NotNull
private InheritanceNode buildGroupNode(UserGroup group) {
    ContextSetFactory contextSetFactory = luckPerms.getContextManager().getContextSetFactory();
    InheritanceNode.Builder builder = InheritanceNode.builder(group.getGroupName());
    if (group.getContextMap() != null) {
        group.getContextMap().forEach((k, v) -> builder.withContext((contextSetFactory.immutableOf(k, v))));
    }
    return builder.build();
}
Also used : InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ContextSetFactory(net.luckperms.api.context.ContextSetFactory) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with InheritanceNode

use of net.luckperms.api.node.types.InheritanceNode in project AuthMeReloaded by AuthMe.

the class LuckPermsHandler method setGroup.

@Override
public boolean setGroup(OfflinePlayer player, UserGroup group) {
    String playerName = player.getName();
    if (playerName == null) {
        return false;
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        logger.warning("LuckPermsHandler: tried to set group for offline user " + player.getName() + " but it isn't loaded!");
        return false;
    }
    InheritanceNode groupNode = buildGroupNode(group);
    DataMutateResult result = user.data().add(groupNode);
    if (result == DataMutateResult.FAIL) {
        return false;
    }
    user.data().clear(node -> {
        if (!(node instanceof InheritanceNode)) {
            return false;
        }
        InheritanceNode inheritanceNode = (InheritanceNode) node;
        return !inheritanceNode.equals(groupNode);
    });
    luckPerms.getUserManager().saveUser(user);
    return true;
}
Also used : User(net.luckperms.api.model.user.User) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 4 with InheritanceNode

use of net.luckperms.api.node.types.InheritanceNode in project AuthMeReloaded by AuthMe.

the class LuckPermsHandler method isInGroup.

@Override
public boolean isInGroup(OfflinePlayer player, UserGroup group) {
    String playerName = player.getName();
    if (playerName == null) {
        return false;
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        logger.warning("LuckPermsHandler: tried to check group for offline user " + player.getName() + " but it isn't loaded!");
        return false;
    }
    InheritanceNode inheritanceNode = InheritanceNode.builder(group.getGroupName()).build();
    return user.data().contains(inheritanceNode, NodeEqualityPredicate.EXACT).asBoolean();
}
Also used : User(net.luckperms.api.model.user.User) InheritanceNode(net.luckperms.api.node.types.InheritanceNode)

Example 5 with InheritanceNode

use of net.luckperms.api.node.types.InheritanceNode in project AuthMeReloaded by AuthMe.

the class LuckPermsHandler method addToGroup.

@Override
public boolean addToGroup(OfflinePlayer player, UserGroup group) {
    Group newGroup = luckPerms.getGroupManager().getGroup(group.getGroupName());
    if (newGroup == null) {
        return false;
    }
    String playerName = player.getName();
    if (playerName == null) {
        return false;
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        return false;
    }
    InheritanceNode node = buildGroupNode(group);
    DataMutateResult result = user.data().add(node);
    if (result == DataMutateResult.FAIL) {
        return false;
    }
    luckPerms.getUserManager().saveUser(user);
    return true;
}
Also used : UserGroup(fr.xephi.authme.data.limbo.UserGroup) Group(net.luckperms.api.model.group.Group) User(net.luckperms.api.model.user.User) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Aggregations

InheritanceNode (net.luckperms.api.node.types.InheritanceNode)6 User (net.luckperms.api.model.user.User)5 DataMutateResult (net.luckperms.api.model.data.DataMutateResult)3 UserGroup (fr.xephi.authme.data.limbo.UserGroup)2 ContextSetFactory (net.luckperms.api.context.ContextSetFactory)2 Group (net.luckperms.api.model.group.Group)2 NotNull (org.jetbrains.annotations.NotNull)2 ConsoleLogger (fr.xephi.authme.ConsoleLogger)1 ConsoleLoggerFactory (fr.xephi.authme.output.ConsoleLoggerFactory)1 PermissionNode (fr.xephi.authme.permission.PermissionNode)1 PermissionsSystemType (fr.xephi.authme.permission.PermissionsSystemType)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 LuckPerms (net.luckperms.api.LuckPerms)1