Class MultipleOptionsArgument<TValue>
java.lang.Object
com.minecolonies.core.commands.arguments.MultipleOptionsArgument<TValue>
- Type Parameters:
TValue- the generic type of the value that the parser should return (this must be shared across all options).
- All Implemented Interfaces:
com.mojang.brigadier.arguments.ArgumentType<MultipleOptionsArgument.OptionContainer<TValue>>
- Direct Known Subclasses:
ColonyIdArgument,MultiColonyIdArgument
public abstract class MultipleOptionsArgument<TValue>
extends Object
implements com.mojang.brigadier.arguments.ArgumentType<MultipleOptionsArgument.OptionContainer<TValue>>
Base argument class that can serve to handle multiple different option values.
You pass one more MultipleOptionsArgument.ArgumentOption instances into the constructor.
The parser will then run over these options, in the specified order, and determine which option matches the argument value first.
Make sure the order can actually be respected in a logical way, with the outermost fallback option at the last position. For example:
- Match against a specific keyword
- Match against a known identifier (i.e. a number or UUID)
- Match against any other string value
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA singular argument option, this is responsible for checking if the argument value matches the expected user input.static final recordContainer class carrying the chosen option + original input value to the resolver method. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMultipleOptionsArgument(List<MultipleOptionsArgument.ArgumentOption<TValue>> allowedOptions) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected static <TValue> TValuegetValue(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, String name) Get the underlying value by running the resolver method on the chosen option parser.<S> CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> listSuggestions(com.mojang.brigadier.context.CommandContext<S> context, com.mojang.brigadier.suggestion.SuggestionsBuilder builder) parse(com.mojang.brigadier.StringReader reader) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.mojang.brigadier.arguments.ArgumentType
getExamples, parse
-
Constructor Details
-
MultipleOptionsArgument
protected MultipleOptionsArgument(List<MultipleOptionsArgument.ArgumentOption<TValue>> allowedOptions) Default constructor.- Parameters:
allowedOptions- the list of all argument options specified.
-
-
Method Details
-
getValue
protected static <TValue> TValue getValue(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, String name) throws com.mojang.brigadier.exceptions.CommandSyntaxException Get the underlying value by running the resolver method on the chosen option parser.- Type Parameters:
TValue- the generic type of the option parser.- Parameters:
context- the command context.name- the name of the argument.- Returns:
- the resolved value from the option.
- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- when any of the resolvers fail to resolve the finalized value.
-
parse
public final MultipleOptionsArgument.OptionContainer<TValue> parse(com.mojang.brigadier.StringReader reader) throws com.mojang.brigadier.exceptions.CommandSyntaxException - Specified by:
parsein interfacecom.mojang.brigadier.arguments.ArgumentType<TValue>- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException
-
listSuggestions
public <S> CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> listSuggestions(com.mojang.brigadier.context.CommandContext<S> context, com.mojang.brigadier.suggestion.SuggestionsBuilder builder) - Specified by:
listSuggestionsin interfacecom.mojang.brigadier.arguments.ArgumentType<TValue>
-