net.luckperms.api.node.Node Java Examples

The following examples show how to use net.luckperms.api.node.Node. 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 6 votes vote down vote up
public Map<Set<Context>, Map<String, Boolean>> getTransientPermissions(GDPermissionHolder holder) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.transientData().toCollection();
    Map<Set<Context>, Map<String, Boolean>> transientPermissionMap = new TreeMap<Set<Context>, Map<String, Boolean>>(CONTEXT_COMPARATOR);
    for (Node node : nodes) {
        if (node.getType() != NodeType.PERMISSION) {
            continue;
        }

        final PermissionNode permissionNode = (PermissionNode) node;
        final Set<Context> contexts = getGPContexts(node.getContexts());
        Map<String, Boolean> permissionEntry = transientPermissionMap.get(contexts);
        if (permissionEntry == null) {
            permissionEntry = new HashMap<>();
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
            transientPermissionMap.put(contexts, permissionEntry);
        } else {
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
        }
    }
    return transientPermissionMap;
}
 
Example #2
Source File: PermissionHolder.java    From LuckPerms with MIT License 6 votes vote down vote up
private boolean auditTemporaryNodes(DataType dataType) {
    ImmutableCollection<? extends Node> before = getData(dataType).immutable().values();
    Set<Node> removed = new HashSet<>();

    boolean work = getData(dataType).auditTemporaryNodes(removed);
    if (work) {
        // invalidate
        invalidateCache();

        // call event
        ImmutableCollection<? extends Node> after = getData(dataType).immutable().values();
        for (Node r : removed) {
            this.plugin.getEventDispatcher().dispatchNodeRemove(r, this, dataType, before, after);
        }
    }
    return work;
}
 
Example #3
Source File: SqlStorage.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public <N extends Node> List<NodeEntry<String, N>> searchGroupNodes(ConstraintNodeMatcher<N> constraint) throws SQLException {
    PreparedStatementBuilder builder = new PreparedStatementBuilder().append(GROUP_PERMISSIONS_SELECT_PERMISSION);
    constraint.getConstraint().appendSql(builder, "permission");

    List<NodeEntry<String, N>> held = new ArrayList<>();
    try (Connection c = this.connectionFactory.getConnection()) {
        try (PreparedStatement ps = builder.build(c, this.statementProcessor)) {
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    String holder = rs.getString("name");
                    Node node = readNode(rs).toNode();

                    N match = constraint.filterConstraintMatch(node);
                    if (match != null) {
                        held.add(NodeEntry.of(holder, match));
                    }
                }
            }
        }
    }
    return held;
}
 
Example #4
Source File: NodeJsonSerializer.java    From LuckPerms with MIT License 6 votes vote down vote up
public static JsonArray serializeNodes(Collection<Node> nodes) {
    JsonArray arr = new JsonArray();
    for (Node node : nodes) {
        JsonObject attributes = new JsonObject();

        attributes.addProperty("type", node.getType().name().toLowerCase());
        attributes.addProperty("key", node.getKey());
        attributes.addProperty("value", node.getValue());

        Instant expiry = node.getExpiry();
        if (expiry != null) {
            attributes.addProperty("expiry", expiry.getEpochSecond());
        }

        if (!node.getContexts().isEmpty()) {
            attributes.add("context", ContextSetJsonSerializer.serializeContextSet(node.getContexts()));
        }

        arr.add(attributes);
    }
    return arr;
}
 
Example #5
Source File: NodeWithContextComparator.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public int compare(Node o1, Node o2) {
    if (o1.equals(o2)) {
        return 0;
    }

    int result = ContextSetComparator.normal().compare(
            o1.getContexts(),
            o2.getContexts()
    );

    if (result != 0) {
        return result;
    }

    return NodeComparator.normal().compare(o1, o2);
}
 
Example #6
Source File: LuckPermsVaultChat.java    From LuckPerms with MIT License 6 votes vote down vote up
private void setMeta(PermissionHolder holder, String key, Object value, String world) {
    if (key.equalsIgnoreCase(Prefix.NODE_KEY) || key.equalsIgnoreCase(Suffix.NODE_KEY)) {
        setChatMeta(holder, ChatMetaType.valueOf(key.toUpperCase()), value == null ? null : value.toString(), world);
        return;
    }

    holder.removeIf(DataType.NORMAL, null, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false);

    if (value == null) {
        this.vaultPermission.holderSave(holder);
        return;
    }

    Node node = Meta.builder(key, value.toString())
            .withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer())
            .withContext(DefaultContextKeys.WORLD_KEY, world == null ? "global" : world)
            .build();

    holder.setNode(DataType.NORMAL, node, true);
    this.vaultPermission.holderSave(holder);
}
 
