Search in sources :

Example 1 with MutableContextSet

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

the class ContextSetJsonSerializer method deserialize.

public static ContextSet deserialize(JsonElement element) {
    Preconditions.checkArgument(element.isJsonObject());
    JsonObject jsonObject = element.getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entries = jsonObject.entrySet();
    if (entries.isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }
    MutableContextSet contextSet = new MutableContextSetImpl();
    for (Map.Entry<String, JsonElement> entry : entries) {
        String k = entry.getKey();
        JsonElement v = entry.getValue();
        if (v.isJsonArray()) {
            JsonArray values = v.getAsJsonArray();
            for (JsonElement value : values) {
                contextSet.add(k, value.getAsString());
            }
        } else {
            contextSet.add(k, v.getAsString());
        }
    }
    return contextSet;
}
Also used : JsonArray(com.google.gson.JsonArray) MutableContextSet(net.luckperms.api.context.MutableContextSet) JsonElement(com.google.gson.JsonElement) MutableContextSetImpl(me.lucko.luckperms.common.context.MutableContextSetImpl) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 2 with MutableContextSet

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

the class MetaAddChatMeta 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.get(1);
    MutableContextSet context = args.getContextOrDefault(2, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    DataMutateResult result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
    if (result.wasSuccessful()) {
        Message.ADD_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, context);
        LoggedAction.build().source(sender).target(target).description("meta", "add" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.ALREADY_HAS_CHAT_META.send(sender, target, this.type, meta, priority, context);
    }
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 3 with MutableContextSet

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

the class MetaClear 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;
    }
    NodeType<?> type = null;
    if (!args.isEmpty()) {
        String typeId = args.get(0).toLowerCase(Locale.ROOT);
        if (typeId.equals("any") || typeId.equals("all") || typeId.equals("*")) {
            type = NodeType.META_OR_CHAT_META;
        }
        if (typeId.equals("chat") || typeId.equals("chatmeta")) {
            type = NodeType.CHAT_META;
        }
        if (typeId.equals("meta")) {
            type = NodeType.META;
        }
        if (typeId.equals("prefix") || typeId.equals("prefixes")) {
            type = NodeType.PREFIX;
        }
        if (typeId.equals("suffix") || typeId.equals("suffixes")) {
            type = NodeType.SUFFIX;
        }
        if (type != null) {
            args.remove(0);
        }
    }
    if (type == null) {
        type = NodeType.META_OR_CHAT_META;
    }
    int before = target.normalData().size();
    MutableContextSet context = args.getContextOrDefault(0, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (context.isEmpty()) {
        target.removeIf(DataType.NORMAL, null, type::matches, false);
    } else {
        target.removeIf(DataType.NORMAL, context, type::matches, false);
    }
    int changed = before - target.normalData().size();
    Message.META_CLEAR_SUCCESS.send(sender, target, type.name().toLowerCase(Locale.ROOT), context, changed);
    LoggedAction.build().source(sender).target(target).description("meta", "clear", context).build().submit(plugin, sender);
    StorageAssistant.save(target, sender, plugin);
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet)

Example 4 with MutableContextSet

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

the class MetaUnset 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 key = args.get(0);
    MutableContextSet context = args.getContextOrDefault(1, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
        Message.UNSET_META_SUCCESS.send(sender, key, target, context);
        LoggedAction.build().source(sender).target(target).description("meta", "unset", key, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.DOESNT_HAVE_META.send(sender, target, key, context);
    }
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) NodeType(net.luckperms.api.node.NodeType) 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) MutableContextSet(net.luckperms.api.context.MutableContextSet) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) 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) MutableContextSet(net.luckperms.api.context.MutableContextSet)

Example 5 with MutableContextSet

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

the class HolderClear method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, T target, ArgumentList args, String label) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    int before = target.normalData().size();
    MutableContextSet context = args.getContextOrDefault(0, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (context.isEmpty()) {
        target.clearNodes(DataType.NORMAL, null, true);
    } else {
        target.clearNodes(DataType.NORMAL, context, true);
    }
    int changed = before - target.normalData().size();
    Message.CLEAR_SUCCESS.send(sender, target, context, changed);
    LoggedAction.build().source(sender).target(target).description("clear", context).build().submit(plugin, sender);
    StorageAssistant.save(target, sender, plugin);
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet)

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