Skip to content

Commit

Permalink
Filter team & party parser suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
  • Loading branch information
Pablete1234 committed Oct 21, 2022
1 parent e9b88f9 commit cae0d5a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import tc.oc.pgm.api.map.MapOrder;
import tc.oc.pgm.rotation.MapPoolManager;
import tc.oc.pgm.rotation.pools.MapPool;
import tc.oc.pgm.util.StringUtils;
import tc.oc.pgm.util.LiquidMetal;

public final class MapPoolParser implements ArgumentParser<CommandSender, MapPool> {

Expand All @@ -42,12 +42,10 @@ public final class MapPoolParser implements ArgumentParser<CommandSender, MapPoo
MapOrder mapOrder = PGM.get().getMapOrder();
if (!(mapOrder instanceof MapPoolManager)) return Collections.emptyList();

String normalized = StringUtils.normalize(input);

return ((MapPoolManager) mapOrder)
.getMapPools().stream()
.map(MapPool::getName)
.filter(n -> StringUtils.normalize(n).startsWith(normalized))
.filter(name -> LiquidMetal.match(name, input))
.collect(Collectors.toList());
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/tc/oc/pgm/command/parsers/PartyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.party.Party;
import tc.oc.pgm.util.LiquidMetal;

public final class PartyParser extends StringLikeParser<CommandSender, Party> {

Expand All @@ -39,6 +40,7 @@ public ArgumentParseResult<Party> parse(
public @NonNull List<@NonNull String> suggestions(
@NonNull CommandContext<CommandSender> context, @NonNull String input) {
return Stream.concat(Stream.of("obs"), TeamParser.getTeams(context.getSender()))
.filter(str -> LiquidMetal.match(str, input))
.collect(Collectors.toList());
}
}
5 changes: 4 additions & 1 deletion core/src/main/java/tc/oc/pgm/command/parsers/TeamParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.teams.Team;
import tc.oc.pgm.teams.TeamMatchModule;
import tc.oc.pgm.util.LiquidMetal;

public final class TeamParser extends StringLikeParser<CommandSender, Team> {

Expand All @@ -38,7 +39,9 @@ public ArgumentParseResult<Team> parse(
@Override
public @NonNull List<@NonNull String> suggestions(
@NonNull CommandContext<CommandSender> context, @NonNull String input) {
return getTeams(context.getSender()).collect(Collectors.toList());
return getTeams(context.getSender())
.filter(str -> LiquidMetal.match(str, input))
.collect(Collectors.toList());
}

public static ArgumentParseResult<Team> getTeam(Match match, String text) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/tc/oc/pgm/command/parsers/TeamsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.teams.Team;
import tc.oc.pgm.teams.TeamMatchModule;
import tc.oc.pgm.util.LiquidMetal;

public final class TeamsParser extends StringLikeParser<CommandSender, Collection<Team>> {

Expand All @@ -46,6 +47,7 @@ public ArgumentParseResult<Collection<Team>> parse(
public @NonNull List<@NonNull String> suggestions(
@NonNull CommandContext<CommandSender> context, @NonNull String input) {
return Stream.concat(Stream.of("*"), TeamParser.getTeams(context.getSender()))
.filter(str -> LiquidMetal.match(str, input))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tc.oc.pgm.teams.TeamMatchModule;
import tc.oc.pgm.timelimit.TimeLimit;
import tc.oc.pgm.timelimit.TimeLimitMatchModule;
import tc.oc.pgm.util.LiquidMetal;
import tc.oc.pgm.util.text.TextException;

public final class VictoryConditionParser
Expand Down Expand Up @@ -73,6 +74,7 @@ public final class VictoryConditionParser
tmm.getParticipatingTeams().stream()
.map(Team::getNameLegacy)
.map(name -> name.replace(" ", "")))
.filter(str -> LiquidMetal.match(str, input))
.collect(Collectors.toList());
}
}

0 comments on commit cae0d5a

Please sign in to comment.