Search in sources :

Example 21 with ImmutableContextSet

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

the class ParentInfo 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 parents matching contexts &bANY&a.");
        Map<ImmutableContextSet, ImmutableList<LPSubjectReference>> parents = subjectData.getAllParents();
        if (parents.isEmpty()) {
            SpongeCommandUtils.sendPrefixed(sender, "That subject does not have any parents defined.");
            return;
        }
        for (Map.Entry<ImmutableContextSet, ImmutableList<LPSubjectReference>> e : parents.entrySet()) {
            SpongeCommandUtils.sendPrefixed(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
        }
    } else {
        List<LPSubjectReference> parents = subjectData.getParents(contextSet);
        if (parents.isEmpty()) {
            SpongeCommandUtils.sendPrefixed(sender, "That subject does not have any parents defined in those contexts.");
            return;
        }
        SpongeCommandUtils.sendPrefixed(sender, "&aShowing parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.parentsToString(parents));
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Map(java.util.Map)

Example 22 with ImmutableContextSet

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

the class PermissionClear method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    ImmutableContextSet contextSet = args.getContextOrEmpty(0);
    if (contextSet.isEmpty()) {
        subjectData.clearPermissions();
        SpongeCommandUtils.sendPrefixed(sender, "&aCleared permissions matching contexts &bANY&a.");
    } else {
        subjectData.clearPermissions(contextSet);
        SpongeCommandUtils.sendPrefixed(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
    }
}
Also used : ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Example 23 with ImmutableContextSet

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

the class CompatibilityUtil method convertContexts.

public static ImmutableContextSet convertContexts(Set<Context> contexts) {
    Objects.requireNonNull(contexts, "contexts");
    if (contexts instanceof ForwardingContextSet) {
        return ((ForwardingContextSet) contexts).delegate().immutableCopy();
    }
    if (contexts.isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }
    ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
    for (Map.Entry<String, String> entry : contexts) {
        builder.add(new ContextImpl(entry.getKey(), entry.getValue()));
    }
    return builder.build();
}
Also used : ForwardingContextSet(me.lucko.luckperms.sponge.service.context.ForwardingContextSet) ForwardingImmutableContextSet(me.lucko.luckperms.sponge.service.context.ForwardingImmutableContextSet) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) ContextImpl(me.lucko.luckperms.common.context.ContextImpl) Map(java.util.Map)

Example 24 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)

Example 25 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)

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