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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations