enhancement: role weight fallback to luckperms placeholder (#238)

This commit is contained in:
Preva1l 2024-12-17 06:00:25 +11:00 committed by GitHub
parent 9cb20be6e0
commit e398306cd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View File

@ -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(""))),

View File

@ -30,7 +30,7 @@ import java.util.Optional;
@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;
@ -65,8 +65,11 @@ public class Role implements Comparable<Role> {
}
@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

View File

@ -96,7 +96,7 @@ public final class TabPlayer implements Comparable<TabPlayer> {
}
@NotNull
public String getRoleWeightString() {
public Optional<String> getRoleWeightString() {
return getRole().getWeightString();
}
@ -263,7 +263,7 @@ public final class TabPlayer implements Comparable<TabPlayer> {
@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;