Example #7
Source File: LuckPermsVaultChat.java    From LuckPerms with MIT License 6 votes vote down vote up
private void setChatMeta(PermissionHolder holder, ChatMetaType type, String value, String world) {
    // remove all prefixes/suffixes directly set on the user/group
    holder.removeIf(DataType.NORMAL, null, type.nodeType()::matches, false);

    if (value == null) {
        this.vaultPermission.holderSave(holder);
        return;
    }

    // find the max inherited priority & add 10
    MetaAccumulator metaAccumulator = holder.accumulateMeta(createQueryOptionsForWorldSet(world));
    int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10;

    Node node = type.builder(value, priority)
            .withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer())
            .withContext(DefaultContextKeys.WORLD_KEY, world == null ? "global" : world).build();

    holder.setNode(DataType.NORMAL, node, true);
    this.vaultPermission.holderSave(holder);
}
 
Example #8
Source File: MongoStorage.java    From LuckPerms with MIT License 6 votes vote down vote up
private static Document nodeToDoc(Node node) {
    Document document = new Document();

    document.append("key", node.getKey());
    document.append("value", node.getValue());

    Instant expiry = node.getExpiry();
    if (expiry != null) {
        document.append("expiry", expiry.getEpochSecond());
    }

    if (!node.getContexts().isEmpty()) {
        document.append("context", contextSetToDocs(node.getContexts()));
    }

    return document;
}
 
Example #9
Source File: PermissionInfo.java    From LuckPerms with MIT License 6 votes vote down vote up
private static Consumer<ComponentBuilder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
    HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
            "§3> " + (node.getValue() ? "§a" : "§c") + node.getKey(),
            " ",
            "§7Click to remove this node from " + holder.getPlainDisplayName()
    ), '§'));

    String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
    boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
    String command = "/" + label + " " + NodeCommandFactory.undoCommand(node, id, holder.getType(), explicitGlobalContext);
    ClickEvent clickEvent = ClickEvent.suggestCommand(command);

    return component -> {
        component.hoverEvent(hoverEvent);
        component.clickEvent(clickEvent);
    };
}
 
Example #10
Source File: PermissionHolder.java    From LuckPerms with MIT License 6 votes vote down vote up
public DataMutateResult setNode(DataType dataType, Node node, boolean callEvent) {
    if (hasNode(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) {
        return DataMutateResult.FAIL_ALREADY_HAS;
    }

    NodeMap data = getData(dataType);

    ImmutableCollection<? extends Node> before = data.immutable().values();

    data.add(node);
    invalidateCache();

    ImmutableCollection<? extends Node> after = data.immutable().values();
    if (callEvent) {
        this.plugin.getEventDispatcher().dispatchNodeAdd(node, this, dataType, before, after);
    }

    return DataMutateResult.SUCCESS;
}
 
Example #11
Source File: NodeJsonSerializer.java    From LuckPerms with MIT License 6 votes vote down vote up
public static Set<Node> deserializeNodes(JsonArray arr) {
    Set<Node> nodes = new HashSet<>();
    for (JsonElement ent : arr) {
        JsonObject attributes = ent.getAsJsonObject();

        String key = attributes.get("key").getAsString();
        boolean value = attributes.get("value").getAsBoolean();

        NodeBuilder<?, ?> builder = NodeBuilders.determineMostApplicable(key).value(value);

        if (attributes.has("expiry")) {
            builder.expiry(attributes.get("expiry").getAsLong());
        }

        if (attributes.has("context")) {
            builder.context(ContextSetJsonSerializer.deserializeContextSet(attributes.get("context")));
        }

        nodes.add(builder.build());
    }
    return nodes;
}
 
Example #12
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 6 votes vote down vote up
public Map<String, String> getPermanentOptions(GDPermissionHolder holder, Set<Context> contexts) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.data().toCollection();
    final Map<String, String> options = new HashMap<>();
    for (Node node : nodes) {
        if (node.getType() != NodeType.META) {
            continue;
        }

        final MetaNode metaNode = (MetaNode) node;
        if (contexts == null) {
            options.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        } else if (getGPContexts(node.getContexts()).containsAll(contexts)) {
            options.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        }
    }
    return options;
}
 
