Search in sources :

Example 1 with DataType

use of net.luckperms.api.model.data.DataType in project LuckPerms by lucko.

the class PermissionHolder method resolveInheritedNodes.

public List<Node> resolveInheritedNodes(QueryOptions queryOptions) {
    if (!queryOptions.flag(Flag.RESOLVE_INHERITANCE)) {
        return getOwnNodes(queryOptions);
    }
    List<Node> nodes = new ArrayList<>();
    InheritanceGraph graph = this.plugin.getInheritanceGraphFactory().getGraph(queryOptions);
    for (PermissionHolder holder : graph.traverse(this)) {
        for (DataType dataType : holder.queryOrder(queryOptions)) {
            holder.getData(dataType).copyTo(nodes, queryOptions);
        }
    }
    return nodes;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ArrayList(java.util.ArrayList) DataType(net.luckperms.api.model.data.DataType) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 2 with DataType

use of net.luckperms.api.model.data.DataType in project LuckPerms by lucko.

the class PermissionHolder method resolveInheritedNodesSorted.

public SortedSet<Node> resolveInheritedNodesSorted(QueryOptions queryOptions) {
    if (!queryOptions.flag(Flag.RESOLVE_INHERITANCE)) {
        return getOwnNodesSorted(queryOptions);
    }
    SortedSet<Node> nodes = new TreeSet<>(NodeWithContextComparator.reverse());
    InheritanceGraph graph = this.plugin.getInheritanceGraphFactory().getGraph(queryOptions);
    for (PermissionHolder holder : graph.traverse(this)) {
        for (DataType dataType : holder.queryOrder(queryOptions)) {
            holder.getData(dataType).copyTo(nodes, queryOptions);
        }
    }
    return nodes;
}
Also used : TreeSet(java.util.TreeSet) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) DataType(net.luckperms.api.model.data.DataType) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 3 with DataType

use of net.luckperms.api.model.data.DataType in project LuckPerms by lucko.

the class PermissionHolder method accumulateMeta.

public MetaAccumulator accumulateMeta(MetaAccumulator accumulator, QueryOptions queryOptions) {
    InheritanceGraph graph = this.plugin.getInheritanceGraphFactory().getGraph(queryOptions);
    for (PermissionHolder holder : graph.traverse(this)) {
        // accumulate nodes
        for (DataType dataType : holder.queryOrder(queryOptions)) {
            holder.getData(dataType).forEach(queryOptions, node -> {
                if (NodeType.META_OR_CHAT_META.matches(node)) {
                    accumulator.accumulateNode(node);
                }
            });
        }
        // accumulate weight
        OptionalInt w = holder.getWeight();
        if (w.isPresent()) {
            accumulator.accumulateWeight(w.getAsInt());
        }
    }
    // accumulate primary group
    if (this instanceof User) {
        String primaryGroup = ((User) this).getPrimaryGroup().calculateValue(queryOptions);
        accumulator.setPrimaryGroup(primaryGroup);
    }
    accumulator.complete();
    return accumulator;
}
Also used : DataType(net.luckperms.api.model.data.DataType) OptionalInt(java.util.OptionalInt) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 4 with DataType

use of net.luckperms.api.model.data.DataType in project LuckPerms by lucko.

the class PermissionHolder method resolveInheritedNodes.

public <T extends Node> List<T> resolveInheritedNodes(NodeType<T> type, QueryOptions queryOptions) {
    if (!queryOptions.flag(Flag.RESOLVE_INHERITANCE)) {
        return getOwnNodes(type, queryOptions);
    }
    List<T> nodes = new ArrayList<>();
    InheritanceGraph graph = this.plugin.getInheritanceGraphFactory().getGraph(queryOptions);
    for (PermissionHolder holder : graph.traverse(this)) {
        for (DataType dataType : holder.queryOrder(queryOptions)) {
            holder.getData(dataType).copyTo(nodes, type, queryOptions);
        }
    }
    return nodes;
}
Also used : ArrayList(java.util.ArrayList) DataType(net.luckperms.api.model.data.DataType) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 5 with DataType

use of net.luckperms.api.model.data.DataType in project LuckPerms by lucko.

the class DataSelector method selectOrder.

public static DataType[] selectOrder(QueryOptions queryOptions, PermissionHolder.Identifier identifier) {
    final DataQueryOrderFunction orderFunc = queryOptions.option(DataQueryOrderFunction.KEY).orElse(null);
    final DataTypeFilterFunction filterFunc = queryOptions.option(DataTypeFilterFunction.KEY).orElse(null);
    if (orderFunc == null && filterFunc == null) {
        return TRANSIENT_NORMAL;
    }
    Predicate<DataType> predicate = filterFunc != null ? filterFunc.getTypeFilter(identifier) : DataTypeFilter.ALL;
    boolean normal = predicate.test(DataType.NORMAL);
    boolean trans = predicate.test(DataType.TRANSIENT);
    // if both are included - we need to consult the order comparator
    if (normal && trans) {
        Comparator<DataType> comparator = orderFunc != null ? orderFunc.getOrderComparator(identifier) : DataQueryOrder.TRANSIENT_FIRST;
        int compare = comparator.compare(DataType.TRANSIENT, DataType.NORMAL);
        if (compare == 0) {
            throw new IllegalStateException("Comparator " + comparator + " does not define an order between DataType.NORMAL and DataType.TRANSIENT!");
        }
        return compare > 0 ? TRANSIENT_NORMAL : NORMAL_TRANSIENT;
    }
    // otherwise, no need to worry about order
    if (normal) {
        return NORMAL;
    } else if (trans) {
        return TRANSIENT;
    } else {
        return NONE;
    }
}
Also used : DataQueryOrderFunction(net.luckperms.api.query.dataorder.DataQueryOrderFunction) DataType(net.luckperms.api.model.data.DataType) DataTypeFilterFunction(net.luckperms.api.query.dataorder.DataTypeFilterFunction)

Aggregations

DataType (net.luckperms.api.model.data.DataType)6 InheritanceGraph (me.lucko.luckperms.common.inheritance.InheritanceGraph)4 ArrayList (java.util.ArrayList)2 Node (net.luckperms.api.node.Node)2 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)2 List (java.util.List)1 Locale (java.util.Locale)1 OptionalInt (java.util.OptionalInt)1 TreeSet (java.util.TreeSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)1 BulkUpdate (me.lucko.luckperms.common.bulkupdate.BulkUpdate)1 BulkUpdateBuilder (me.lucko.luckperms.common.bulkupdate.BulkUpdateBuilder)1 UpdateAction (me.lucko.luckperms.common.bulkupdate.action.UpdateAction)1 Constraint (me.lucko.luckperms.common.bulkupdate.comparison.Constraint)1 StandardComparison (me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison)1 Query (me.lucko.luckperms.common.bulkupdate.query.Query)1 QueryField (me.lucko.luckperms.common.bulkupdate.query.QueryField)1 ChildCommand (me.lucko.luckperms.common.command.abstraction.ChildCommand)1 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)1