Fix role sort order

This commit is contained in:
William 2023-02-19 13:05:02 +00:00
parent 60baf597fd
commit 8ad443f4fc
No known key found for this signature in database
4 changed files with 19 additions and 5 deletions

View File

@ -104,7 +104,8 @@ public class Velocitab {
@NotNull
public TabPlayer getTabPlayer(@NotNull Player player) {
return new TabPlayer(player, getLuckPerms().map(hook -> hook.getPlayerRole(player)).orElse(Role.DEFAULT_ROLE));
return new TabPlayer(player, getLuckPerms().map(hook -> hook.getPlayerRole(player)).orElse(Role.DEFAULT_ROLE),
getLuckPerms().map(LuckPermsHook::getHighestWeight).orElse(0));
}
}

View File

@ -19,6 +19,7 @@ import java.util.UUID;
public class LuckPermsHook {
private int highestWeight = Role.DEFAULT_WEIGHT;
private final Velocitab plugin;
private final LuckPerms api;
@ -60,6 +61,18 @@ public class LuckPermsHook {
return group.getWeight();
}
public int getHighestWeight() {
if (highestWeight == Role.DEFAULT_WEIGHT) {
api.getGroupManager().getLoadedGroups().forEach(group -> {
final OptionalInt weight = group.getWeight();
if (weight.isPresent() && weight.getAsInt() > highestWeight) {
highestWeight = weight.getAsInt();
}
});
}
return highestWeight;
}
private User getUser(@NotNull UUID uuid) {
return api.getUserManager().getUser(uuid);
}

View File

@ -41,7 +41,7 @@ public class Role implements Comparable<Role> {
}
@NotNull
public String getStringComparableWeight() {
return String.format("%03d", weight);
public String getStringComparableWeight(int highestWeight) {
return String.format("%0" + (highestWeight + "").length() + "d", highestWeight - weight);
}
}

View File

@ -22,10 +22,10 @@ public final class TabPlayer implements Comparable<TabPlayer> {
private final Role role;
private final GameProfile profile;
public TabPlayer(@NotNull Player player, @NotNull Role role) {
public TabPlayer(@NotNull Player player, @NotNull Role role, int highestWeight) {
this.player = player;
this.role = role;
final String profileName = role.getStringComparableWeight() + "-" + getServerName() + "-" + player.getUsername();
final String profileName = role.getStringComparableWeight(highestWeight) + getServerName() + player.getUsername();
this.profile = new GameProfile(
new UUID(0, new Random().nextLong()),
profileName.length() > 16 ? profileName.substring(0, 16) : profileName,