Java Code Examples for net.luckperms.api.context.ContextSet#size()

The following examples show how to use net.luckperms.api.context.ContextSet#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
private void clearMeta(PermissionHolder holder, String metaKey, ContextSet set) {
    if (set.size() == 1 && set.containsKey("server")) {
        if (set.getAnyValue("server").get().equalsIgnoreCase("global")) {
            // LP does not remove meta if passing only global context so we need to make sure to pass none
            holder.data().clear(NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey)));
            return;
        }
    }
    holder.data().clear(set, NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey)));
}
 
Example 2
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
private void clearMeta(PermissionHolder holder, String metaKey, ContextSet set) {
    if (set.size() == 1 && set.containsKey("server")) {
        if (set.getAnyValue("server").get().equalsIgnoreCase("global")) {
            // LP does not remove meta if passing only global context so we need to make sure to pass none
            holder.data().clear(NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey)));
            return;
        }
    }
    holder.data().clear(set, NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey)));
}
 
Example 3
Source File: AbstractContextSet.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public boolean isSatisfiedBy(@NonNull ContextSet other, @NonNull ContextSatisfyMode mode) {
    if (this == other) {
        return true;
    }

    Objects.requireNonNull(other, "other");
    Objects.requireNonNull(mode, "mode");

    // this is empty, it is always satisfied.
    if (this.isEmpty()) {
        return true;
    }

    // if this set isn't empty, but the other one is, then it can't be satisfied by it.
    if (other.isEmpty()) {
        return false;
    }

    // if mode is ALL_VALUES & this set has more entries than the other one, then it can't be satisfied by it.
    if (mode == ContextSatisfyMode.ALL_VALUES_PER_KEY && this.size() > other.size()) {
        return false;
    }

    // return true if 'other' contains all of 'this', according to the mode.
    return otherContainsAll(other, mode);
}
 
Example 4
Source File: MongoStorage.java    From LuckPerms with MIT License 5 votes vote down vote up
private static List<Document> contextSetToDocs(ContextSet contextSet) {
    List<Document> contexts = new ArrayList<>(contextSet.size());
    for (Context e : contextSet) {
        contexts.add(new Document().append("key", e.getKey()).append("value", e.getValue()));
    }
    return contexts;
}