Example #13
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 6 votes vote down vote up
public Map<Set<Context>, Map<String, String>> getPermanentOptions(GDPermissionHolder holder) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.data().toCollection();
    Map<Set<Context>, Map<String, String>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, String>>(CONTEXT_COMPARATOR);
    for (Node node : nodes) {
        if (node.getType() != NodeType.META) {
            continue;
        }

        final MetaNode metaNode = (MetaNode) node;
        final Set<Context> contexts = getGPContexts(node.getContexts());
        Map<String, String> metaEntry = permanentPermissionMap.get(contexts);
        if (metaEntry == null) {
            metaEntry = new HashMap<>();
            metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue());
            permanentPermissionMap.put(contexts, metaEntry);
        } else {
            metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        }
    }
    return permanentPermissionMap;
}
 
Example #14
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 6 votes vote down vote up
public Map<Set<Context>, Map<String, String>> getPermanentOptions(GDPermissionHolder holder) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.data().toCollection();
    Map<Set<Context>, Map<String, String>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, String>>(CONTEXT_COMPARATOR);
    for (Node node : nodes) {
        if (node.getType() != NodeType.META) {
            continue;
        }

        final MetaNode metaNode = (MetaNode) node;
        final Set<Context> contexts = getGPContexts(node.getContexts());
        Map<String, String> metaEntry = permanentPermissionMap.get(contexts);
        if (metaEntry == null) {
            metaEntry = new HashMap<>();
            metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue());
            permanentPermissionMap.put(contexts, metaEntry);
        } else {
            metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        }
    }
    return permanentPermissionMap;
}
 
Example #15
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 6 votes vote down vote up
public Map<Set<Context>, Map<String, String>> getTransientOptions(GDPermissionHolder holder) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.transientData().toCollection();
    Map<Set<Context>, Map<String, String>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, String>>(CONTEXT_COMPARATOR);
    for (Node node : nodes) {
        if (node.getType() != NodeType.META) {
            continue;
        }

        final MetaNode metaNode = (MetaNode) node;
        final Set<Context> contexts = getGPContexts(node.getContexts());
        Map<String, String> metaEntry = permanentPermissionMap.get(contexts);
        if (metaEntry == null) {
            metaEntry = new HashMap<>();
            metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue());
            permanentPermissionMap.put(contexts, metaEntry);
        } else {
            metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        }
    }
    return permanentPermissionMap;
}
 
Example #16
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 6 votes vote down vote up
public Map<String, String> getPermanentOptions(GDPermissionHolder holder, Set<Context> contexts) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.data().toCollection();
    final Map<String, String> options = new HashMap<>();
    for (Node node : nodes) {
        if (node.getType() != NodeType.META) {
            continue;
        }

        final MetaNode metaNode = (MetaNode) node;
        if (contexts == null) {
            options.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        } else if (getGPContexts(node.getContexts()).containsAll(contexts)) {
            options.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        }
    }
    return options;
}
 
Example #17
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 6 votes vote down vote up
public Map<String, String> getTransientOptions(GDPermissionHolder holder, Set<Context> contexts) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.transientData().toCollection();
    final Map<String, String> options = new HashMap<>();
    for (Node node : nodes) {
        if (node.getType() != NodeType.META) {
            continue;
        }

        final MetaNode metaNode = (MetaNode) node;
        if (contexts == null) {
            options.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        } else if (getGPContexts(node.getContexts()).containsAll(contexts)) {
            options.put(metaNode.getMetaKey(), metaNode.getMetaValue());
        }
    }
    return options;
}
 
Example #18
Source File: MongoStorage.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
    List<NodeEntry<UUID, N>> held = new ArrayList<>();
    MongoCollection<Document> c = this.database.getCollection(this.prefix + "users");
    try (MongoCursor<Document> cursor = c.find().iterator()) {
        while (cursor.hasNext()) {
            Document d = cursor.next();
            UUID holder = getDocumentId(d);

            Set<Node> nodes = new HashSet<>(nodesFromDoc(d));
            for (Node e : nodes) {
                N match = constraint.match(e);
                if (match != null) {
                    held.add(NodeEntry.of(holder, match));
                }
            }
        }
    }
    return held;
}
 
