Skip to content

Commit

Permalink
enhancement: role weight fallback to luckperms placeholder (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
ProdPreva1l authored Dec 16, 2024
1 parent 9cb20be commit e398306
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public enum Placeholder {
.orElse(getPlaceholderFallback(plugin, "%luckperms_primary_group_name%"))),
ROLE_DISPLAY_NAME((plugin, player) -> player.getRole().getDisplayName()
.orElse(getPlaceholderFallback(plugin, "%luckperms_primary_group_name%"))),
ROLE_WEIGHT((plugin, player) -> player.getRoleWeightString()),
ROLE_WEIGHT((plugin, player) -> player.getRoleWeightString()
.orElse(getPlaceholderFallback(plugin, "%luckperms_meta_weight%"))),
SERVER_GROUP((plugin, player) -> player.getGroup().name()),
SERVER_GROUP_INDEX((plugin, player) -> Integer.toString(player.getServerGroupPosition(plugin))),
DEBUG_TEAM_NAME((plugin, player) -> plugin.getFormatter().escape(player.getLastTeamName().orElse(""))),
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/net/william278/velocitab/player/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@RequiredArgsConstructor
public class Role implements Comparable<Role> {

public static final int DEFAULT_WEIGHT = 0;
public static final int DEFAULT_WEIGHT = -1;
public static final Role DEFAULT_ROLE = new Role(DEFAULT_WEIGHT, null, null, null, null);
@Getter
private final int weight;
Expand Down Expand Up @@ -65,8 +65,11 @@ public Optional<String> getSuffix() {
}

@NotNull
protected String getWeightString() {
return Integer.toString(weight);
protected Optional<String> getWeightString() {
if (weight == -1) {
return Optional.empty();
}
return Optional.of(Integer.toString(weight));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/william278/velocitab/player/TabPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public TabPlayer(@NotNull Velocitab plugin, @NotNull Player player,
}

@NotNull
public String getRoleWeightString() {
public Optional<String> getRoleWeightString() {
return getRole().getWeightString();
}

Expand Down Expand Up @@ -263,7 +263,7 @@ public Optional<String> getCustomName() {
@Override
public int compareTo(@NotNull TabPlayer o) {
final int roleDifference = role.compareTo(o.role);
if (roleDifference == 0) {
if (roleDifference <= 0) {
return player.getUsername().compareTo(o.player.getUsername());
}
return roleDifference;
Expand Down

0 comments on commit e398306

Please sign in to comment.