mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-01 05:57:51 +01:00
Increase editor users limit to 1000 & sort users according to their max inherited group weight
This commit is contained in:
parent
3bf2fab2e9
commit
5f0df1b167
@ -63,6 +63,7 @@ public class SimpleMetaCache implements CachedMetaData {
|
|||||||
protected Map<String, String> flattenedMeta = ImmutableMap.of();
|
protected Map<String, String> flattenedMeta = ImmutableMap.of();
|
||||||
protected SortedMap<Integer, String> prefixes = ImmutableSortedMap.of();
|
protected SortedMap<Integer, String> prefixes = ImmutableSortedMap.of();
|
||||||
protected SortedMap<Integer, String> suffixes = ImmutableSortedMap.of();
|
protected SortedMap<Integer, String> suffixes = ImmutableSortedMap.of();
|
||||||
|
protected int weight = 0;
|
||||||
protected String primaryGroup = null;
|
protected String primaryGroup = null;
|
||||||
protected MetaStack prefixStack = null;
|
protected MetaStack prefixStack = null;
|
||||||
protected MetaStack suffixStack = null;
|
protected MetaStack suffixStack = null;
|
||||||
@ -95,6 +96,7 @@ public class SimpleMetaCache implements CachedMetaData {
|
|||||||
|
|
||||||
this.prefixes = ImmutableSortedMap.copyOfSorted(meta.getPrefixes());
|
this.prefixes = ImmutableSortedMap.copyOfSorted(meta.getPrefixes());
|
||||||
this.suffixes = ImmutableSortedMap.copyOfSorted(meta.getSuffixes());
|
this.suffixes = ImmutableSortedMap.copyOfSorted(meta.getSuffixes());
|
||||||
|
this.weight = meta.getWeight();
|
||||||
this.primaryGroup = meta.getPrimaryGroup();
|
this.primaryGroup = meta.getPrimaryGroup();
|
||||||
this.prefixStack = meta.getPrefixStack();
|
this.prefixStack = meta.getPrefixStack();
|
||||||
this.suffixStack = meta.getSuffixStack();
|
this.suffixStack = meta.getSuffixStack();
|
||||||
@ -149,13 +151,22 @@ public class SimpleMetaCache implements CachedMetaData {
|
|||||||
return this.suffixes;
|
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) {
|
public @Nullable String getPrimaryGroup(MetaCheckEvent.Origin origin) {
|
||||||
return this.primaryGroup;
|
return this.primaryGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final @Nullable String getPrimaryGroup() {
|
public final @Nullable String getPrimaryGroup() {
|
||||||
return this.primaryGroup;
|
return getPrimaryGroup(MetaCheckEvent.Origin.LUCKPERMS_API);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
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.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.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.util.Predicates;
|
import me.lucko.luckperms.common.util.Predicates;
|
||||||
|
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.query.QueryOptions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class EditorCommand extends SingleCommand {
|
public class EditorCommand extends SingleCommand {
|
||||||
private static final int MAX_USERS = 500;
|
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, 1));
|
||||||
@ -70,45 +74,46 @@ public class EditorCommand extends SingleCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run a sync task
|
||||||
|
plugin.getSyncTaskBuffer().requestDirectly();
|
||||||
|
|
||||||
// collect holders
|
// collect holders
|
||||||
List<PermissionHolder> holders = new ArrayList<>();
|
List<PermissionHolder> holders = new ArrayList<>();
|
||||||
List<Track> tracks = new ArrayList<>();
|
List<Track> tracks = new ArrayList<>();
|
||||||
if (type.includingGroups) {
|
if (type.includingGroups) {
|
||||||
// run a sync task
|
|
||||||
plugin.getSyncTaskBuffer().requestDirectly();
|
|
||||||
|
|
||||||
plugin.getGroupManager().getAll().values().stream()
|
plugin.getGroupManager().getAll().values().stream()
|
||||||
.sorted((o1, o2) -> {
|
.sorted(Comparator
|
||||||
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
|
.<Group>comparingInt(g -> g.getWeight().orElse(0)).reversed()
|
||||||
return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
|
.thenComparing(Group::getName, String.CASE_INSENSITIVE_ORDER)
|
||||||
})
|
)
|
||||||
.forEach(holders::add);
|
.forEach(holders::add);
|
||||||
tracks = new ArrayList<>(plugin.getTrackManager().getAll().values());
|
|
||||||
|
tracks.addAll(plugin.getTrackManager().getAll().values());
|
||||||
}
|
}
|
||||||
if (type.includingUsers) {
|
if (type.includingUsers) {
|
||||||
Set<UUID> users = new LinkedHashSet<>();
|
// include all online players
|
||||||
|
Set<User> users = new LinkedHashSet<>(plugin.getUserManager().getAll().values());
|
||||||
// online players first
|
|
||||||
plugin.getUserManager().getAll().values().stream()
|
|
||||||
.sorted((o1, o2) -> o1.getFormattedDisplayName().compareToIgnoreCase(o2.getFormattedDisplayName()))
|
|
||||||
.map(User::getUniqueId)
|
|
||||||
.forEach(users::add);
|
|
||||||
|
|
||||||
// then fill up with other users
|
// 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 -> {
|
users.stream()
|
||||||
User user = plugin.getUserManager().getIfLoaded(uuid);
|
.sorted(Comparator
|
||||||
if (user != null) {
|
.<User>comparingInt(u -> u.getCachedData().getMetaData(QueryOptions.nonContextual()).getWeight(MetaCheckEvent.Origin.INTERNAL))
|
||||||
holders.add(user);
|
.thenComparing(User::getFormattedDisplayName, String.CASE_INSENSITIVE_ORDER)
|
||||||
} else {
|
)
|
||||||
user = plugin.getStorage().loadUser(uuid, null).join();
|
.forEach(holders::add);
|
||||||
if (user != null) {
|
|
||||||
holders.add(user);
|
|
||||||
}
|
|
||||||
plugin.getUserManager().getHouseKeeper().cleanup(uuid);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (holders.isEmpty()) {
|
if (holders.isEmpty()) {
|
||||||
@ -133,16 +138,19 @@ public class EditorCommand extends SingleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private enum Type {
|
private enum Type {
|
||||||
ALL(true, true),
|
ALL(true, true, true),
|
||||||
USERS(true, false),
|
ONLINE(true, true, false),
|
||||||
GROUPS(false, true);
|
USERS(true, false, true),
|
||||||
|
GROUPS(false, true, true);
|
||||||
|
|
||||||
private final boolean includingUsers;
|
private final boolean includingUsers;
|
||||||
private final boolean includingGroups;
|
private final boolean includingGroups;
|
||||||
|
private final boolean includingOffline;
|
||||||
|
|
||||||
Type(boolean includingUsers, boolean includingGroups) {
|
Type(boolean includingUsers, boolean includingGroups, boolean includingOffline) {
|
||||||
this.includingUsers = includingUsers;
|
this.includingUsers = includingUsers;
|
||||||
this.includingGroups = includingGroups;
|
this.includingGroups = includingGroups;
|
||||||
|
this.includingOffline = includingOffline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user