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

The following examples show how to use net.luckperms.api.node.Node#getType() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
public Map<Set<Context>, Map<String, Boolean>> getPermanentPermissions(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, Boolean>> permanentPermissionMap = 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 = permanentPermissionMap.get(contexts);
        if (permissionEntry == null) {
            permissionEntry = new HashMap<>();
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
            permanentPermissionMap.put(contexts, permissionEntry);
        } else {
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
        }
    }

    return permanentPermissionMap;
}
 
Example 12
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
public Map<Set<Context>, Map<String, Boolean>> getPermanentPermissions(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, Boolean>> permanentPermissionMap = 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 = permanentPermissionMap.get(contexts);
        if (permissionEntry == null) {
            permissionEntry = new HashMap<>();
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
            permanentPermissionMap.put(contexts, permissionEntry);
        } else {
            permissionEntry.put(permissionNode.getPermission(), node.getValue());
        }
    }

    return permanentPermissionMap;
}
 
Example 13
Source File: LuckPermsHook.java    From DiscordSRV with GNU General Public License v3.0 5 votes vote down vote up
private void handle(NodeMutateEvent event, Node node, boolean add) {
    if (event.isUser() && node.getType() == NodeType.INHERITANCE) {
        String groupName = NodeType.INHERITANCE.cast(node).getGroupName();
        UUID uuid = ((User) event.getTarget()).getUniqueId();
        Map<String, List<String>> justModified = DiscordSRV.getPlugin()
                .getGroupSynchronizationManager().getJustModifiedGroups().getOrDefault(uuid, null);
        if (justModified != null && justModified.getOrDefault(add ? "add" : "remove", Collections.emptyList()).remove(groupName)) {
            return;
        }
        handle(((User) event.getTarget()).getUniqueId());
    }
}