Search in sources :

Example 1 with ChatMetaType

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();
}
Also used : ChatMetaType(me.lucko.luckperms.api.ChatMetaType)

Example 2 with ChatMetaType

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;
}
Also used : LogEntry(me.lucko.luckperms.api.LogEntry) FilenameFilter(java.io.FilenameFilter) Iterables(com.google.common.collect.Iterables) AbstractDao(me.lucko.luckperms.common.storage.dao.AbstractDao) Arrays(java.util.Arrays) UserIdentifier(me.lucko.luckperms.common.references.UserIdentifier) BulkUpdate(me.lucko.luckperms.common.bulkupdate.BulkUpdate) Function(java.util.function.Function) ConfigurationLoader(ninja.leaping.configurate.loader.ConfigurationLoader) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PlayerSaveResult(me.lucko.luckperms.common.storage.PlayerSaveResult) NodeModel(me.lucko.luckperms.common.node.NodeModel) Map(java.util.Map) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) Types(ninja.leaping.configurate.Types) HeldPermission(me.lucko.luckperms.api.HeldPermission) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) GroupManager(me.lucko.luckperms.common.managers.group.GroupManager) Collection(java.util.Collection) NodeHeldPermission(me.lucko.luckperms.common.node.NodeHeldPermission) Set(java.util.Set) IOException(java.io.IOException) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) Log(me.lucko.luckperms.common.actionlog.Log) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) UUID(java.util.UUID) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) File(java.io.File) MetaType(me.lucko.luckperms.common.node.MetaType) Objects(java.util.Objects) ContextSetConfigurateSerializer(me.lucko.luckperms.common.contexts.ContextSetConfigurateSerializer) Track(me.lucko.luckperms.common.model.Track) ImmutableCollectors(me.lucko.luckperms.common.utils.ImmutableCollectors) List(java.util.List) TrackManager(me.lucko.luckperms.common.managers.track.TrackManager) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) Optional(java.util.Optional) Node(me.lucko.luckperms.api.Node) Collections(java.util.Collections) User(me.lucko.luckperms.common.model.User) Uuids(me.lucko.luckperms.common.utils.Uuids) Types(ninja.leaping.configurate.Types) NodeModel(me.lucko.luckperms.common.node.NodeModel) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with ChatMetaType

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());
        }
    }
}
Also used : Entry(org.tyrannyofheaven.bukkit.zPermissions.model.Entry) EntityMetadata(org.tyrannyofheaven.bukkit.zPermissions.model.EntityMetadata) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) PermissionEntity(org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity)

Example 4 with ChatMetaType

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);
    };
}
Also used : SortedSet(java.util.SortedSet) NodeWithContextComparator(me.lucko.luckperms.common.node.NodeWithContextComparator) TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) HoverEvent(net.kyori.text.event.HoverEvent) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) SharedSubCommand(me.lucko.luckperms.common.command.abstraction.SharedSubCommand) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) CommandManager(me.lucko.luckperms.common.command.CommandManager) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) Set(java.util.Set) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) TextComponent(net.kyori.text.TextComponent) Maps(com.google.common.collect.Maps) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) BuildableComponent(net.kyori.text.BuildableComponent) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Comparator(java.util.Comparator) Predicates(me.lucko.luckperms.common.utils.Predicates) Group(me.lucko.luckperms.common.model.Group) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Example 5 with ChatMetaType

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);
    }
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) LogEntry(me.lucko.luckperms.api.LogEntry) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) Node(me.lucko.luckperms.api.Node) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Map(java.util.Map)

Aggregations

ChatMetaType (me.lucko.luckperms.api.ChatMetaType)9 Map (java.util.Map)6 Node (me.lucko.luckperms.api.Node)5 Group (me.lucko.luckperms.common.model.Group)5 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)5 List (java.util.List)4 HashSet (java.util.HashSet)3 Objects (java.util.Objects)3 Set (java.util.Set)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)3 User (me.lucko.luckperms.common.model.User)3 Maps (com.google.common.collect.Maps)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Function (java.util.function.Function)2 LogEntry (me.lucko.luckperms.api.LogEntry)2 MetaAccumulator (me.lucko.luckperms.common.caching.type.MetaAccumulator)2 CommandManager (me.lucko.luckperms.common.command.CommandManager)2