Search in sources :

Example 6 with NodeModel

use of me.lucko.luckperms.common.node.NodeModel 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 7 with NodeModel

use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.

the class ConfigurateDao method getUsersWithPermission.

@Override
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) throws Exception {
    List<HeldPermission<UUID>> held = new ArrayList<>();
    File[] files = getDirectory(StorageLocation.USER).listFiles(getFileTypeFilter());
    if (files == null) {
        throw new IllegalStateException("Users directory matched no files.");
    }
    for (File file : files) {
        try {
            registerFileAction(StorageLocation.USER, file);
            ConfigurationNode object = readFile(file);
            UUID holder = UUID.fromString(file.getName().substring(0, file.getName().length() - this.fileExtension.length()));
            Set<NodeModel> nodes = readNodes(object);
            for (NodeModel e : nodes) {
                if (!e.getPermission().equalsIgnoreCase(permission)) {
                    continue;
                }
                held.add(NodeHeldPermission.of(holder, e));
            }
        } catch (Exception e) {
            throw reportException(file.getName(), e);
        }
    }
    return held;
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) HeldPermission(me.lucko.luckperms.api.HeldPermission) NodeHeldPermission(me.lucko.luckperms.common.node.NodeHeldPermission) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID) File(java.io.File) IOException(java.io.IOException)

Example 8 with NodeModel

use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.

the class ConfigurateDao method getGroupsWithPermission.

@Override
public List<HeldPermission<String>> getGroupsWithPermission(String permission) throws Exception {
    List<HeldPermission<String>> held = new ArrayList<>();
    File[] files = getDirectory(StorageLocation.GROUP).listFiles(getFileTypeFilter());
    if (files == null) {
        throw new IllegalStateException("Groups directory matched no files.");
    }
    for (File file : files) {
        try {
            registerFileAction(StorageLocation.GROUP, file);
            ConfigurationNode object = readFile(file);
            String holder = file.getName().substring(0, file.getName().length() - this.fileExtension.length());
            Set<NodeModel> nodes = readNodes(object);
            for (NodeModel e : nodes) {
                if (!e.getPermission().equalsIgnoreCase(permission)) {
                    continue;
                }
                held.add(NodeHeldPermission.of(holder, e));
            }
        } catch (Exception e) {
            throw reportException(file.getName(), e);
        }
    }
    return held;
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) HeldPermission(me.lucko.luckperms.api.HeldPermission) NodeHeldPermission(me.lucko.luckperms.common.node.NodeHeldPermission) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException)

Example 9 with NodeModel

use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.

the class MongoDao method getGroupsWithPermission.

@Override
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
    List<HeldPermission<String>> held = new ArrayList<>();
    MongoCollection<Document> c = this.database.getCollection(this.prefix + "groups");
    try (MongoCursor<Document> cursor = c.find().iterator()) {
        while (cursor.hasNext()) {
            Document d = cursor.next();
            String holder = d.getString("_id");
            Set<NodeModel> nodes = new HashSet<>(nodesFromDoc(d));
            for (NodeModel e : nodes) {
                if (!e.getPermission().equalsIgnoreCase(permission)) {
                    continue;
                }
                held.add(NodeHeldPermission.of(holder, e));
            }
        }
    }
    return held;
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) HeldPermission(me.lucko.luckperms.api.HeldPermission) NodeHeldPermission(me.lucko.luckperms.common.node.NodeHeldPermission) ArrayList(java.util.ArrayList) Document(org.bson.Document) HashSet(java.util.HashSet)

Example 10 with NodeModel

use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.

the class ApplyEditsCommand method read.

private boolean read(JsonObject data, String code, Sender sender, LuckPermsPlugin plugin) {
    if (!data.has("who") || data.get("who").getAsString().isEmpty()) {
        Message.APPLY_EDITS_NO_TARGET.send(sender);
        return false;
    }
    String who = data.get("who").getAsString();
    PermissionHolder holder = WebEditor.getHolderFromIdentifier(plugin, sender, who);
    if (holder == null) {
        // the #getHolderFromIdentifier method will send the error message onto the sender
        return false;
    }
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return false;
    }
    Set<NodeModel> nodes = WebEditor.deserializePermissions(data.getAsJsonArray("nodes"));
    Set<Node> before = new HashSet<>(holder.getEnduringNodes().values());
    Set<Node> after = nodes.stream().map(NodeModel::toNode).collect(Collectors.toSet());
    Map.Entry<Set<Node>, Set<Node>> diff = diff(before, after);
    int additions = diff.getKey().size();
    int deletions = diff.getValue().size();
    if (additions == 0 && deletions == 0) {
        return false;
    }
    ExtendedLogEntry.build().actor(sender).acted(holder).action("applyedits", code).build().submit(plugin, sender);
    holder.setEnduringNodes(after);
    String additionsSummary = "addition" + (additions == 1 ? "" : "s");
    String deletionsSummary = "deletion" + (deletions == 1 ? "" : "s");
    Message.APPLY_EDITS_SUCCESS.send(sender, holder.getFriendlyName());
    Message.APPLY_EDITS_SUCCESS_SUMMARY.send(sender, additions, additionsSummary, deletions, deletionsSummary);
    for (Node n : diff.getKey()) {
        Message.APPLY_EDITS_DIFF_ADDED.send(sender, formatNode(n));
    }
    for (Node n : diff.getValue()) {
        Message.APPLY_EDITS_DIFF_REMOVED.send(sender, formatNode(n));
    }
    StorageAssistant.save(holder, sender, plugin);
    return true;
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) HashSet(java.util.HashSet) Set(java.util.Set) Node(me.lucko.luckperms.api.Node) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

NodeModel (me.lucko.luckperms.common.node.NodeModel)22 ArrayList (java.util.ArrayList)11 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)10 SimpleConfigurationNode (ninja.leaping.configurate.SimpleConfigurationNode)10 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 HeldPermission (me.lucko.luckperms.api.HeldPermission)7 Node (me.lucko.luckperms.api.Node)7 NodeHeldPermission (me.lucko.luckperms.common.node.NodeHeldPermission)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 Map (java.util.Map)6 UUID (java.util.UUID)5 File (java.io.File)4 Set (java.util.Set)4 Group (me.lucko.luckperms.common.model.Group)4 ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)3 Document (org.bson.Document)3 List (java.util.List)2