use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.
the class CombinedConfigurateStorage method searchGroupNodes.
@Override
public <N extends Node> List<NodeEntry<String, N>> searchGroupNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
List<NodeEntry<String, N>> held = new ArrayList<>();
this.groups.apply(false, true, root -> {
for (Map.Entry<Object, ? extends ConfigurationNode> entry : root.getChildrenMap().entrySet()) {
try {
String holder = entry.getKey().toString();
ConfigurationNode object = entry.getValue();
Set<Node> nodes = readNodes(object);
for (Node e : nodes) {
N match = constraint.match(e);
if (match != null) {
held.add(NodeEntry.of(holder, match));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
return held;
}
use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.
the class CombinedConfigurateStorage method searchUserNodes.
@Override
public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
List<NodeEntry<UUID, N>> held = new ArrayList<>();
this.users.apply(false, true, root -> {
for (Map.Entry<Object, ? extends ConfigurationNode> entry : root.getChildrenMap().entrySet()) {
try {
UUID holder = UUID.fromString(entry.getKey().toString());
ConfigurationNode object = entry.getValue();
Set<Node> nodes = readNodes(object);
for (Node e : nodes) {
N match = constraint.match(e);
if (match != null) {
held.add(NodeEntry.of(holder, match));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
return held;
}
use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.
the class SeparatedConfigurateStorage method searchUserNodes.
@Override
public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws IOException {
List<NodeEntry<UUID, N>> held = new ArrayList<>();
try (Stream<Path> stream = Files.list(getDirectory(StorageLocation.USERS))) {
stream.filter(this.fileExtensionFilter).forEach(file -> {
String fileName = file.getFileName().toString();
try {
registerFileAction(StorageLocation.USERS, file);
ConfigurationNode object = readFile(file);
UUID holder = UUID.fromString(fileName.substring(0, fileName.length() - this.fileExtension.length()));
Set<Node> nodes = readNodes(object);
for (Node e : nodes) {
N match = constraint.match(e);
if (match != null) {
held.add(NodeEntry.of(holder, match));
}
}
} catch (Exception e) {
this.plugin.getLogger().severe("Exception whilst searching user nodes", new FileIOException(file.getFileName().toString(), e));
}
});
}
return held;
}
use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.
the class SearchCommand method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
Comparison comparison = StandardComparison.parseComparison(args.get(0));
if (comparison == null) {
comparison = StandardComparison.EQUAL;
args.add(0, "==");
}
ConstraintNodeMatcher<Node> matcher = StandardNodeMatchers.of(Constraint.of(comparison, args.get(1)));
int page = args.getIntOrDefault(2, 1);
Message.SEARCH_SEARCHING.send(sender, matcher.toString());
List<NodeEntry<UUID, Node>> matchedUsers = plugin.getStorage().searchUserNodes(matcher).join();
List<NodeEntry<String, Node>> matchedGroups = plugin.getStorage().searchGroupNodes(matcher).join();
int users = matchedUsers.size();
int groups = matchedGroups.size();
Message.SEARCH_RESULT.send(sender, users + groups, users, groups);
if (!matchedUsers.isEmpty()) {
Map<UUID, String> uuidLookups = LoadingMap.of(u -> plugin.lookupUsername(u).orElseGet(u::toString));
sendResult(sender, matchedUsers, uuidLookups::get, Message.SEARCH_SHOWING_USERS, HolderType.USER, label, page, comparison);
}
if (!matchedGroups.isEmpty()) {
sendResult(sender, matchedGroups, Function.identity(), Message.SEARCH_SHOWING_GROUPS, HolderType.GROUP, label, page, comparison);
}
}
use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.
the class WebEditorRequest method findMatchingOfflineUsers.
private static void findMatchingOfflineUsers(Map<UUID, User> users, ConstraintNodeMatcher<Node> matcher, LuckPermsPlugin plugin) {
Stream<UUID> stream;
if (matcher == null) {
stream = plugin.getStorage().getUniqueUsers().join().stream();
} else {
stream = plugin.getStorage().searchUserNodes(matcher).join().stream().map(NodeEntry::getHolder).distinct();
}
Set<UUID> uuids = stream.filter(uuid -> !users.containsKey(uuid)).sorted().limit(MAX_USERS - users.size()).collect(Collectors.toSet());
if (uuids.isEmpty()) {
return;
}
// load users in bulk from storage
Map<UUID, User> loadedUsers = plugin.getStorage().loadUsers(uuids).join();
users.putAll(loadedUsers);
// schedule cleanup
for (UUID uniqueId : loadedUsers.keySet()) {
plugin.getUserManager().getHouseKeeper().cleanup(uniqueId);
}
}
Aggregations