Example #19
Source File: MongoStorage.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public <N extends Node> List<NodeEntry<String, N>> searchGroupNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
    List<NodeEntry<String, N>> held = new ArrayList<>();
    MongoCollection<Document> c = this.database.getCollection(this.prefix + "groups");
    try (MongoCursor<Document> cursor = c.find().iterator()) {
        while (cursor.hasNext()) {
            Document d = cursor.next();
            String holder = d.getString("_id");

            Set<Node> nodes = new HashSet<>(nodesFromDoc(d));
            for (Node e : nodes) {
                N match = constraint.match(e);
                if (match != null) {
                    held.add(NodeEntry.of(holder, match));
                }
            }
        }
    }
    return held;
}
 
Example #20
Source File: NodeMap.java    From LuckPerms with MIT License 6 votes vote down vote up
public void forEach(QueryOptions filter, Consumer<? super Node> consumer) {
    for (Map.Entry<ImmutableContextSet, SortedSet<Node>> e : this.map.entrySet()) {
        if (!filter.satisfies(e.getKey(), defaultSatisfyMode())) {
            continue;
        }

        if (normalNodesExcludeTest(filter, e.getKey())) {
            if (inheritanceNodesIncludeTest(filter, e.getKey())) {
                // only copy inheritance nodes.
                SortedSet<InheritanceNode> inheritanceNodes = this.inheritanceMap.get(e.getKey());
                if (inheritanceNodes != null) {
                    inheritanceNodes.forEach(consumer);
                }
            }
        } else {
            e.getValue().forEach(consumer);
        }
    }
}
 
Example #21
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 6 votes vote down vote up
public Map<Set<Context>, Map<String, Boolean>> getTransientPermissions(GDPermissionHolder holder) {
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new HashMap<>();
    }

    final Collection<Node> nodes = permissionHolder.transientData().toCollection();
    Map<Set<Context>, Map<String, Boolean>> transientPermissionMap = new TreeMap<Set<Context>, Map<String, Boolean>>(CONTEXT_COMPARATOR);
    for (Node node : nodes) {
        if (node.getType() != NodeType.PERMISSION) {
            continue;
        }

        final PermissionNode permissionNode = (PermissionNode) node;
        final Set<Context> contexts = getGPContexts(node.getContexts());
        Map<String, Boolean> permissionEntry = transientPermissionMap.get(contexts);
        if (permissionEntry == null) {
            permissionEntry = new HashMap<>();
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
            transientPermissionMap.put(contexts, permissionEntry);
        } else {
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
        }
    }
    return transientPermissionMap;
}
 
Example #22
Source File: AbstractNode.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public boolean equals(@NonNull Node o, @NonNull NodeEqualityPredicate equalityPredicate) {
    AbstractNode<?, ?> other = (AbstractNode<?, ?>) o;
    if (equalityPredicate == NodeEqualityPredicate.EXACT) {
        return Equality.KEY_VALUE_EXPIRY_CONTEXTS.equals(this, other);
    } else if (equalityPredicate == NodeEqualityPredicate.IGNORE_VALUE) {
        return Equality.KEY_EXPIRY_CONTEXTS.equals(this, other);
    } else if (equalityPredicate == NodeEqualityPredicate.IGNORE_EXPIRY_TIME) {
        return Equality.KEY_VALUE_HASEXPIRY_CONTEXTS.equals(this, other);
    } else if (equalityPredicate == NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE) {
        return Equality.KEY_HASEXPIRY_CONTEXTS.equals(this, other);
    } else if (equalityPredicate == NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY) {
        return Equality.KEY_CONTEXTS.equals(this, other);
    } else if (equalityPredicate == NodeEqualityPredicate.ONLY_KEY) {
        return Equality.KEY.equals(this, other);
    } else {
        return equalityPredicate.areEqual(this, o);
    }
}
 
Example #23
Source File: PermissionHolder.java    From LuckPerms with MIT License 5 votes vote down vote up
public SortedSet<Node> getOwnNodesSorted(QueryOptions queryOptions) {
    SortedSet<Node> nodes = new TreeSet<>(NodeWithContextComparator.reverse());
    for (DataType dataType : queryOrder(queryOptions)) {
        getData(dataType).copyTo(nodes, queryOptions);
    }
    return nodes;
}
 
