Increase editor users limit to 1000 & sort users according to their max inherited group weight

This commit is contained in:
Luck 2020-05-10 16:31:35 +01:00
parent 3bf2fab2e9
commit 5f0df1b167
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 54 additions and 35 deletions

View File

@ -63,6 +63,7 @@ public class SimpleMetaCache implements CachedMetaData {
protected Map<String, String> flattenedMeta = ImmutableMap.of();
protected SortedMap<Integer, String> prefixes = ImmutableSortedMap.of();
protected SortedMap<Integer, String> suffixes = ImmutableSortedMap.of();
protected int weight = 0;
protected String primaryGroup = null;
protected MetaStack prefixStack = null;
protected MetaStack suffixStack = null;
@ -95,6 +96,7 @@ public class SimpleMetaCache implements CachedMetaData {
this.prefixes = ImmutableSortedMap.copyOfSorted(meta.getPrefixes());
this.suffixes = ImmutableSortedMap.copyOfSorted(meta.getSuffixes());
this.weight = meta.getWeight();
this.primaryGroup = meta.getPrimaryGroup();
this.prefixStack = meta.getPrefixStack();
this.suffixStack = meta.getSuffixStack();
@ -149,13 +151,22 @@ public class SimpleMetaCache implements CachedMetaData {
return this.suffixes;
}
public int getWeight(MetaCheckEvent.Origin origin) {
return this.weight;
}
//@Override
public final int getWeight() {
return getWeight(MetaCheckEvent.Origin.LUCKPERMS_API);
}
public @Nullable String getPrimaryGroup(MetaCheckEvent.Origin origin) {
return this.primaryGroup;
}
@Override
public final @Nullable String getPrimaryGroup() {
return this.primaryGroup;
return getPrimaryGroup(MetaCheckEvent.Origin.LUCKPERMS_API);
}
@Override

View File

@ -35,22 +35,26 @@ import me.lucko.luckperms.common.command.utils.ArgumentParser;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
import me.lucko.luckperms.common.web.WebEditor;
import net.luckperms.api.query.QueryOptions;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class EditorCommand extends SingleCommand {
private static final int MAX_USERS = 500;
private static final int MAX_USERS = 1000;
public EditorCommand(LocaleManager locale) {
super(CommandSpec.EDITOR.localize(locale), "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 1));
@ -70,45 +74,46 @@ public class EditorCommand extends SingleCommand {
}
}
// run a sync task
plugin.getSyncTaskBuffer().requestDirectly();
// collect holders
List<PermissionHolder> holders = new ArrayList<>();
List<Track> tracks = new ArrayList<>();
if (type.includingGroups) {
// run a sync task
plugin.getSyncTaskBuffer().requestDirectly();
plugin.getGroupManager().getAll().values().stream()
.sorted((o1, o2) -> {
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
})
.sorted(Comparator
.<Group>comparingInt(g -> g.getWeight().orElse(0)).reversed()
.thenComparing(Group::getName, String.CASE_INSENSITIVE_ORDER)
)
.forEach(holders::add);
tracks = new ArrayList<>(plugin.getTrackManager().getAll().values());
tracks.addAll(plugin.getTrackManager().getAll().values());
}
if (type.includingUsers) {
Set<UUID> users = new LinkedHashSet<>();
// online players first
plugin.getUserManager().getAll().values().stream()
.sorted((o1, o2) -> o1.getFormattedDisplayName().compareToIgnoreCase(o2.getFormattedDisplayName()))
.map(User::getUniqueId)
.forEach(users::add);
// include all online players
Set<User> users = new LinkedHashSet<>(plugin.getUserManager().getAll().values());
// then fill up with other users
users.addAll(plugin.getStorage().getUniqueUsers().join());
if (type.includingOffline && users.size() < MAX_USERS) {
plugin.getStorage().getUniqueUsers().join().stream()
.sorted()
.limit(MAX_USERS - users.size())
.forEach(uuid -> {
User user = plugin.getStorage().loadUser(uuid, null).join();
if (user != null) {
holders.add(user);
}
plugin.getUserManager().getHouseKeeper().cleanup(uuid);
});
}
users.stream().limit(MAX_USERS).forEach(uuid -> {
User user = plugin.getUserManager().getIfLoaded(uuid);
if (user != null) {
holders.add(user);
} else {
user = plugin.getStorage().loadUser(uuid, null).join();
if (user != null) {
holders.add(user);
}
plugin.getUserManager().getHouseKeeper().cleanup(uuid);
}
});
users.stream()
.sorted(Comparator
.<User>comparingInt(u -> u.getCachedData().getMetaData(QueryOptions.nonContextual()).getWeight(MetaCheckEvent.Origin.INTERNAL))
.thenComparing(User::getFormattedDisplayName, String.CASE_INSENSITIVE_ORDER)
)
.forEach(holders::add);
}
if (holders.isEmpty()) {
@ -133,16 +138,19 @@ public class EditorCommand extends SingleCommand {
}
private enum Type {
ALL(true, true),
USERS(true, false),
GROUPS(false, true);
ALL(true, true, true),
ONLINE(true, true, false),
USERS(true, false, true),
GROUPS(false, true, true);
private final boolean includingUsers;
private final boolean includingGroups;
private final boolean includingOffline;
Type(boolean includingUsers, boolean includingGroups) {
Type(boolean includingUsers, boolean includingGroups, boolean includingOffline) {
this.includingUsers = includingUsers;
this.includingGroups = includingGroups;
this.includingOffline = includingOffline;
}
}
}