use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class ParentAdd method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
String collection = args.get(0);
String name = args.get(1);
ImmutableContextSet contextSet = args.getContextOrEmpty(2);
LPPermissionService service = subjectData.getParentSubject().getService();
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
SpongeCommandUtils.sendPrefixed(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't already exist.");
}
LPSubjectCollection c = service.getCollection(collection);
if (!c.hasRegistered(name).join()) {
SpongeCommandUtils.sendPrefixed(sender, "Warning: Subject '&4" + name + "&c' doesn't already exist.");
}
LPSubject subject = c.loadSubject(name).join();
if (subjectData.addParent(contextSet, subject.toReference()).join()) {
SpongeCommandUtils.sendPrefixed(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier().getName() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
SpongeCommandUtils.sendPrefixed(sender, "Unable to add parent. Does the Subject already have it added?");
}
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class PermissionSet method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) throws CommandException {
String node = args.get(0);
Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
ImmutableContextSet contextSet = args.getContextOrEmpty(2);
if (subjectData.setPermission(contextSet, node, tristate).join()) {
SpongeCommandUtils.sendPrefixed(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase(Locale.ROOT) + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
SpongeCommandUtils.sendPrefixed(sender, "Unable to set permission. Does the Subject already have it set?");
}
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class PermissionHolderSubjectData method setOption.
@Override
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
Objects.requireNonNull(contexts, "contexts");
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
Node node;
if (key.equalsIgnoreCase(Prefix.NODE_KEY) || key.equalsIgnoreCase(Suffix.NODE_KEY)) {
// special handling.
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase(Locale.ROOT));
// remove all prefixes/suffixes from the user
this.holder.removeIf(this.type, contexts, type.nodeType()::matches, false);
MetaAccumulator metaAccumulator = this.holder.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build());
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
priority += 10;
node = type.builder(value, priority).withContext(contexts).build();
} else {
// standard remove
this.holder.removeIf(this.type, contexts, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false);
node = Meta.builder(key, value).withContext(contexts).build();
}
this.holder.setNode(this.type, node, true);
return save(this.holder).thenApply(v -> true);
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class PermissionHolderSubjectData method getAllPermissions.
@Override
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, Boolean>> permissions = ImmutableMap.builder();
for (Map.Entry<ImmutableContextSet, Collection<Node>> entry : this.holder.getData(this.type).asMap().entrySet()) {
ImmutableMap.Builder<String, Boolean> builder = ImmutableMap.builder();
for (Node n : entry.getValue()) {
builder.put(n.getKey(), n.getValue());
}
permissions.put(entry.getKey(), builder.build());
}
return permissions.build();
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class ParentRemove method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
String collection = args.get(0);
String name = args.get(1);
ImmutableContextSet contextSet = args.getContextOrEmpty(2);
LPPermissionService service = subjectData.getParentSubject().getService();
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
SpongeCommandUtils.sendPrefixed(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't exist.");
}
LPSubjectCollection c = service.getCollection(collection);
if (!c.hasRegistered(name).join()) {
SpongeCommandUtils.sendPrefixed(sender, "Warning: Subject '&4" + name + "&c' doesn't exist.");
}
LPSubject subject = c.loadSubject(name).join();
if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
SpongeCommandUtils.sendPrefixed(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier().getName() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
SpongeCommandUtils.sendPrefixed(sender, "Unable to remove parent. Are you sure the Subject has it added?");
}
}
Aggregations