Search in sources :

Example 26 with MutableContextSet

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

the class ParentAdd 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 groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
    MutableContextSet context = args.getContextOrDefault(1, plugin);
    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, group.getName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    DataMutateResult result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
    if (result.wasSuccessful()) {
        Message.SET_INHERIT_SUCCESS.send(sender, target, group, context);
        LoggedAction.build().source(sender).target(target).description("parent", "add", group.getName(), context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.ALREADY_INHERITS.send(sender, target, group, context);
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) MutableContextSet(net.luckperms.api.context.MutableContextSet) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 27 with MutableContextSet

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

the class PermissionSet 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);
    boolean value = args.getBooleanOrInsert(1, true);
    MutableContextSet context = args.getContextOrDefault(2, 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).value(value).withContext(context).build();
    if (builtNode instanceof InheritanceNode) {
        if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
            Message.COMMAND_NO_PERMISSION.send(sender);
            return;
        }
    }
    DataMutateResult result = target.setNode(DataType.NORMAL, builtNode, true);
    if (result.wasSuccessful()) {
        Message.SETPERMISSION_SUCCESS.send(sender, node, value, target, context);
        LoggedAction.build().source(sender).target(target).description("permission", "set", node, value, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.ALREADY_HASPERMISSION.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) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 28 with MutableContextSet

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

the class ContextSetConfigurateSerializer method deserializeContextSet.

public static ContextSet deserializeContextSet(ConfigurationNode data) {
    Preconditions.checkArgument(data.isMap());
    Map<Object, ? extends ConfigurationNode> dataMap = data.getChildrenMap();
    if (dataMap.isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }
    MutableContextSet map = new MutableContextSetImpl();
    for (Map.Entry<Object, ? extends ConfigurationNode> e : dataMap.entrySet()) {
        String k = e.getKey().toString();
        ConfigurationNode v = e.getValue();
        if (v.isList()) {
            for (ConfigurationNode value : v.getChildrenList()) {
                map.add(k, value.getString());
            }
        } else {
            map.add(k, v.getString());
        }
    }
    return map;
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) MutableContextSet(net.luckperms.api.context.MutableContextSet) MutableContextSetImpl(me.lucko.luckperms.common.context.MutableContextSetImpl) Map(java.util.Map)

Aggregations

MutableContextSet (net.luckperms.api.context.MutableContextSet)28 DataMutateResult (net.luckperms.api.model.data.DataMutateResult)13 Node (net.luckperms.api.node.Node)8 Duration (java.time.Duration)7 List (java.util.List)6 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)6 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)6 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)6 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)6 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)6 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)6 TabCompletions (me.lucko.luckperms.common.command.tabcomplete.TabCompletions)6 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)6 StorageAssistant (me.lucko.luckperms.common.command.utils.StorageAssistant)6 Message (me.lucko.luckperms.common.locale.Message)6 Group (me.lucko.luckperms.common.model.Group)6 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)6 Sender (me.lucko.luckperms.common.sender.Sender)6 Predicates (me.lucko.luckperms.common.util.Predicates)6 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)5