Search in sources :

Example 21 with NodeModel

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

the class ConfigurateDao method loadGroup.

@Override
public Optional<Group> loadGroup(String name) throws Exception {
    Group group = this.plugin.getGroupManager().getIfLoaded(name);
    if (group != null) {
        group.getIoLock().lock();
    }
    try {
        ConfigurationNode object = readFile(StorageLocation.GROUP, name);
        if (object == null) {
            return Optional.empty();
        }
        if (group == null) {
            group = this.plugin.getGroupManager().getOrMake(name);
            group.getIoLock().lock();
        }
        Set<NodeModel> data = readNodes(object);
        Set<Node> nodes = data.stream().map(NodeModel::toNode).collect(Collectors.toSet());
        group.setEnduringNodes(nodes);
    } catch (Exception e) {
        throw reportException(name, e);
    } finally {
        if (group != null) {
            group.getIoLock().unlock();
        }
    }
    group.getRefreshBuffer().requestDirectly();
    return Optional.of(group);
}
Also used : Group(me.lucko.luckperms.common.model.Group) NodeModel(me.lucko.luckperms.common.node.NodeModel) 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) IOException(java.io.IOException)

Example 22 with NodeModel

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

the class WebEditor method deserializePermissions.

public static Set<NodeModel> deserializePermissions(JsonArray permissionsSection) {
    Set<NodeModel> nodes = new HashSet<>();
    for (JsonElement ent : permissionsSection) {
        if (!ent.isJsonObject()) {
            continue;
        }
        JsonObject data = ent.getAsJsonObject();
        String permission = data.get("permission").getAsString();
        boolean value = true;
        String server = "global";
        String world = "global";
        long expiry = 0L;
        ImmutableContextSet context = ImmutableContextSet.empty();
        if (data.has("value")) {
            value = data.get("value").getAsBoolean();
        }
        if (data.has("server")) {
            server = data.get("server").getAsString();
        }
        if (data.has("world")) {
            world = data.get("world").getAsString();
        }
        if (data.has("expiry")) {
            expiry = data.get("expiry").getAsLong();
        }
        if (data.has("context") && data.get("context").isJsonObject()) {
            JsonObject contexts = data.get("context").getAsJsonObject();
            context = ContextSetJsonSerializer.deserializeContextSet(contexts).makeImmutable();
        }
        nodes.add(NodeModel.of(permission, value, server, world, expiry, context));
    }
    return nodes;
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) 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