Java Code Examples for net.luckperms.api.node.Node#getContexts()

The following examples show how to use net.luckperms.api.node.Node#getContexts() . 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: NodeMap.java    From LuckPerms with MIT License 6 votes vote down vote up
void add(Node node) {
    ImmutableContextSet context = node.getContexts();
    Node n = localise(node);

    SortedSet<Node> nodesInContext = this.map.computeIfAbsent(context, VALUE_SET_SUPPLIER);
    nodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
    nodesInContext.add(n);

    if (n instanceof InheritanceNode) {
        SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.computeIfAbsent(context, INHERITANCE_VALUE_SET_SUPPLIER);
        inheritanceNodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
        if (n.getValue()) {
            inheritanceNodesInContext.add((InheritanceNode) n);
        }
    }
}
 
Example 2
Source File: NodeMap.java    From LuckPerms with MIT License 5 votes vote down vote up
void remove(Node node) {
    ImmutableContextSet context = node.getContexts();
    SortedSet<Node> nodesInContext = this.map.get(context);
    if (nodesInContext != null) {
        nodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
    }

    if (node instanceof InheritanceNode) {
        SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(context);
        if (inheritanceNodesInContext != null) {
            inheritanceNodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
        }
    }
}
 
Example 3
Source File: NodeMap.java    From LuckPerms with MIT License 5 votes vote down vote up
private void removeExact(Node node) {
    ImmutableContextSet context = node.getContexts();
    SortedSet<Node> nodesInContext = this.map.get(context);
    if (nodesInContext != null) {
        nodesInContext.remove(node);
    }

    if (node instanceof InheritanceNode && node.getValue()) {
        SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(context);
        if (inheritanceNodesInContext != null) {
            inheritanceNodesInContext.remove(node);
        }
    }
}
 
Example 4
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 5
Source File: NodeCommandFactory.java    From LuckPerms with MIT License 4 votes vote down vote up
public static String undoCommand(Node node, String holder, HolderType holderType, boolean explicitGlobalContext) {
    StringBuilder sb = new StringBuilder(32);

    sb.append(holderType.toString()).append(' ').append(holder).append(' ');

    if (node instanceof InheritanceNode) {
        // command
        sb.append("parent remove");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');
        
        // value
        sb.append(((InheritanceNode) node).getGroupName());

    } else if (node.getValue() && (node instanceof ChatMetaNode<?, ?>)) {
        ChatMetaNode<?, ?> chatNode = (ChatMetaNode<?, ?>) node;

        // command
        sb.append("meta remove");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(chatNode.getMetaType().toString());
        
        // values
        sb.append(' ').append(chatNode.getPriority()).append(' ');
        appendEscaped(sb, chatNode.getMetaValue());

    } else if (node.getValue() && node instanceof MetaNode) {
        MetaNode metaNode = (MetaNode) node;
        
        // command
        sb.append("meta unset");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');

        // value
        appendEscaped(sb, metaNode.getMetaKey());

    } else {
        // command
        sb.append("permission unset");
        if (node.hasExpiry()) {
            sb.append("temp");
        }
        sb.append(' ');

        // value
        appendEscaped(sb, node.getKey());
    }

    if (!node.getContexts().isEmpty()) {
        for (Context context : node.getContexts()) {
            sb.append(' ').append(context.getKey()).append("=").append(context.getValue());
        }
    } else if (explicitGlobalContext) {
        sb.append(" global");
    }

    return sb.toString();
}