Search in sources :

Example 1 with HolderType

use of me.lucko.luckperms.common.model.HolderType in project LuckPerms by lucko.

the class Importer method parseWebEditorData.

private void parseWebEditorData(Map<String, Set<Node>> groups, Map<String, List<String>> tracks, Map<UUID, UserData> users) {
    JsonArray holdersArray = this.data.get("permissionHolders").getAsJsonArray();
    for (JsonElement holderElement : holdersArray) {
        JsonObject jsonData = holderElement.getAsJsonObject();
        HolderType type = HolderType.valueOf(jsonData.get("type").getAsString().toUpperCase(Locale.ROOT));
        String id = jsonData.get("id").getAsString();
        if (type == HolderType.GROUP) {
            groups.put(id, NodeJsonSerializer.deserializeNodes(jsonData.get("nodes").getAsJsonArray()));
        } else {
            UUID uuid = UUID.fromString(id);
            String username = null;
            String displayName = jsonData.get("displayName").getAsString();
            if (!Uuids.PREDICATE.test(displayName)) {
                username = displayName;
            }
            Set<Node> nodes = NodeJsonSerializer.deserializeNodes(jsonData.get("nodes").getAsJsonArray());
            users.put(uuid, new UserData(username, null, nodes));
        }
    }
    JsonArray tracksArray = this.data.get("tracks").getAsJsonArray();
    for (JsonElement trackElement : tracksArray) {
        JsonObject jsonData = trackElement.getAsJsonObject();
        String name = jsonData.get("id").getAsString();
        JsonArray trackGroups = jsonData.get("groups").getAsJsonArray();
        List<String> trackGroupsList = new ArrayList<>();
        trackGroups.forEach(g -> trackGroupsList.add(g.getAsString()));
        tracks.put(name, trackGroupsList);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) Node(net.luckperms.api.node.Node) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) UUID(java.util.UUID) HolderType(me.lucko.luckperms.common.model.HolderType)

Example 2 with HolderType

use of me.lucko.luckperms.common.model.HolderType in project LuckPerms by lucko.

the class SearchCommand method sendResult.

private static <T extends Comparable<T>> void sendResult(Sender sender, List<NodeEntry<T, Node>> results, Function<T, String> lookupFunction, Message.Args3<Integer, Integer, Integer> headerMessage, HolderType holderType, String label, int page, Comparison comparison) {
    results = new ArrayList<>(results);
    results.sort(NodeEntryComparator.normal());
    int pageIndex = page - 1;
    List<List<NodeEntry<T, Node>>> pages = Iterators.divideIterable(results, 15);
    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;
        pageIndex = 0;
    }
    List<NodeEntry<T, Node>> content = pages.get(pageIndex);
    List<Map.Entry<String, NodeEntry<T, Node>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
    // send header
    headerMessage.send(sender, page, pages.size(), results.size());
    for (Map.Entry<String, NodeEntry<T, Node>> ent : mappedContent) {
        Message.SEARCH_NODE_ENTRY.send(sender, comparison != StandardComparison.EQUAL, ent.getValue().getNode(), ent.getKey(), holderType, label, sender.getPlugin());
    }
}
Also used : LoadingMap(me.lucko.luckperms.common.cache.LoadingMap) StandardNodeMatchers(me.lucko.luckperms.common.node.matcher.StandardNodeMatchers) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) Constraint(me.lucko.luckperms.common.bulkupdate.comparison.Constraint) TabCompletions(me.lucko.luckperms.common.command.tabcomplete.TabCompletions) Function(java.util.function.Function) Message(me.lucko.luckperms.common.locale.Message) NodeEntryComparator(me.lucko.luckperms.common.node.comparator.NodeEntryComparator) ArrayList(java.util.ArrayList) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) Map(java.util.Map) Node(net.luckperms.api.node.Node) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) HolderType(me.lucko.luckperms.common.model.HolderType) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) StandardComparison(me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison) Comparison(me.lucko.luckperms.common.bulkupdate.comparison.Comparison) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) ConstraintNodeMatcher(me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher) Iterators(me.lucko.luckperms.common.util.Iterators) List(java.util.List) Node(net.luckperms.api.node.Node) Constraint(me.lucko.luckperms.common.bulkupdate.comparison.Constraint) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) ArrayList(java.util.ArrayList) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) List(java.util.List) LoadingMap(me.lucko.luckperms.common.cache.LoadingMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 HolderType (me.lucko.luckperms.common.model.HolderType)2 Node (net.luckperms.api.node.Node)2 Maps (com.google.common.collect.Maps)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Comparison (me.lucko.luckperms.common.bulkupdate.comparison.Comparison)1 Constraint (me.lucko.luckperms.common.bulkupdate.comparison.Constraint)1 StandardComparison (me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison)1 LoadingMap (me.lucko.luckperms.common.cache.LoadingMap)1 SingleCommand (me.lucko.luckperms.common.command.abstraction.SingleCommand)1 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)1 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)1 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)1