Search in sources :

Example 1 with HeldPermission

use of me.lucko.luckperms.api.HeldPermission in project LuckPerms by lucko.

the class SqlDao method getGroupsWithPermission.

@Override
public List<HeldPermission<String>> getGroupsWithPermission(String permission) throws SQLException {
    List<HeldPermission<String>> held = new ArrayList<>();
    try (Connection c = this.provider.getConnection()) {
        try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(GROUP_PERMISSIONS_SELECT_PERMISSION))) {
            ps.setString(1, permission);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    String holder = rs.getString("name");
                    boolean value = rs.getBoolean("value");
                    String server = rs.getString("server");
                    String world = rs.getString("world");
                    long expiry = rs.getLong("expiry");
                    String contexts = rs.getString("contexts");
                    NodeModel data = deserializeNode(permission, value, server, world, expiry, contexts);
                    held.add(NodeHeldPermission.of(holder, data));
                }
            }
        }
    }
    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) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with HeldPermission

use of me.lucko.luckperms.api.HeldPermission 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 3 with HeldPermission

use of me.lucko.luckperms.api.HeldPermission 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 4 with HeldPermission

use of me.lucko.luckperms.api.HeldPermission 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 5 with HeldPermission

use of me.lucko.luckperms.api.HeldPermission in project LuckPerms by lucko.

the class SearchCommand method makeFancy.

private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm) {
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> " + (perm.asNode().getValuePrimitive() ? "&a" : "&c") + perm.asNode().getPermission(), " ", "&7Click to remove this node from " + holderName), CommandManager.AMPERSAND_CHAR));
    String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false);
    ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
    return component -> {
        component.hoverEvent(hoverEvent);
        component.clickEvent(clickEvent);
    };
}
Also used : TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) HoverEvent(net.kyori.text.event.HoverEvent) Function(java.util.function.Function) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) DateUtil(me.lucko.luckperms.common.utils.DateUtil) 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) HolderType(me.lucko.luckperms.common.references.HolderType) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) HeldPermission(me.lucko.luckperms.api.HeldPermission) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) CommandManager(me.lucko.luckperms.common.command.CommandManager) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Iterators(me.lucko.luckperms.common.utils.Iterators) TextComponent(net.kyori.text.TextComponent) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) TabCompletions(me.lucko.luckperms.common.command.utils.TabCompletions) BuildableComponent(net.kyori.text.BuildableComponent) Node(me.lucko.luckperms.api.Node) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Aggregations

ArrayList (java.util.ArrayList)10 HeldPermission (me.lucko.luckperms.api.HeldPermission)10 UUID (java.util.UUID)7 NodeHeldPermission (me.lucko.luckperms.common.node.NodeHeldPermission)6 NodeModel (me.lucko.luckperms.common.node.NodeModel)6 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)4 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)4 Maps (com.google.common.collect.Maps)4 List (java.util.List)4 Map (java.util.Map)4 Consumer (java.util.function.Consumer)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 Node (me.lucko.luckperms.api.Node)4 CommandManager (me.lucko.luckperms.common.command.CommandManager)4 CommandResult (me.lucko.luckperms.common.command.CommandResult)4 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)4 ArgumentParser (me.lucko.luckperms.common.command.utils.ArgumentParser)4 MessageUtils (me.lucko.luckperms.common.command.utils.MessageUtils)4 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)4