Search in sources :

Example 16 with ImmutableContextSet

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

the class PermissionInfo method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    ImmutableContextSet contextSet = args.getContextOrEmpty(0);
    if (contextSet.isEmpty()) {
        SpongeCommandUtils.sendPrefixed(sender, "&aShowing permissions matching contexts &bANY&a.");
        Map<ImmutableContextSet, ImmutableMap<String, Boolean>> permissions = subjectData.getAllPermissions();
        if (permissions.isEmpty()) {
            SpongeCommandUtils.sendPrefixed(sender, "That subject does not have any permissions defined.");
            return;
        }
        for (Map.Entry<ImmutableContextSet, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
            SpongeCommandUtils.sendPrefixed(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue()));
        }
    } else {
        Map<String, Boolean> permissions = subjectData.getPermissions(contextSet);
        if (permissions.isEmpty()) {
            SpongeCommandUtils.sendPrefixed(sender, "That subject does not have any permissions defined in those contexts.");
            return;
        }
        SpongeCommandUtils.sendPrefixed(sender, "&aShowing permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.nodesToString(permissions));
    }
}
Also used : ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 17 with ImmutableContextSet

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

the class OptionSet method execute.

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

Example 18 with ImmutableContextSet

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

the class MetaRemoveTempChatMeta 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_TEMP_CHATMETA_SUCCESS.send(sender, target, this.type, priority, context);
        LoggedAction.build().source(sender).target(target).description("meta", "removetemp" + 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).expiry(10L).withContext(context).build());
    if (result.wasSuccessful()) {
        Message.REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, context);
        LoggedAction.build().source(sender).target(target).description("meta", "removetemp" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.DOES_NOT_HAVE_TEMP_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 19 with ImmutableContextSet

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

the class ContextSetTest method testImmutableBuilder.

@Test
public void testImmutableBuilder() {
    List<Consumer<ImmutableContextSet.Builder>> tests = ImmutableList.of(builder -> {
        builder.add("test", "a");
        builder.add("test", "b");
        builder.add("test", "c");
    }, builder -> {
        builder.add("test", "c");
        builder.add("test", "b");
        builder.add("test", "a");
    }, builder -> {
        builder.add("test", "b");
        builder.add("test", "a");
        builder.add("test", "c");
    }, builder -> {
        builder.add("test", "b");
        builder.add("test", "c");
        builder.add("test", "a");
    }, builder -> {
        builder.add("test", "a");
        builder.add("test", "a");
        builder.add("test", "b");
        builder.add("test", "c");
    });
    for (Consumer<ImmutableContextSet.Builder> action : tests) {
        ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
        action.accept(builder);
        ImmutableContextSet set = builder.build();
        ImmutableSet<Context> expected = ImmutableSet.of(new ContextImpl("test", "a"), new ContextImpl("test", "b"), new ContextImpl("test", "c"));
        assertEquals(expected, set.toSet());
        assertEquals(3, set.size());
        assertTrue(set.contains("test", "a"));
        assertTrue(set.contains("test", "b"));
        assertTrue(set.contains("test", "c"));
    }
}
Also used : Context(net.luckperms.api.context.Context) Consumer(java.util.function.Consumer) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Test(org.junit.jupiter.api.Test)

Example 20 with ImmutableContextSet

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

the class ContextSetTest method testImmutableContains.

@Test
public void testImmutableContains() {
    ImmutableContextSet set = new ImmutableContextSetImpl.BuilderImpl().add("test", "a").add("test", "a").add("test", "b").add("test", "c").build();
    assertTrue(set.contains("test", "a"));
    assertFalse(set.contains("test", "z"));
    assertFalse(set.contains("aaa", "a"));
    assertTrue(set.containsKey("test"));
    assertFalse(set.containsKey("aaa"));
}
Also used : ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Test(org.junit.jupiter.api.Test)

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