forked from Upstream/Velocitab
Fix role sort order
This commit is contained in:
parent
60baf597fd
commit
8ad443f4fc
@ -104,7 +104,8 @@ public class Velocitab {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TabPlayer getTabPlayer(@NotNull Player player) {
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class LuckPermsHook {
|
public class LuckPermsHook {
|
||||||
|
|
||||||
|
private int highestWeight = Role.DEFAULT_WEIGHT;
|
||||||
private final Velocitab plugin;
|
private final Velocitab plugin;
|
||||||
private final LuckPerms api;
|
private final LuckPerms api;
|
||||||
|
|
||||||
@ -60,6 +61,18 @@ public class LuckPermsHook {
|
|||||||
return group.getWeight();
|
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) {
|
private User getUser(@NotNull UUID uuid) {
|
||||||
return api.getUserManager().getUser(uuid);
|
return api.getUserManager().getUser(uuid);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class Role implements Comparable<Role> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getStringComparableWeight() {
|
public String getStringComparableWeight(int highestWeight) {
|
||||||
return String.format("%03d", weight);
|
return String.format("%0" + (highestWeight + "").length() + "d", highestWeight - weight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ public final class TabPlayer implements Comparable<TabPlayer> {
|
|||||||
private final Role role;
|
private final Role role;
|
||||||
private final GameProfile profile;
|
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.player = player;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
final String profileName = role.getStringComparableWeight() + "-" + getServerName() + "-" + player.getUsername();
|
final String profileName = role.getStringComparableWeight(highestWeight) + getServerName() + player.getUsername();
|
||||||
this.profile = new GameProfile(
|
this.profile = new GameProfile(
|
||||||
new UUID(0, new Random().nextLong()),
|
new UUID(0, new Random().nextLong()),
|
||||||
profileName.length() > 16 ? profileName.substring(0, 16) : profileName,
|
profileName.length() > 16 ? profileName.substring(0, 16) : profileName,
|
||||||
|
Loading…
Reference in New Issue
Block a user