Search in sources :

Example 1 with DataMutateResult

use of net.luckperms.api.model.data.DataMutateResult 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 2 with DataMutateResult

use of net.luckperms.api.model.data.DataMutateResult 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

DataMutateResult (net.luckperms.api.model.data.DataMutateResult)2 User (net.luckperms.api.model.user.User)2 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)2 UserGroup (fr.xephi.authme.data.limbo.UserGroup)1 Group (net.luckperms.api.model.group.Group)1