Search in sources :

Example 16 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class SearchCommand method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
    Comparison comparison = StandardComparison.parseComparison(args.get(0));
    if (comparison == null) {
        comparison = StandardComparison.EQUAL;
        args.add(0, "==");
    }
    ConstraintNodeMatcher<Node> matcher = StandardNodeMatchers.of(Constraint.of(comparison, args.get(1)));
    int page = args.getIntOrDefault(2, 1);
    Message.SEARCH_SEARCHING.send(sender, matcher.toString());
    List<NodeEntry<UUID, Node>> matchedUsers = plugin.getStorage().searchUserNodes(matcher).join();
    List<NodeEntry<String, Node>> matchedGroups = plugin.getStorage().searchGroupNodes(matcher).join();
    int users = matchedUsers.size();
    int groups = matchedGroups.size();
    Message.SEARCH_RESULT.send(sender, users + groups, users, groups);
    if (!matchedUsers.isEmpty()) {
        Map<UUID, String> uuidLookups = LoadingMap.of(u -> plugin.lookupUsername(u).orElseGet(u::toString));
        sendResult(sender, matchedUsers, uuidLookups::get, Message.SEARCH_SHOWING_USERS, HolderType.USER, label, page, comparison);
    }
    if (!matchedGroups.isEmpty()) {
        sendResult(sender, matchedGroups, Function.identity(), Message.SEARCH_SHOWING_GROUPS, HolderType.GROUP, label, page, comparison);
    }
}
Also used : NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) StandardComparison(me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison) Comparison(me.lucko.luckperms.common.bulkupdate.comparison.Comparison) Node(net.luckperms.api.node.Node) UUID(java.util.UUID) Constraint(me.lucko.luckperms.common.bulkupdate.comparison.Constraint)

Example 17 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class UserSwitchPrimaryGroup method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) {
    // cast to user
    // although this command is build as a sharedsubcommand,
    // it is only added to the listings for users.
    User user = (User) target;
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, user)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    String opt = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD);
    if (!opt.equals("stored")) {
        Message.USER_PRIMARYGROUP_WARN_OPTION.send(sender, opt);
    }
    Group group = plugin.getGroupManager().getIfLoaded(args.get(0).toLowerCase(Locale.ROOT));
    if (group == null) {
        Message.DOES_NOT_EXIST.send(sender, args.get(0).toLowerCase(Locale.ROOT));
        return;
    }
    if (ArgumentPermissions.checkContext(plugin, sender, permission, ImmutableContextSetImpl.EMPTY) || ArgumentPermissions.checkGroup(plugin, sender, target, ImmutableContextSetImpl.EMPTY) || ArgumentPermissions.checkGroup(plugin, sender, group, ImmutableContextSetImpl.EMPTY) || ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(group.getName())) {
        Message.USER_PRIMARYGROUP_ERROR_ALREADYHAS.send(sender, user, group);
        return;
    }
    Node node = Inheritance.builder(group.getName()).build();
    if (!user.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_VALUE).asBoolean()) {
        Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user, group);
        target.setNode(DataType.NORMAL, node, true);
    }
    user.getPrimaryGroup().setStoredValue(group.getName());
    Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user, group);
    LoggedAction.build().source(sender).target(user).description("parent", "switchprimarygroup", group.getName()).build().submit(plugin, sender);
    StorageAssistant.save(user, sender, plugin);
}
Also used : Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User) Node(net.luckperms.api.node.Node)

