forked from Upstream/Velocitab
Fix parsing of enums in sortable element list in config file
This commit is contained in:
parent
829ab42e2e
commit
8a4651fb5f
@ -58,9 +58,9 @@ public class Settings {
|
||||
|
||||
@YamlKey("sort_players_by")
|
||||
@YamlComment("Ordered list of elements by which players should be sorted. (ROLE_WEIGHT, ROLE_NAME and SERVER are supported)")
|
||||
private List<TabPlayer.SortableElement> sortPlayersBy = List.of(
|
||||
TabPlayer.SortableElement.ROLE_WEIGHT,
|
||||
TabPlayer.SortableElement.ROLE_NAME
|
||||
private List<String> sortPlayersBy = List.of(
|
||||
TabPlayer.SortableElement.ROLE_WEIGHT.name(),
|
||||
TabPlayer.SortableElement.ROLE_NAME.name()
|
||||
);
|
||||
|
||||
@YamlKey("update_rate")
|
||||
@ -118,7 +118,10 @@ public class Settings {
|
||||
|
||||
@NotNull
|
||||
public List<TabPlayer.SortableElement> getSortingElementList() {
|
||||
return sortPlayersBy;
|
||||
return sortPlayersBy.stream()
|
||||
.map(p -> TabPlayer.SortableElement.parse(p).orElseThrow(() ->
|
||||
new IllegalArgumentException("Invalid sorting element set in config file: " + p)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public int getUpdateRate() {
|
||||
|
@ -7,6 +7,8 @@ import net.william278.velocitab.config.Placeholder;
|
||||
import net.william278.velocitab.tab.PlayerTabList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
@ -94,6 +96,10 @@ public final class TabPlayer implements Comparable<TabPlayer> {
|
||||
private String resolve(@NotNull TabPlayer tabPlayer, @NotNull Velocitab plugin) {
|
||||
return elementResolver.apply(tabPlayer, plugin);
|
||||
}
|
||||
|
||||
public static Optional<SortableElement> parse(@NotNull String s) {
|
||||
return Arrays.stream(values()).filter(element -> element.name().equalsIgnoreCase(s)).findFirst();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user