Example #24
Source File: SpongeUserManager.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(String permission) {
    return CompletableFuture.supplyAsync(() -> {
        ImmutableMap.Builder<LPSubjectReference, Boolean> builder = ImmutableMap.builder();

        List<NodeEntry<UUID, Node>> lookup = this.plugin.getStorage().searchUserNodes(StandardNodeMatchers.key(permission)).join();
        for (NodeEntry<UUID, Node> holder : lookup) {
            if (holder.getNode().getContexts().equals(ImmutableContextSetImpl.EMPTY)) {
                builder.put(getService().getReferenceFactory().obtain(getIdentifier(), holder.getHolder().toString()), holder.getNode().getValue());
            }
        }

        return builder.build();
    }, this.plugin.getBootstrap().getScheduler().async());
}
 
Example #25
Source File: MessageUtils.java    From LuckPerms with MIT License 5 votes vote down vote up
/**
 * Produces a string representing a Nodes context, suitable for appending onto another message line.
 *
 * @param localeManager the locale manager
 * @param node the node to query context from
 * @return a string representing the nodes context, or an empty string if the node applies globally.
 */
public static String getAppendableNodeContextString(LocaleManager localeManager, Node node) {
    StringBuilder sb = new StringBuilder();
    for (Context c : node.getContexts()) {
        sb.append(" ").append(contextToString(localeManager, c.getKey(), c.getValue()));
    }
    return sb.toString();
}
 
Example #26
Source File: ApiGroupManager.java    From LuckPerms with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public @NonNull <T extends Node> CompletableFuture<Map<String, Collection<T>>> searchAll(@NonNull NodeMatcher<? extends T> matcher) {
    Objects.requireNonNull(matcher, "matcher");
    ConstraintNodeMatcher<? extends T> constraint = (ConstraintNodeMatcher<? extends T>) matcher;
    return this.plugin.getStorage().searchGroupNodes(constraint).thenApply(list -> {
        ImmutableListMultimap.Builder<String, T> builder = ImmutableListMultimap.builder();
        for (NodeEntry<String, ? extends T> row : list) {
            builder.put(row.getHolder(), row.getNode());
        }
        return builder.build().asMap();
    });
}
 
Example #27
Source File: LogNotify.java    From LuckPerms with MIT License 5 votes vote down vote up
public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {
    User user = plugin.getUserManager().getIfLoaded(uuid);
    if (user == null) {
        return false;
    }

    Optional<? extends Node> node = user.normalData().immutable().get(ImmutableContextSetImpl.EMPTY).stream()
            .filter(n -> n.getKey().equalsIgnoreCase(IGNORE_NODE))
            .findFirst();

    // if they don't have the perm, they're not ignoring
    // if set to false, ignore it, return false
    return node.map(Node::getValue).orElse(false);
}
 
Example #28
Source File: PermissionHolder.java    From LuckPerms with MIT License 5 votes vote down vote up
public DataMutateResult unsetNode(DataType dataType, Node node) {
    if (hasNode(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE) == Tristate.UNDEFINED) {
        return DataMutateResult.FAIL_LACKS;
    }

    ImmutableCollection<? extends Node> before = getData(dataType).immutable().values();

    getData(dataType).remove(node);
    invalidateCache();

    ImmutableCollection<? extends Node> after = getData(dataType).immutable().values();
    this.plugin.getEventDispatcher().dispatchNodeRemove(node, this, dataType, before, after);

    return DataMutateResult.SUCCESS;
}
 
Example #29
Source File: ApiUserManager.java    From LuckPerms with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends Node> @NonNull CompletableFuture<Map<UUID, Collection<T>>> searchAll(@NonNull NodeMatcher<? extends T> matcher) {
    Objects.requireNonNull(matcher, "matcher");
    ConstraintNodeMatcher<? extends T> constraint = (ConstraintNodeMatcher<? extends T>) matcher;
    return this.plugin.getStorage().searchUserNodes(constraint).thenApply(list -> {
        ImmutableListMultimap.Builder<UUID, T> builder = ImmutableListMultimap.builder();
        for (NodeEntry<UUID, ? extends T> row : list) {
            builder.put(row.getHolder(), row.getNode());
        }
        return builder.build().asMap();
    });
}
 
Example #30
Source File: SearchCommand.java    From LuckPerms with MIT License 5 votes vote down vote up
private static String getNodeExpiryString(Node node) {
    if (!node.hasExpiry()) {
        return "";
    }

    return " &8(&7expires in " + DurationFormatter.LONG.format(node.getExpiryDuration()) + "&8)";
}