use of net.luckperms.api.node.types.MetaNode in project LuckPerms by lucko.
the class AbstractConfigurateStorage method writeNodes.
private void writeNodes(ConfigurationNode to, Collection<Node> nodes) {
ConfigurationNode permissionsSection = ConfigurationNode.root();
// to save to the file even if it's just an empty list.
if (this instanceof CombinedConfigurateStorage) {
permissionsSection.setValue(Collections.emptyList());
}
ConfigurationNode parentsSection = ConfigurationNode.root();
ConfigurationNode prefixesSection = ConfigurationNode.root();
ConfigurationNode suffixesSection = ConfigurationNode.root();
ConfigurationNode metaSection = ConfigurationNode.root();
for (Node n : nodes) {
// just add a string to the list.
if (this.loader instanceof YamlLoader && isPlain(n)) {
if (n instanceof InheritanceNode) {
parentsSection.appendListNode().setValue(((InheritanceNode) n).getGroupName());
continue;
}
if (!NodeType.META_OR_CHAT_META.matches(n)) {
permissionsSection.appendListNode().setValue(n.getKey());
continue;
}
}
if (n instanceof ChatMetaNode<?, ?> && n.getValue()) {
// handle prefixes / suffixes
ChatMetaNode<?, ?> chatMeta = (ChatMetaNode<?, ?>) n;
ConfigurationNode attributes = ConfigurationNode.root();
attributes.getNode("priority").setValue(chatMeta.getPriority());
writeAttributesTo(attributes, n, false);
switch(chatMeta.getMetaType()) {
case PREFIX:
appendNode(prefixesSection, chatMeta.getMetaValue(), attributes, "prefix");
break;
case SUFFIX:
appendNode(suffixesSection, chatMeta.getMetaValue(), attributes, "suffix");
break;
default:
throw new AssertionError();
}
} else if (n instanceof MetaNode && n.getValue()) {
// handle meta nodes
MetaNode meta = (MetaNode) n;
ConfigurationNode attributes = ConfigurationNode.root();
attributes.getNode("value").setValue(meta.getMetaValue());
writeAttributesTo(attributes, n, false);
appendNode(metaSection, meta.getMetaKey(), attributes, "key");
} else if (n instanceof InheritanceNode && n.getValue()) {
// handle group nodes
InheritanceNode inheritance = (InheritanceNode) n;
ConfigurationNode attributes = ConfigurationNode.root();
writeAttributesTo(attributes, n, false);
appendNode(parentsSection, inheritance.getGroupName(), attributes, "group");
} else {
// handle regular permissions and negated meta+prefixes+suffixes
ConfigurationNode attributes = ConfigurationNode.root();
writeAttributesTo(attributes, n, true);
appendNode(permissionsSection, n.getKey(), attributes, "permission");
}
}
if (permissionsSection.isList() || this instanceof CombinedConfigurateStorage) {
to.getNode("permissions").setValue(permissionsSection);
} else {
to.removeChild("permissions");
}
if (parentsSection.isList()) {
to.getNode("parents").setValue(parentsSection);
} else {
to.removeChild("parents");
}
if (prefixesSection.isList()) {
to.getNode("prefixes").setValue(prefixesSection);
} else {
to.removeChild("prefixes");
}
if (suffixesSection.isList()) {
to.getNode("suffixes").setValue(suffixesSection);
} else {
to.removeChild("suffixes");
}
if (metaSection.isList()) {
to.getNode("meta").setValue(metaSection);
} else {
to.removeChild("meta");
}
}
use of net.luckperms.api.node.types.MetaNode in project LuckPerms by lucko.
the class CalculatedSubject method resolveAllOptions.
public Map<String, String> resolveAllOptions(QueryOptions filter) {
SubjectInheritanceGraph graph = new SubjectInheritanceGraph(filter);
Map<String, String> result = new HashMap<>();
Iterable<CalculatedSubject> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this);
for (CalculatedSubject subject : traversal) {
for (MetaNode entry : subject.getCombinedOptions(filter).values()) {
result.putIfAbsent(entry.getMetaKey(), entry.getMetaValue());
}
}
return result;
}
use of net.luckperms.api.node.types.MetaNode in project LuckPerms by lucko.
the class CalculatedSubjectData method resolveOptions.
public Map<String, MetaNode> resolveOptions(QueryOptions filter) {
// get relevant entries
SortedMap<ImmutableContextSet, Map<String, MetaNode>> sorted = new TreeMap<>(ContextSetComparator.reverse());
for (Map.Entry<ImmutableContextSet, Map<String, String>> entry : this.options.entrySet()) {
if (!filter.satisfies(entry.getKey(), defaultSatisfyMode())) {
continue;
}
Map<String, MetaNode> nodeMap = new HashMap<>();
entry.getValue().forEach((key, value) -> {
MetaNode node = Meta.builder().key(key).value(value).context(entry.getKey()).withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin).build();
nodeMap.put(key, node);
});
sorted.put(entry.getKey(), nodeMap);
}
// flatten
Map<String, MetaNode> result = new HashMap<>();
for (Map<String, MetaNode> map : sorted.values()) {
for (Map.Entry<String, MetaNode> e : map.entrySet()) {
result.putIfAbsent(e.getKey(), e.getValue());
}
}
return result;
}
use of net.luckperms.api.node.types.MetaNode in project LuckPerms by lucko.
the class PermissionHolderSubjectData method nodesToOptions.
private static ImmutableMap<String, String> nodesToOptions(Iterable<? extends Node> nodes) {
Map<String, String> builder = new HashMap<>();
int maxPrefixPriority = Integer.MIN_VALUE;
int maxSuffixPriority = Integer.MIN_VALUE;
for (Node n : nodes) {
if (!n.getValue())
continue;
if (!NodeType.META_OR_CHAT_META.matches(n))
continue;
if (n instanceof PrefixNode) {
PrefixNode pn = (PrefixNode) n;
if (pn.getPriority() > maxPrefixPriority) {
builder.put(Prefix.NODE_KEY, pn.getMetaValue());
maxPrefixPriority = pn.getPriority();
}
continue;
}
if (n instanceof SuffixNode) {
SuffixNode sn = (SuffixNode) n;
if (sn.getPriority() > maxSuffixPriority) {
builder.put(Suffix.NODE_KEY, sn.getMetaValue());
maxSuffixPriority = sn.getPriority();
}
continue;
}
if (n instanceof MetaNode) {
MetaNode mn = (MetaNode) n;
builder.put(mn.getMetaKey(), mn.getMetaValue());
}
}
return ImmutableMap.copyOf(builder);
}
Aggregations