Search in sources :

Example 1 with ImmutableContextSet

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

the class ConfigurateDao method readAttributes.

private static Collection<NodeModel> readAttributes(ConfigurationNode attributes, String permission) {
    boolean value = attributes.getNode("value").getBoolean(true);
    String server = attributes.getNode("server").getString("global");
    String world = attributes.getNode("world").getString("global");
    long expiry = attributes.getNode("expiry").getLong(0L);
    ImmutableContextSet context = ImmutableContextSet.empty();
    ConfigurationNode contextMap = attributes.getNode("context");
    if (!contextMap.isVirtual() && contextMap.hasMapChildren()) {
        context = ContextSetConfigurateSerializer.deserializeContextSet(contextMap).makeImmutable();
    }
    ConfigurationNode batchAttribute = attributes.getNode("permissions");
    if (permission.startsWith("luckperms.batch") && !batchAttribute.isVirtual() && batchAttribute.hasListChildren()) {
        List<NodeModel> nodes = new ArrayList<>();
        for (ConfigurationNode element : batchAttribute.getChildrenList()) {
            nodes.add(NodeModel.of(element.getString(), value, server, world, expiry, context));
        }
        return nodes;
    } else {
        return Collections.singleton(NodeModel.of(permission, value, server, world, expiry, context));
    }
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ArrayList(java.util.ArrayList) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet)

Example 2 with ImmutableContextSet

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

the class ConfigurateDao method readAttributes.

private static NodeModel readAttributes(ConfigurationNode attributes, Function<ConfigurationNode, String> permissionFunction) {
    boolean value = attributes.getNode("value").getBoolean(true);
    String server = attributes.getNode("server").getString("global");
    String world = attributes.getNode("world").getString("global");
    long expiry = attributes.getNode("expiry").getLong(0L);
    ImmutableContextSet context = ImmutableContextSet.empty();
    ConfigurationNode contextMap = attributes.getNode("context");
    if (!contextMap.isVirtual() && contextMap.hasMapChildren()) {
        context = ContextSetConfigurateSerializer.deserializeContextSet(contextMap).makeImmutable();
    }
    return NodeModel.of(permissionFunction.apply(attributes), value, server, world, expiry, context);
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet)

Example 3 with ImmutableContextSet

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

the class MongoDao method nodeFromDoc.

private static NodeModel nodeFromDoc(Document document) {
    String permission = document.getString("permission");
    boolean value = true;
    String server = "global";
    String world = "global";
    long expiry = 0L;
    ImmutableContextSet context = ImmutableContextSet.empty();
    if (document.containsKey("value")) {
        value = document.getBoolean("value");
    }
    if (document.containsKey("server")) {
        server = document.getString("server");
    }
    if (document.containsKey("world")) {
        world = document.getString("world");
    }
    if (document.containsKey("expiry")) {
        expiry = document.getLong("expiry");
    }
    if (document.containsKey("context") && document.get("context") instanceof List) {
        // noinspection unchecked
        List<Document> contexts = (List<Document>) document.get("context");
        context = docsToContextSet(contexts).makeImmutable();
    }
    return NodeModel.of(permission, value, server, world, expiry, context);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) Document(org.bson.Document)

Example 4 with ImmutableContextSet

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

the class OptionInfo method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
    ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(0, args);
    if (contextSet.isEmpty()) {
        MessageUtils.sendPluginMessage(sender, "&aShowing options matching contexts &bANY&a.");
        Map<ImmutableContextSet, ImmutableMap<String, String>> options = subjectData.getAllOptions();
        if (options.isEmpty()) {
            MessageUtils.sendPluginMessage(sender, "That subject does not have any options defined.");
            return CommandResult.SUCCESS;
        }
        for (Map.Entry<ImmutableContextSet, ImmutableMap<String, String>> e : options.entrySet()) {
            MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.optionsToString(e.getValue()));
        }
    } else {
        Map<String, String> options = subjectData.getOptions(contextSet);
        if (options.isEmpty()) {
            MessageUtils.sendPluginMessage(sender, "That subject does not have any options defined in those contexts.");
            return CommandResult.SUCCESS;
        }
        MessageUtils.sendPluginMessage(sender, "&aShowing options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.optionsToString(options));
    }
    return CommandResult.SUCCESS;
}
Also used : ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with ImmutableContextSet

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

the class OptionSet method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
    String key = args.get(0);
    String value = args.get(1);
    ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
    if (subjectData.setOption(contextSet, key, value).join()) {
        MessageUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        MessageUtils.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?");
    }
    return CommandResult.SUCCESS;
}
Also used : ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet)

Aggregations

ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)27 Map (java.util.Map)10 ImmutableMap (com.google.common.collect.ImmutableMap)9 HashMap (java.util.HashMap)6 LPSubjectReference (me.lucko.luckperms.sponge.service.model.LPSubjectReference)6 Node (me.lucko.luckperms.api.Node)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)3 JsonObject (com.google.gson.JsonObject)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Tristate (me.lucko.luckperms.api.Tristate)2 ContextSet (me.lucko.luckperms.api.context.ContextSet)2 NodeModel (me.lucko.luckperms.common.node.NodeModel)2