Search in sources :

Example 6 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class ContextManager method getPotentialContexts.

public ImmutableContextSet getPotentialContexts() {
    ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
    for (ContextCalculator<? super S> calculator : this.calculators.calculators()) {
        ContextSet potentialContexts;
        try {
            potentialContexts = calculator.estimatePotentialContexts();
        } catch (Throwable e) {
            this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst estimating potential contexts", e);
            continue;
        }
        builder.addAll(potentialContexts);
    }
    return builder.build();
}
Also used : ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) ContextSet(net.luckperms.api.context.ContextSet) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Example 7 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class MetaRemoveChatMeta 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;
    }
    int priority = args.getPriority(0);
    String meta = args.getOrDefault(1, "null");
    ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    // Handle bulk removal
    if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
        target.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && !n.hasExpiry()), false);
        Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, target, this.type, priority, context);
        LoggedAction.build().source(sender).target(target).description("meta", "remove" + this.type.name().toLowerCase(Locale.ROOT), priority, "*", context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
        return;
    }
    DataMutateResult result = target.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build());
    if (result.wasSuccessful()) {
        Message.REMOVE_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, context);
        LoggedAction.build().source(sender).target(target).description("meta", "remove" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.DOES_NOT_HAVE_CHAT_META.send(sender, target, this.type, meta, priority, context);
    }
}
Also used : DataMutateResult(net.luckperms.api.model.data.DataMutateResult) CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) ChatMetaType(net.luckperms.api.node.ChatMetaType) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Sender(me.lucko.luckperms.common.sender.Sender) TabCompletions(me.lucko.luckperms.common.command.tabcomplete.TabCompletions) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) Message(me.lucko.luckperms.common.locale.Message) GenericChildCommand(me.lucko.luckperms.common.command.abstraction.GenericChildCommand) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) Locale(java.util.Locale) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) DataType(net.luckperms.api.model.data.DataType) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 8 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class ParentSetTrack 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;
    }
    final String trackName = args.get(0).toLowerCase(Locale.ROOT);
    if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
        Message.TRACK_INVALID_ENTRY.send(sender, trackName);
        return;
    }
    Track track = StorageAssistant.loadTrack(trackName, sender, plugin);
    if (track == null) {
        return;
    }
    if (track.getSize() <= 1) {
        Message.TRACK_EMPTY.send(sender, track.getName());
        return;
    }
    int index = args.getIntOrDefault(1, -1);
    String groupName;
    if (index > 0) {
        List<String> trackGroups = track.getGroups();
        if (index - 1 >= trackGroups.size()) {
            Message.DOES_NOT_EXIST.send(sender, String.valueOf(index));
            return;
        }
        groupName = track.getGroups().get(index - 1);
    } else {
        groupName = args.getLowercase(1, DataConstraints.GROUP_NAME_TEST);
        if (!track.containsGroup(groupName)) {
            Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
            return;
        }
    }
    ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
    Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
    if (group == null) {
        return;
    }
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, group, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, track.getName(), group.getName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
    target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
    Message.SET_TRACK_PARENT_SUCCESS.send(sender, target, track.getName(), group, context);
    LoggedAction.build().source(sender).target(target).description("parent", "settrack", track.getName(), groupName, context).build().submit(plugin, sender);
    StorageAssistant.save(target, sender, plugin);
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) NodeType(net.luckperms.api.node.NodeType) DataConstraints(me.lucko.luckperms.common.storage.misc.DataConstraints) Sender(me.lucko.luckperms.common.sender.Sender) TabCompletions(me.lucko.luckperms.common.command.tabcomplete.TabCompletions) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) Message(me.lucko.luckperms.common.locale.Message) GenericChildCommand(me.lucko.luckperms.common.command.abstraction.GenericChildCommand) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Track(me.lucko.luckperms.common.model.Track) List(java.util.List) Locale(java.util.Locale) Group(me.lucko.luckperms.common.model.Group) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Inheritance(me.lucko.luckperms.common.node.types.Inheritance) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) DataType(net.luckperms.api.model.data.DataType) Group(me.lucko.luckperms.common.model.Group) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Track(me.lucko.luckperms.common.model.Track)

Example 9 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet 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 10 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class OptionUnset method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    String key = args.get(0);
    ImmutableContextSet contextSet = args.getContextOrEmpty(1);
    if (subjectData.unsetOption(contextSet, key).join()) {
        SpongeCommandUtils.sendPrefixed(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        SpongeCommandUtils.sendPrefixed(sender, "Unable to unset option. Are you sure the Subject has it set?");
    }
}
Also used : ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Aggregations

ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)35 Map (java.util.Map)10 Node (net.luckperms.api.node.Node)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)8 HashMap (java.util.HashMap)5 List (java.util.List)5 Locale (java.util.Locale)5 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)5 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)5 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)5 Difference (me.lucko.luckperms.common.util.Difference)5 DataType (net.luckperms.api.model.data.DataType)5 ImmutableList (com.google.common.collect.ImmutableList)4 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)4 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)4 GenericChildCommand (me.lucko.luckperms.common.command.abstraction.GenericChildCommand)4 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)4 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)4 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)4