Skip to content

Commit

Permalink
don't extend StringParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jan 6, 2022
1 parent b5d77a8 commit d400b2a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.captions.CaptionVariable;
import cloud.commandframework.captions.StandardCaptionKeys;
import cloud.commandframework.context.CommandContext;
Expand Down Expand Up @@ -296,15 +297,16 @@ private Builder(final @NonNull String name, final Set<String> allowedValues) {
* @param <C> Command sender type
* @since 1.6.0
*/
public static final class PseudoEnumParser<C> extends StringArgument.StringParser<C> {
public static final class PseudoEnumParser<C> implements ArgumentParser<C, String> {

private final Set<String> allowedValues;
private final StringArgument.StringParser<C> stringParser;

public PseudoEnumParser(
final StringArgument.@NonNull StringMode stringMode,
final @NonNull Set<String> allowedValues
) {
super(stringMode, (context, s) -> new ArrayList<>(allowedValues));
this.stringParser = new StringArgument.StringParser<>(stringMode, (context, s) -> new ArrayList<>(allowedValues));
this.allowedValues = allowedValues;
}

Expand All @@ -313,7 +315,7 @@ public PseudoEnumParser(
@NonNull final CommandContext<@NonNull C> commandContext,
@NonNull final Queue<@NonNull String> inputQueue
) {
ArgumentParseResult<String> result = super.parse(commandContext, inputQueue);
ArgumentParseResult<String> result = this.stringParser.parse(commandContext, inputQueue);
if (result.getFailure().isPresent()) {
return result;
} else if (result.getParsedValue().isPresent()) {
Expand All @@ -328,6 +330,28 @@ public PseudoEnumParser(
}
}

@Override
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return this.stringParser.suggestions(commandContext, input);
}

@Override
public boolean isContextFree() {
return true;
}

/**
* Get the string mode
*
* @return String mode
* @since 1.6.0
*/
public StringArgument.@NonNull StringMode getStringMode() {
return this.stringParser.getStringMode();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private Builder(final @NonNull String name) {
}


public static class StringParser<C> implements ArgumentParser<C, String> {
public static final class StringParser<C> implements ArgumentParser<C, String> {

private final StringMode stringMode;
private final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
Expand Down

0 comments on commit d400b2a

Please sign in to comment.