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));
}
}
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));
}
}
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();
}
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"));
}
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"));
}
}
Aggregations