Skip to content

Commit

Permalink
feat: Made TeamParser index dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Apr 18, 2024
1 parent 9bc694b commit 28b84dc
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@

public final class TeamParser<C> implements ArgumentParser<C, Team> {

private static final Map<String, Team> BASE_TEAMS = Arrays.stream(Team.baseTeams)
.collect(Collectors.toUnmodifiableMap(t -> t.name.toLowerCase(Locale.ROOT), Function.identity()));

private static final Map<String, Team> ALL_TEAMS = Arrays.stream(Team.all)
.collect(Collectors.toUnmodifiableMap(t -> t.name.toLowerCase(Locale.ROOT), Function.identity()));

public static <C> ParserDescriptor<C, Team> teamParser() {
return teamParser(TeamMode.BASE);
}
Expand Down Expand Up @@ -83,7 +77,12 @@ public ArgumentParseResult<Team> parse(final CommandContext<C> ctx, final Comman
}

private Map<String, Team> getTeamIndex() {
return this.teamMode == TeamMode.ALL ? ALL_TEAMS : BASE_TEAMS;
return Arrays.stream(
switch (this.teamMode) {
case BASE -> Team.baseTeams;
case ALL -> Team.all;
})
.collect(Collectors.toUnmodifiableMap(t -> t.name.toLowerCase(Locale.ROOT), Function.identity()));
}

/**
Expand Down

0 comments on commit 28b84dc

Please sign in to comment.