use of net.luckperms.api.query.dataorder.DataQueryOrderFunction 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