use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class ParentRemove method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
String collection = args.get(0);
String name = args.get(1);
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
LPPermissionService service = Sponge.getServiceManager().provideUnchecked(LPPermissionService.class);
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
MessageUtils.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't exist.");
}
LPSubjectCollection c = service.getCollection(collection);
if (!c.hasRegistered(name).join()) {
MessageUtils.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't exist.");
}
LPSubject subject = c.loadSubject(name).join();
if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
MessageUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?");
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class PermissionInfo method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(0, args);
if (contextSet.isEmpty()) {
MessageUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &bANY&a.");
Map<ImmutableContextSet, ImmutableMap<String, Boolean>> permissions = subjectData.getAllPermissions();
if (permissions.isEmpty()) {
MessageUtils.sendPluginMessage(sender, "That subject does not have any permissions defined.");
return CommandResult.SUCCESS;
}
for (Map.Entry<ImmutableContextSet, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue()));
}
} else {
Map<String, Boolean> permissions = subjectData.getPermissions(contextSet);
if (permissions.isEmpty()) {
MessageUtils.sendPluginMessage(sender, "That subject does not have any permissions defined in those contexts.");
return CommandResult.SUCCESS;
}
MessageUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.nodesToString(permissions));
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class HolderSubjectData method getAllParents.
@Override
public ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents() {
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<LPSubjectReference>> ret = ImmutableMap.builder();
for (Map.Entry<ImmutableContextSet, Collection<Node>> entry : this.holder.getNodes(this.type).asMap().entrySet()) {
ImmutableList.Builder<LPSubjectReference> builder = ImmutableList.builder();
for (Node n : entry.getValue()) {
if (n.isGroupNode()) {
builder.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
}
}
ret.put(entry.getKey(), builder.build());
}
return ret.build();
}
use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class HolderSubjectData 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(NodeFactory.PREFIX_KEY) || key.equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
// special handling.
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
// remove all prefixes/suffixes from the user
List<Node> toRemove = streamNodes().filter(type::matches).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, this.service.getPlugin().getContextManager().formContexts(contexts));
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
priority += 10;
node = NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(contexts).build();
} else {
// standard remove
List<Node> toRemove = streamNodes().filter(n -> n.isMeta() && n.getMeta().getKey().equals(key)).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
node = NodeFactory.buildMetaNode(key, value).withExtraContext(contexts).build();
}
this.type.run(() -> this.holder.setPermission(node), () -> this.holder.setTransientPermission(node));
return objectSave(this.holder).thenApply(v -> true);
}
use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class HolderSubjectData method getAllPermissions.
@Override
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, Boolean>> ret = ImmutableMap.builder();
for (Map.Entry<ImmutableContextSet, Collection<Node>> entry : this.holder.getNodes(this.type).asMap().entrySet()) {
ImmutableMap.Builder<String, Boolean> builder = ImmutableMap.builder();
for (Node n : entry.getValue()) {
builder.put(n.getPermission(), n.getValuePrimitive());
}
ret.put(entry.getKey(), builder.build());
}
return ret.build();
}
Aggregations