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