Search in sources :

Example 1 with Group

use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.

the class ExpireTemporaryTask method run.

@Override
public void run() {
    boolean groupChanges = false;
    for (Group group : this.plugin.getGroupManager().getAll().values()) {
        if (shouldSkip(group)) {
            continue;
        }
        if (group.auditTemporaryPermissions()) {
            this.plugin.getStorage().saveGroup(group);
            groupChanges = true;
        }
    }
    for (User user : this.plugin.getUserManager().getAll().values()) {
        if (shouldSkip(user)) {
            continue;
        }
        if (user.auditTemporaryPermissions()) {
            this.plugin.getStorage().saveUser(user);
            if (!groupChanges) {
                user.getRefreshBuffer().request();
            }
        }
    }
    if (groupChanges) {
        this.plugin.getUpdateTaskBuffer().request();
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User)

Example 2 with Group

use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.

the class GroupReference method apply.

@Override
public void apply(LuckPermsPlugin plugin, Consumer<Group> consumer) {
    Group group = plugin.getGroupManager().getIfLoaded(this.id);
    if (group == null)
        return;
    consumer.accept(group);
}
Also used : Group(me.lucko.luckperms.common.model.Group)

Example 3 with Group

use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.

the class AllParentsByWeightHolder method calculateValue.

@Override
protected String calculateValue() {
    Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
    if (contexts == null) {
        contexts = this.user.getPlugin().getContextManager().getStaticContexts();
    }
    InheritanceGraph graph = this.user.getPlugin().getInheritanceHandler().getGraph(contexts);
    // fully traverse the graph, obtain a list of permission holders the user inherits from
    List<PermissionHolder> traversal = ImmutableList.copyOf(graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this.user));
    Group bestGroup = null;
    if (!traversal.isEmpty()) {
        int best = 0;
        for (PermissionHolder holder : traversal) {
            if (!(holder instanceof Group)) {
                continue;
            }
            Group g = ((Group) holder);
            int weight = g.getWeight().orElse(0);
            if (bestGroup == null || g.getWeight().orElse(0) > best) {
                bestGroup = g;
                best = weight;
            }
        }
    }
    return bestGroup == null ? null : bestGroup.getName();
}
Also used : Group(me.lucko.luckperms.common.model.Group) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Contexts(me.lucko.luckperms.api.Contexts) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 4 with Group

use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.

the class ConfigurateDao method createAndLoadGroup.

@Override
public Group createAndLoadGroup(String name) throws Exception {
    Group group = this.plugin.getGroupManager().getOrMake(name);
    group.getIoLock().lock();
    try {
        ConfigurationNode object = readFile(StorageLocation.GROUP, name);
        if (object != null) {
            Set<Node> nodes = readNodes(object).stream().map(NodeModel::toNode).collect(Collectors.toSet());
            group.setEnduringNodes(nodes);
        } else {
            ConfigurationNode data = SimpleConfigurationNode.root();
            data.getNode("name").setValue(group.getName());
            Set<NodeModel> nodes = group.getEnduringNodes().values().stream().map(NodeModel::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
            writeNodes(data, nodes);
            saveFile(StorageLocation.GROUP, name, data);
        }
    } catch (Exception e) {
        throw reportException(name, e);
    } finally {
        group.getIoLock().unlock();
    }
    group.getRefreshBuffer().requestDirectly();
    return group;
}
Also used : Group(me.lucko.luckperms.common.model.Group) NodeModel(me.lucko.luckperms.common.node.NodeModel) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) Node(me.lucko.luckperms.api.Node) IOException(java.io.IOException)

Example 5 with Group

use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.

the class WebEditor method getHolderFromIdentifier.

public static PermissionHolder getHolderFromIdentifier(LuckPermsPlugin plugin, Sender sender, String who) {
    if (who.startsWith(GROUP_ID_PATTERN)) {
        String group = who.substring(GROUP_ID_PATTERN.length());
        Group holder = plugin.getGroupManager().getIfLoaded(group);
        if (holder == null) {
            Message.APPLY_EDITS_TARGET_GROUP_NOT_EXISTS.send(sender, group);
        }
        return holder;
    } else if (who.startsWith(USER_ID_PATTERN)) {
        String user = who.substring(USER_ID_PATTERN.length());
        UUID uuid = Uuids.parseNullable(user);
        if (uuid == null) {
            Message.APPLY_EDITS_TARGET_USER_NOT_UUID.send(sender, user);
            return null;
        }
        User holder = plugin.getStorage().loadUser(uuid, null).join();
        if (holder == null) {
            Message.APPLY_EDITS_TARGET_USER_UNABLE_TO_LOAD.send(sender, uuid.toString());
        }
        return holder;
    } else {
        Message.APPLY_EDITS_TARGET_UNKNOWN.send(sender, who);
        return null;
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User) UUID(java.util.UUID)

Aggregations

Group (me.lucko.luckperms.common.model.Group)52 User (me.lucko.luckperms.common.model.User)20 Node (me.lucko.luckperms.api.Node)16 Set (java.util.Set)10 UUID (java.util.UUID)10 Track (me.lucko.luckperms.common.model.Track)10 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)10 List (java.util.List)9 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)9 Contexts (me.lucko.luckperms.api.Contexts)8 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)8 Sender (me.lucko.luckperms.common.sender.Sender)8 HashSet (java.util.HashSet)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)7 CommandResult (me.lucko.luckperms.common.command.CommandResult)7 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)7 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)7 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)7