use of me.lucko.luckperms.api.ChatMetaType in project LuckPerms by lucko.
the class NodeFactory method nodeAsCommand.
public static String nodeAsCommand(Node node, String id, HolderType type, boolean set) {
StringBuilder sb = new StringBuilder(32);
sb.append(type.toString()).append(" ").append(id).append(" ");
if (node.isGroupNode()) {
sb.append("parent ");
if (set) {
sb.append("add");
} else {
sb.append("remove");
}
if (node.isTemporary()) {
sb.append("temp");
}
sb.append(" ").append(node.getGroupName());
if (node.isTemporary() && set) {
sb.append(" ").append(node.getExpiryUnixTime());
}
return appendContextToCommand(sb, node).toString();
}
if (node.getValuePrimitive() && (node.isPrefix() || node.isSuffix())) {
ChatMetaType chatMetaType = node.isPrefix() ? ChatMetaType.PREFIX : ChatMetaType.SUFFIX;
sb.append("meta ");
if (set) {
sb.append("add");
} else {
sb.append("remove");
}
if (node.isTemporary()) {
sb.append("temp");
}
sb.append(chatMetaType).append(" ").append(// weight
chatMetaType.getEntry(node).getKey()).append(" ");
String value = chatMetaType.getEntry(node).getValue();
if (value.contains(" ")) {
// wrap value in quotes
sb.append("\"").append(value).append("\"");
} else {
sb.append(value);
}
if (set && node.isTemporary()) {
sb.append(" ").append(node.getExpiryUnixTime());
}
return appendContextToCommand(sb, node).toString();
}
if (node.getValuePrimitive() && node.isMeta()) {
sb.append("meta ");
if (set) {
sb.append("set");
} else {
sb.append("unset");
}
if (node.isTemporary()) {
sb.append("temp");
}
sb.append(" ");
String key = node.getMeta().getKey();
if (key.contains(" ")) {
sb.append("\"").append(key).append("\"");
} else {
sb.append(key);
}
if (set) {
sb.append(" ");
String value = node.getMeta().getValue();
if (value.contains(" ")) {
sb.append("\"").append(value).append("\"");
} else {
sb.append(value);
}
if (node.isTemporary()) {
sb.append(" ").append(node.getExpiryUnixTime());
}
}
return appendContextToCommand(sb, node).toString();
}
sb.append("permission ");
if (set) {
sb.append("set");
} else {
sb.append("unset");
}
if (node.isTemporary()) {
sb.append("temp");
}
sb.append(" ");
String perm = node.getPermission();
if (perm.contains(" ")) {
sb.append("\"").append(perm).append("\"");
} else {
sb.append(perm);
}
if (set) {
sb.append(" ").append(node.getValuePrimitive());
if (node.isTemporary()) {
sb.append(" ").append(node.getExpiryUnixTime());
}
}
return appendContextToCommand(sb, node).toString();
}
use of me.lucko.luckperms.api.ChatMetaType in project LuckPerms by lucko.
the class ConfigurateDao method readNodes.
private static Set<NodeModel> readNodes(ConfigurationNode data) {
Set<NodeModel> nodes = new HashSet<>();
if (data.getNode("permissions").hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode("permissions").getChildrenList();
for (ConfigurationNode appended : children) {
String plainValue = appended.getValue(Types::strictAsString);
if (plainValue != null) {
nodes.add(NodeModel.of(plainValue));
continue;
}
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.addAll(readAttributes(entry.getValue(), entry.getKey()));
}
}
if (data.getNode("parents").hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode("parents").getChildrenList();
for (ConfigurationNode appended : children) {
String stringValue = appended.getValue(Types::strictAsString);
if (stringValue != null) {
nodes.add(NodeModel.of(NodeFactory.groupNode(stringValue)));
continue;
}
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.add(readAttributes(entry.getValue(), c -> NodeFactory.groupNode(entry.getKey())));
}
}
for (ChatMetaType chatMetaType : ChatMetaType.values()) {
String keyName = chatMetaType.toString() + "es";
if (data.getNode(keyName).hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode(keyName).getChildrenList();
for (ConfigurationNode appended : children) {
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.add(readAttributes(entry.getValue(), c -> NodeFactory.chatMetaNode(chatMetaType, c.getNode("priority").getInt(0), entry.getKey())));
}
}
}
if (data.getNode("meta").hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode("meta").getChildrenList();
for (ConfigurationNode appended : children) {
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.add(readAttributes(entry.getValue(), c -> NodeFactory.metaNode(entry.getKey(), entry.getValue().getNode("value").getString("null"))));
}
}
return nodes;
}
use of me.lucko.luckperms.api.ChatMetaType in project LuckPerms by lucko.
the class MigrationZPermissions method migrateEntity.
private void migrateEntity(PermissionHolder holder, PermissionEntity entity, int weight) {
for (Entry e : entity.getPermissions()) {
if (e.getPermission().isEmpty())
continue;
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
holder.setPermission(NodeFactory.builder(e.getPermission()).setValue(e.isValue()).setWorld(e.getWorld().getName()).build());
} else {
holder.setPermission(NodeFactory.builder(e.getPermission()).setValue(e.isValue()).build());
}
}
// only migrate inheritances for groups
if (entity.isGroup()) {
for (PermissionEntity inheritance : entity.getParents()) {
if (!inheritance.getDisplayName().equals(holder.getObjectName())) {
holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(inheritance.getDisplayName())).build());
}
}
}
for (EntityMetadata metadata : entity.getMetadata()) {
String key = metadata.getName().toLowerCase();
if (key.isEmpty() || metadata.getStringValue().isEmpty())
continue;
if (key.equals(NodeFactory.PREFIX_KEY) || key.equals(NodeFactory.SUFFIX_KEY)) {
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
holder.setPermission(NodeFactory.buildChatMetaNode(type, weight, metadata.getStringValue()).build());
} else {
holder.setPermission(NodeFactory.buildMetaNode(key, metadata.getStringValue()).build());
}
}
}
use of me.lucko.luckperms.api.ChatMetaType in project LuckPerms by lucko.
the class MetaInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥a" + type.getEntry(node).getKey() + " ¥7- ¥r" + type.getEntry(node).getValue(), " ", "¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFriendlyName()), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.api.ChatMetaType in project LuckPerms by lucko.
the class ConfigurateDao method writeNodes.
private static void writeNodes(ConfigurationNode to, Set<NodeModel> nodes) {
ConfigurationNode permissionsSection = SimpleConfigurationNode.root();
ConfigurationNode parentsSection = SimpleConfigurationNode.root();
ConfigurationNode prefixesSection = SimpleConfigurationNode.root();
ConfigurationNode suffixesSection = SimpleConfigurationNode.root();
ConfigurationNode metaSection = SimpleConfigurationNode.root();
for (NodeModel node : nodes) {
Node n = node.toNode();
// just add a string to the list.
if (isPlain(node)) {
if (n.isGroupNode()) {
parentsSection.getAppendedNode().setValue(n.getGroupName());
continue;
}
if (!MetaType.ANY.matches(n)) {
permissionsSection.getAppendedNode().setValue(node.getPermission());
continue;
}
}
ChatMetaType chatMetaType = ChatMetaType.ofNode(n).orElse(null);
if (chatMetaType != null && n.getValuePrimitive()) {
// handle prefixes / suffixes
Map.Entry<Integer, String> entry = chatMetaType.getEntry(n);
ConfigurationNode attributes = SimpleConfigurationNode.root();
attributes.getNode("priority").setValue(entry.getKey());
writeAttributesTo(attributes, node, false);
ConfigurationNode appended = SimpleConfigurationNode.root();
appended.getNode(entry.getValue()).setValue(attributes);
switch(chatMetaType) {
case PREFIX:
prefixesSection.getAppendedNode().setValue(appended);
break;
case SUFFIX:
suffixesSection.getAppendedNode().setValue(appended);
break;
default:
throw new AssertionError();
}
} else if (n.isMeta() && n.getValuePrimitive()) {
// handle meta nodes
Map.Entry<String, String> meta = n.getMeta();
ConfigurationNode attributes = SimpleConfigurationNode.root();
attributes.getNode("value").setValue(meta.getValue());
writeAttributesTo(attributes, node, false);
ConfigurationNode appended = SimpleConfigurationNode.root();
appended.getNode(meta.getKey()).setValue(attributes);
metaSection.getAppendedNode().setValue(appended);
} else if (n.isGroupNode() && n.getValuePrimitive()) {
// handle group nodes
ConfigurationNode attributes = SimpleConfigurationNode.root();
writeAttributesTo(attributes, node, false);
ConfigurationNode appended = SimpleConfigurationNode.root();
appended.getNode(n.getGroupName()).setValue(attributes);
parentsSection.getAppendedNode().setValue(appended);
} else {
// handle regular permissions and negated meta+prefixes+suffixes
ConfigurationNode attributes = SimpleConfigurationNode.root();
writeAttributesTo(attributes, node, true);
ConfigurationNode appended = SimpleConfigurationNode.root();
appended.getNode(n.getPermission()).setValue(attributes);
permissionsSection.getAppendedNode().setValue(appended);
}
}
if (permissionsSection.hasListChildren()) {
to.getNode("permissions").setValue(permissionsSection);
}
if (parentsSection.hasListChildren()) {
to.getNode("parents").setValue(parentsSection);
}
if (prefixesSection.hasListChildren()) {
to.getNode("prefixes").setValue(prefixesSection);
}
if (suffixesSection.hasListChildren()) {
to.getNode("suffixes").setValue(suffixesSection);
}
if (metaSection.hasListChildren()) {
to.getNode("meta").setValue(metaSection);
}
}
Aggregations