mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-30 20:21:50 +01:00
Add optional filter argument to editor command
This commit is contained in:
parent
98c71739f8
commit
6c88f7629e
@ -39,12 +39,16 @@ import me.lucko.luckperms.common.model.Group;
|
|||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.Track;
|
import me.lucko.luckperms.common.model.Track;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
|
import me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher;
|
||||||
|
import me.lucko.luckperms.common.node.matcher.StandardNodeMatchers;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.sender.Sender;
|
import me.lucko.luckperms.common.sender.Sender;
|
||||||
|
import me.lucko.luckperms.common.storage.misc.NodeEntry;
|
||||||
import me.lucko.luckperms.common.util.Predicates;
|
import me.lucko.luckperms.common.util.Predicates;
|
||||||
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
|
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
|
||||||
import me.lucko.luckperms.common.web.WebEditor;
|
import me.lucko.luckperms.common.web.WebEditor;
|
||||||
|
|
||||||
|
import net.luckperms.api.node.Node;
|
||||||
import net.luckperms.api.query.QueryOptions;
|
import net.luckperms.api.query.QueryOptions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -58,7 +62,7 @@ public class EditorCommand extends SingleCommand {
|
|||||||
private static final int MAX_USERS = 1000;
|
private static final int MAX_USERS = 1000;
|
||||||
|
|
||||||
public EditorCommand(LocaleManager locale) {
|
public EditorCommand(LocaleManager locale) {
|
||||||
super(CommandSpec.EDITOR.localize(locale), "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 1));
|
super(CommandSpec.EDITOR.localize(locale), "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -75,6 +79,8 @@ public class EditorCommand extends SingleCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String filter = ArgumentParser.parseStringOrElse(1, args, null);
|
||||||
|
|
||||||
// run a sync task
|
// run a sync task
|
||||||
plugin.getSyncTaskBuffer().requestDirectly();
|
plugin.getSyncTaskBuffer().requestDirectly();
|
||||||
|
|
||||||
@ -92,15 +98,17 @@ public class EditorCommand extends SingleCommand {
|
|||||||
tracks.addAll(plugin.getTrackManager().getAll().values());
|
tracks.addAll(plugin.getTrackManager().getAll().values());
|
||||||
}
|
}
|
||||||
if (type.includingUsers) {
|
if (type.includingUsers) {
|
||||||
// include all online players
|
Map<UUID, User> users;
|
||||||
Map<UUID, User> users = new LinkedHashMap<>(plugin.getUserManager().getAll());
|
|
||||||
|
|
||||||
// then fill up with other users with permissions
|
if (filter != null) {
|
||||||
if (type.includingOffline && users.size() < MAX_USERS) {
|
// return users matching the filter
|
||||||
plugin.getStorage().getUniqueUsers().join().stream()
|
users = new LinkedHashMap<>();
|
||||||
.filter(uuid -> !users.containsKey(uuid))
|
ConstraintNodeMatcher<Node> matcher = StandardNodeMatchers.keyStartsWith(filter);
|
||||||
|
plugin.getStorage().searchUserNodes(matcher).join().stream()
|
||||||
|
.map(NodeEntry::getHolder)
|
||||||
|
.distinct()
|
||||||
.sorted()
|
.sorted()
|
||||||
.limit(MAX_USERS - users.size())
|
.limit(MAX_USERS)
|
||||||
.forEach(uuid -> {
|
.forEach(uuid -> {
|
||||||
User user = plugin.getStorage().loadUser(uuid, null).join();
|
User user = plugin.getStorage().loadUser(uuid, null).join();
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@ -108,12 +116,29 @@ public class EditorCommand extends SingleCommand {
|
|||||||
}
|
}
|
||||||
plugin.getUserManager().getHouseKeeper().cleanup(uuid);
|
plugin.getUserManager().getHouseKeeper().cleanup(uuid);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// include all online players
|
||||||
|
users = new LinkedHashMap<>(plugin.getUserManager().getAll());
|
||||||
|
|
||||||
|
// then fill up with other users with permissions
|
||||||
|
if (type.includingOffline && users.size() < MAX_USERS) {
|
||||||
|
plugin.getStorage().getUniqueUsers().join().stream()
|
||||||
|
.filter(uuid -> !users.containsKey(uuid))
|
||||||
|
.sorted()
|
||||||
|
.limit(MAX_USERS - users.size())
|
||||||
|
.forEach(uuid -> {
|
||||||
|
User user = plugin.getStorage().loadUser(uuid, null).join();
|
||||||
|
if (user != null) {
|
||||||
|
users.put(uuid, user);
|
||||||
|
}
|
||||||
|
plugin.getUserManager().getHouseKeeper().cleanup(uuid);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
users.values().stream()
|
users.values().stream()
|
||||||
.sorted(Comparator
|
.sorted(Comparator
|
||||||
.<User>comparingInt(u -> u.getCachedData().getMetaData(QueryOptions.nonContextual()).getWeight(MetaCheckEvent.Origin.INTERNAL))
|
.<User>comparingInt(u -> u.getCachedData().getMetaData(QueryOptions.nonContextual()).getWeight(MetaCheckEvent.Origin.INTERNAL)).reversed()
|
||||||
.reversed()
|
|
||||||
.thenComparing(User::getFormattedDisplayName, String.CASE_INSENSITIVE_ORDER)
|
.thenComparing(User::getFormattedDisplayName, String.CASE_INSENSITIVE_ORDER)
|
||||||
)
|
)
|
||||||
.forEach(holders::add);
|
.forEach(holders::add);
|
||||||
|
@ -58,7 +58,8 @@ public enum CommandSpec {
|
|||||||
INFO("Prints general information about the active plugin instance.", "/%s info"),
|
INFO("Prints general information about the active plugin instance.", "/%s info"),
|
||||||
EDITOR("Creates a new web editor session", "/%s editor [type]",
|
EDITOR("Creates a new web editor session", "/%s editor [type]",
|
||||||
Argument.list(
|
Argument.list(
|
||||||
Argument.create("type", false, "the types to load into the editor. ('all', 'users' or 'groups')")
|
Argument.create("type", false, "the types to load into the editor. ('all', 'users' or 'groups')"),
|
||||||
|
Argument.create("filter", false, "permission to filter user entries by")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
DEBUG("Produces a set of internal debugging output", "/%s debug"),
|
DEBUG("Produces a set of internal debugging output", "/%s debug"),
|
||||||
|
Loading…
Reference in New Issue
Block a user