Search in sources :

Example 41 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method exportNodesAndShorthand.

public Map<String, Boolean> exportNodesAndShorthand(boolean lowerCase) {
    List<LocalizedNode> entries = resolveInheritances();
    Map<String, Boolean> perms = new HashMap<>();
    boolean applyShorthand = this.plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND);
    for (Node node : entries) {
        String perm = lowerCase ? node.getPermission().toLowerCase().intern() : node.getPermission();
        if (perms.putIfAbsent(perm, node.getValuePrimitive()) == null && applyShorthand) {
            List<String> shorthand = node.resolveShorthand();
            if (!shorthand.isEmpty()) {
                for (String s : shorthand) {
                    perms.putIfAbsent((lowerCase ? s.toLowerCase() : s).intern(), node.getValuePrimitive());
                }
            }
        }
    }
    return ImmutableMap.copyOf(perms);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode)

Example 42 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method accumulateMeta.

public MetaAccumulator accumulateMeta(MetaAccumulator accumulator) {
    if (accumulator == null) {
        accumulator = MetaAccumulator.makeFromConfig(this.plugin);
    }
    InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph();
    Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
    for (PermissionHolder holder : traversal) {
        List<Node> nodes = holder.getOwnNodes();
        for (Node node : nodes) {
            if (!node.getValuePrimitive())
                continue;
            if (!node.isMeta() && !node.isPrefix() && !node.isSuffix())
                continue;
            accumulator.accumulateNode(ImmutableLocalizedNode.of(node, holder.getObjectName()));
        }
        OptionalInt w = getWeight();
        if (w.isPresent()) {
            accumulator.accumulateWeight(w.getAsInt());
        }
    }
    return accumulator;
}
Also used : LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) OptionalInt(java.util.OptionalInt) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 43 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class ConfigurateDao method loadGroup.

@Override
public Optional<Group> loadGroup(String name) throws Exception {
    Group group = this.plugin.getGroupManager().getIfLoaded(name);
    if (group != null) {
        group.getIoLock().lock();
    }
    try {
        ConfigurationNode object = readFile(StorageLocation.GROUP, name);
        if (object == null) {
            return Optional.empty();
        }
        if (group == null) {
            group = this.plugin.getGroupManager().getOrMake(name);
            group.getIoLock().lock();
        }
        Set<NodeModel> data = readNodes(object);
        Set<Node> nodes = data.stream().map(NodeModel::toNode).collect(Collectors.toSet());
        group.setEnduringNodes(nodes);
    } catch (Exception e) {
        throw reportException(name, e);
    } finally {
        if (group != null) {
            group.getIoLock().unlock();
        }
    }
    group.getRefreshBuffer().requestDirectly();
    return Optional.of(group);
}
Also used : Group(me.lucko.luckperms.common.model.Group) NodeModel(me.lucko.luckperms.common.node.NodeModel) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) Node(me.lucko.luckperms.api.Node) IOException(java.io.IOException)

Example 44 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class AbstractUserManager method giveDefaultIfNeeded.

@Override
public boolean giveDefaultIfNeeded(User user, boolean save) {
    boolean work = false;
    // check that they are actually a member of their primary group, otherwise remove it
    if (this.plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD).equals("stored")) {
        String pg = user.getPrimaryGroup().getValue();
        boolean has = false;
        for (Node node : user.getEnduringNodes().get(ImmutableContextSet.empty())) {
            if (node.isGroupNode() && node.getGroupName().equalsIgnoreCase(pg)) {
                has = true;
                break;
            }
        }
        // need to find a new primary group for the user.
        if (!has) {
            String group = user.getEnduringNodes().get(ImmutableContextSet.empty()).stream().filter(Node::isGroupNode).findFirst().map(Node::getGroupName).orElse(null);
            // if the group is null, it'll be resolved in the next step
            if (group != null) {
                user.getPrimaryGroup().setStoredValue(group);
                work = true;
            }
        }
    }
    // check that all users are member of at least one group
    boolean hasGroup = false;
    if (user.getPrimaryGroup().getStoredValue().isPresent()) {
        for (Node node : user.getEnduringNodes().values()) {
            if (node.hasSpecificContext()) {
                continue;
            }
            if (node.isGroupNode()) {
                hasGroup = true;
                break;
            }
        }
    }
    if (!hasGroup) {
        user.getPrimaryGroup().setStoredValue(NodeFactory.DEFAULT_GROUP_NAME);
        user.setPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build());
        work = true;
    }
    if (work && save) {
        this.plugin.getStorage().saveUser(user);
    }
    return work;
}
Also used : Node(me.lucko.luckperms.api.Node)

Example 45 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class LogNotify method isIgnoring.

public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {
    User user = plugin.getUserManager().getIfLoaded(uuid);
    if (user == null) {
        return false;
    }
    Optional<Node> ret = user.getOwnNodes().stream().filter(n -> n.getPermission().equalsIgnoreCase("luckperms.log.notify.ignoring")).findFirst();
    // if set to false, ignore it, return false
    return ret.map(Node::getValuePrimitive).orElse(false);
}
Also used : SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) Log(me.lucko.luckperms.common.actionlog.Log) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) CommandResult(me.lucko.luckperms.common.command.CommandResult) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) List(java.util.List) Message(me.lucko.luckperms.common.locale.message.Message) Optional(java.util.Optional) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Node(me.lucko.luckperms.api.Node) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) User(me.lucko.luckperms.common.model.User) Node(me.lucko.luckperms.api.Node)

Aggregations

Node (me.lucko.luckperms.api.Node)56 LocalizedNode (me.lucko.luckperms.api.LocalizedNode)15 Group (me.lucko.luckperms.common.model.Group)15 User (me.lucko.luckperms.common.model.User)13 Map (java.util.Map)12 ImmutableLocalizedNode (me.lucko.luckperms.common.node.ImmutableLocalizedNode)12 List (java.util.List)11 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)10 Message (me.lucko.luckperms.common.locale.message.Message)9 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)9 Sender (me.lucko.luckperms.common.sender.Sender)9 Collectors (java.util.stream.Collectors)8 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)8 CommandResult (me.lucko.luckperms.common.command.CommandResult)8 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)8 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)8 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)8 Predicates (me.lucko.luckperms.common.utils.Predicates)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7