Skip to content

Commit

Permalink
Fix & cleanup cloud 2.0 integration, use own fork
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 committed May 20, 2024
1 parent 491ceef commit c577142
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

public final class MatchPlayerParser
implements ArgumentParser<CommandSender, MatchPlayer>,
BlockingSuggestionProvider.Strings<CommandSender>,
ParseUtils {
BlockingSuggestionProvider.Strings<CommandSender> {

private final PlayerParser parser = new PlayerParser();

@Override
public @NotNull ArgumentParseResult<@NotNull MatchPlayer> parse(
@NotNull CommandContext<@NotNull CommandSender> context, @NotNull CommandInput inputQueue) {
return map(parser.parse(context, inputQueue), PGM.get().getMatchManager()::getPlayer);
return parser.parse(context, inputQueue).mapParsedValue(PGM.get().getMatchManager()::getPlayer);
}

@Override
Expand Down
23 changes: 0 additions & 23 deletions core/src/main/java/tc/oc/pgm/command/parsers/ParseUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ArgumentParseResult<Party> parse(

if (text.equalsIgnoreCase("obs")) return success(match.getDefaultParty());

return map(teamParser.parse(context, text), team -> team);
return teamParser.parse(context, text).mapParsedValue(team -> team);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

public final class RotationParser
implements ArgumentParser<CommandSender, Rotation>,
BlockingSuggestionProvider.Strings<CommandSender>,
ParseUtils {
BlockingSuggestionProvider.Strings<CommandSender> {

private final MapPoolParser POOL_PARSER = new MapPoolParser();

Expand All @@ -24,7 +23,7 @@ public final class RotationParser
final @NonNull CommandContext<CommandSender> context,
final @NonNull CommandInput inputQueue) {
context.set(CommandKeys.POOL_TYPE, MapPoolType.ORDERED);
return map(POOL_PARSER.parse(context, inputQueue), p -> (Rotation) p);
return POOL_PARSER.parse(context, inputQueue).mapParsedValue(p -> (Rotation) p);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import org.incendo.cloud.parser.ArgumentParseResult;
import org.incendo.cloud.parser.ArgumentParser;
import org.incendo.cloud.parser.ParserParameters;
import org.incendo.cloud.parser.standard.StringParser;
import org.jetbrains.annotations.NotNull;
import tc.oc.pgm.util.StringUtils;

public abstract class StringLikeParser<S, T> implements ArgumentParser<S, T>, ParseUtils {
public abstract class StringLikeParser<S, T> implements ArgumentParser<S, T> {

private final ArgumentParser<S, String> stringParser;
protected final ParserParameters options;
Expand All @@ -27,8 +28,7 @@ public StringLikeParser(CommandManager<S> manager, ParserParameters options) {
@Override
public @NotNull ArgumentParseResult<T> parse(
@NotNull CommandContext<S> context, @NotNull CommandInput args) {
return flatMap(
stringParser.parse(context, args),
return stringParser.parse(context, args).flatMapParsedValue(
text -> parse(context, StringUtils.suggestionToText(text)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ArgumentParseResult<Collection<Team>> parse(
return success(teams.getTeams());
}

return map(teamParser.parse(context, text), Collections::singleton);
return teamParser.parse(context, text).mapParsedValue(Collections::singleton);
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@
</dependency>

<!-- Framework for defining and parsing commands -->
<!-- Version 2.0.0-pgm includes fixes/features not yet in upstream. To be changed when merged. -->
<!-- Source: https://github.com/Pablete1234/cloud/commits/2.0.0-pgm -->
<!-- Repo: https://repo.pgm.fyi/#/snapshots/org/incendo -->
<dependency>
<groupId>org.incendo</groupId>
<artifactId>cloud-core</artifactId>
<version>2.0.0-rc.1</version>
<version>2.0.0-pgm-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion util/src/main/java/tc/oc/pgm/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static String getSuggestion(String suggestion, String mustKeep) {
suggestion = suggestion.substring(matchIdx + 1);
}

return textToSuggestion(suggestion);
return mustKeep + textToSuggestion(suggestion);
}

public static String textToSuggestion(String text) {
Expand Down

0 comments on commit c577142

Please sign in to comment.