Example 18 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class PermissionCheck method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    String node = args.get(0);
    // accumulate nodes
    List<Node> own = new ArrayList<>();
    List<Node> inherited = new ArrayList<>();
    List<Node> wildcards = new ArrayList<>();
    List<Node> resolved = target.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
    for (Node n : resolved) {
        if (matches(node, n, plugin)) {
            if (isInherited(n, target)) {
                inherited.add(n);
            } else {
                own.add(n);
            }
        }
        if (matchesWildcard(node, n, plugin)) {
            wildcards.add(n);
        }
    }
    // send results
    Message.PERMISSION_CHECK_INFO_HEADER.send(sender, node);
    if (own.isEmpty()) {
        Message.PERMISSION_CHECK_INFO_NOT_DIRECTLY.send(sender, target, node);
    } else {
        for (Node n : own) {
            Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
        }
    }
    if (inherited.isEmpty()) {
        Message.PERMISSION_CHECK_INFO_NOT_INHERITED.send(sender, target, node);
    } else {
        for (Node n : inherited) {
            String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
            Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
        }
    }
    for (Node n : wildcards) {
        if (isInherited(n, target)) {
            String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
            Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
        } else {
            Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
        }
    }
    // blank line
    sender.sendMessage(Message.prefixed(Component.empty()));
    // perform a "real" check
    QueryOptions queryOptions = target.getQueryOptions();
    TristateResult checkResult = target.getCachedData().getPermissionData(queryOptions).checkPermission(node, CheckOrigin.INTERNAL);
    Tristate result = checkResult.result();
    String processor = checkResult.processorClassFriendly();
    Node cause = checkResult.node();
    ImmutableContextSet context = queryOptions.context();
    // send results
    Message.PERMISSION_CHECK_RESULT.send(sender, node, result, processor, cause, context);
}
Also used : Tristate(net.luckperms.api.util.Tristate) AbstractNode(me.lucko.luckperms.common.node.AbstractNode) Node(net.luckperms.api.node.Node) RegexPermissionNode(net.luckperms.api.node.types.RegexPermissionNode) PermissionNode(net.luckperms.api.node.types.PermissionNode) ArrayList(java.util.ArrayList) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) QueryOptions(net.luckperms.api.query.QueryOptions) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Example 19 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class PermissionUnsetTemp method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    String node = args.get(0);
    Duration duration = args.getDurationOrDefault(1, null);
    int fromIndex = duration == null ? 1 : 2;
    MutableContextSet context = args.getContextOrDefault(fromIndex, plugin);
    if (node.isEmpty()) {
        Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
    }
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    Node builtNode = NodeBuilders.determineMostApplicable(node).expiry(10L).withContext(context).build();
    if (builtNode instanceof InheritanceNode) {
        if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
            Message.COMMAND_NO_PERMISSION.send(sender);
            return;
        }
    }
    DataMutateResult.WithMergedNode result = target.unsetNode(DataType.NORMAL, builtNode, duration);
    if (result.getResult().wasSuccessful()) {
        Node mergedNode = result.getMergedNode();
        // noinspection ConstantConditions
        if (mergedNode != null) {
            Message.UNSET_TEMP_PERMISSION_SUBTRACT_SUCCESS.send(sender, mergedNode.getKey(), mergedNode.getValue(), target, mergedNode.getExpiryDuration(), context, duration);
            LoggedAction.build().source(sender).target(target).description("permission", "unsettemp", node, duration, context).build().submit(plugin, sender);
        } else {
            Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, target, context);
            LoggedAction.build().source(sender).target(target).description("permission", "unsettemp", node, context).build().submit(plugin, sender);
        }
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, target, node, context);
    }
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) Duration(java.time.Duration) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 20 with Node

use of net.luckperms.api.node.Node in project LuckPerms by lucko.

the class SpongeWildcardProcessor method hasPermission.

@Override
public TristateResult hasPermission(String permission) {
    String node = permission;
    while (true) {
        int endIndex = node.lastIndexOf(AbstractNode.NODE_SEPARATOR);
        if (endIndex == -1) {
            break;
        }
        node = node.substring(0, endIndex);
        if (!node.isEmpty()) {
            Node n = this.sourceMap.get(node);
            if (n != null) {
                return RESULT_FACTORY.result(n);
            }
        }
    }
    return TristateResult.UNDEFINED;
}
Also used : AbstractNode(me.lucko.luckperms.common.node.AbstractNode) Node(net.luckperms.api.node.Node)

Aggregations

Node (net.luckperms.api.node.Node)74 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)28 ArrayList (java.util.ArrayList)23 Map (java.util.Map)16 UUID (java.util.UUID)16 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)13 NodeEntry (me.lucko.luckperms.common.storage.misc.NodeEntry)12 MetaNode (net.luckperms.api.node.types.MetaNode)12 Group (me.lucko.luckperms.common.model.Group)11 HashMap (java.util.HashMap)10 List (java.util.List)10 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)9 Difference (me.lucko.luckperms.common.util.Difference)9 DataType (net.luckperms.api.model.data.DataType)9 Connection (java.sql.Connection)7 User (me.lucko.luckperms.common.model.User)7 MutableContextSet (net.luckperms.api.context.MutableContextSet)7 PrefixNode (net.luckperms.api.node.types.PrefixNode)7 SuffixNode (net.luckperms.api.node.types.SuffixNode)7 IOException (java.io.IOException)6