From 22972281e2480e8d3ba237c5834e094de0ccb682 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 24 Feb 2023 17:58:23 +0000 Subject: [PATCH] Tweak role sort order --- .../java/net/william278/velocitab/Velocitab.java | 5 +---- .../velocitab/luckperms/LuckPermsHook.java | 16 +--------------- .../net/william278/velocitab/player/Role.java | 6 ++---- .../william278/velocitab/player/TabPlayer.java | 6 ++---- 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/william278/velocitab/Velocitab.java b/src/main/java/net/william278/velocitab/Velocitab.java index e2296e7..46e36c9 100644 --- a/src/main/java/net/william278/velocitab/Velocitab.java +++ b/src/main/java/net/william278/velocitab/Velocitab.java @@ -120,13 +120,10 @@ public class Velocitab { @NotNull public TabPlayer getTabPlayer(@NotNull Player player) { - return new TabPlayer( - player, + return new TabPlayer(player, getLuckPerms().map(hook -> hook.getPlayerRole(player)) .orElse(Role.DEFAULT_ROLE), getLuckPerms().map(LuckPermsHook::getHighestWeight) - .orElse(0), - getLuckPerms().map(LuckPermsHook::getLowestWeight) .orElse(0)); } diff --git a/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java b/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java index 06501b2..a41ecca 100644 --- a/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java +++ b/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java @@ -19,7 +19,6 @@ import java.util.UUID; public class LuckPermsHook { private int highestWeight = Role.DEFAULT_WEIGHT; - private int lowestWeight = Role.DEFAULT_WEIGHT; private final Velocitab plugin; private final LuckPerms api; @@ -52,8 +51,7 @@ public class LuckPermsHook { .ifPresent(player -> plugin.getTabList().updatePlayer(new TabPlayer( player, getRoleFromMetadata(event.getData().getMetaData()), - getHighestWeight(), - getLowestWeight() + getHighestWeight() ))); } @@ -77,18 +75,6 @@ public class LuckPermsHook { return highestWeight; } - public int getLowestWeight() { - if (lowestWeight == Role.DEFAULT_WEIGHT) { - api.getGroupManager().getLoadedGroups().forEach(group -> { - final OptionalInt weight = group.getWeight(); - if (weight.isPresent() && weight.getAsInt() < lowestWeight) { - lowestWeight = weight.getAsInt(); - } - }); - } - return lowestWeight; - } - private User getUser(@NotNull UUID uuid) { return api.getUserManager().getUser(uuid); } diff --git a/src/main/java/net/william278/velocitab/player/Role.java b/src/main/java/net/william278/velocitab/player/Role.java index ef4950d..fcf8bf9 100644 --- a/src/main/java/net/william278/velocitab/player/Role.java +++ b/src/main/java/net/william278/velocitab/player/Role.java @@ -41,9 +41,7 @@ public class Role implements Comparable { } @NotNull - public String getStringComparableWeight(int maximumPossibleWeight, int lowestPossibleWeight) { - return String.format("%0" + String.valueOf(maximumPossibleWeight).length() + "d", weight - lowestPossibleWeight) - .replace(" ", "0") - .replace("-", "0"); + public String getStringComparableWeight(int highestWeight) { + return String.format("%0" + (highestWeight + "").length() + "d", highestWeight - weight); } } diff --git a/src/main/java/net/william278/velocitab/player/TabPlayer.java b/src/main/java/net/william278/velocitab/player/TabPlayer.java index 2aa2bd0..844831f 100644 --- a/src/main/java/net/william278/velocitab/player/TabPlayer.java +++ b/src/main/java/net/william278/velocitab/player/TabPlayer.java @@ -12,13 +12,11 @@ public final class TabPlayer implements Comparable { private final Player player; private final Role role; private final int highestWeight; - private final int lowestWeight; - public TabPlayer(@NotNull Player player, @NotNull Role role, int highestWeight, int lowestWeight) { + public TabPlayer(@NotNull Player player, @NotNull Role role, int highestWeight) { this.player = player; this.role = role; this.highestWeight = highestWeight; - this.lowestWeight = lowestWeight; } @NotNull @@ -45,7 +43,7 @@ public final class TabPlayer implements Comparable { @NotNull public String getTeamName() { - return role.getStringComparableWeight(highestWeight, lowestWeight) + "-" + getServerName() + "-" + player.getUsername(); + return role.getStringComparableWeight(highestWeight) + "-" + getServerName() + "-" + player.getUsername(); } public void sendHeaderAndFooter(@NotNull PlayerTabList tabList) {