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);
}
}
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());
}
}
Aggregations