fabric: javadoc cleanup

This commit is contained in:
jmp 2021-03-12 13:28:51 -08:00 committed by Jason
parent 488ea8f9d8
commit 65bb4d7a5d
45 changed files with 649 additions and 211 deletions

View file

@ -32,6 +32,14 @@ import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/**
* An argument parser which wraps another argument parser, converting the output type.
*
* @param <C> sender type
* @param <I> base output type
* @param <O> mapped output type
* @since 1.5.0
*/
public final class MappedArgumentParser<C, I, O> implements ArgumentParser<C, O> { public final class MappedArgumentParser<C, I, O> implements ArgumentParser<C, O> {
private final ArgumentParser<C, I> base; private final ArgumentParser<C, I> base;
private final BiFunction<CommandContext<C>, I, ArgumentParseResult<O>> mapper; private final BiFunction<CommandContext<C>, I, ArgumentParseResult<O>> mapper;

View file

@ -39,6 +39,7 @@ import static java.util.Objects.requireNonNull;
* *
* @param <K> the Cloud argument parser type * @param <K> the Cloud argument parser type
* @param <S> the brigadier-native sender type * @param <S> the brigadier-native sender type
* @since 1.5.0
*/ */
public interface BrigadierMappingBuilder<K extends ArgumentParser<?, ?>, S> { public interface BrigadierMappingBuilder<K extends ArgumentParser<?, ?>, S> {

View file

@ -39,6 +39,8 @@ import java.util.Queue;
* *
* <p>This can be implemented either by wrapping an existing {@link StringReader} instance, or extending {@link StringReader} * <p>This can be implemented either by wrapping an existing {@link StringReader} instance, or extending {@link StringReader}
* at its creation time to implement this interface.</p> * at its creation time to implement this interface.</p>
*
* @since 1.5.0
*/ */
public interface StringReaderAsQueue extends Queue<String> { public interface StringReaderAsQueue extends Queue<String> {

View file

@ -49,6 +49,7 @@ import static java.util.Objects.requireNonNull;
* *
* @param <C> the sender type * @param <C> the sender type
* @param <T> the value type of the argument * @param <T> the value type of the argument
* @since 1.5.0
*/ */
public final class WrappedBrigadierParser<C, T> implements ArgumentParser<C, T> { public final class WrappedBrigadierParser<C, T> implements ArgumentParser<C, T> {
public static final String COMMAND_CONTEXT_BRIGADIER_NATIVE_SENDER = "_cloud_brigadier_native_sender"; public static final String COMMAND_CONTEXT_BRIGADIER_NATIVE_SENDER = "_cloud_brigadier_native_sender";

View file

@ -31,21 +31,35 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
/**
* {@link Caption} instances for messages in cloud-fabric
*
* @since 1.5.0
*/
public final class FabricCaptionKeys { public final class FabricCaptionKeys {
private FabricCaptionKeys() {
}
private static final Collection<Caption> RECOGNIZED_CAPTIONS = new HashSet<>(); private static final Collection<Caption> RECOGNIZED_CAPTIONS = new HashSet<>();
/**
* Variables: {id}, {registry}
*
* @since 1.5.0
*/
public static final Caption ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY = of( public static final Caption ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY = of(
"argument.parse.failure.registry_entry.unknown_entry" "argument.parse.failure.registry_entry.unknown_entry"
); );
/**
* Variables: {input}
*
* @since 1.5.0
*/
public static final Caption ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN = of( public static final Caption ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN = of(
"argument.parse.failure.team.unknown" "argument.parse.failure.team.unknown"
); );
private FabricCaptionKeys() {
}
private static @NonNull Caption of(final @NonNull String key) { private static @NonNull Caption of(final @NonNull String key) {
final Caption caption = Caption.of(key); final Caption caption = Caption.of(key);
RECOGNIZED_CAPTIONS.add(caption); RECOGNIZED_CAPTIONS.add(caption);
@ -56,6 +70,7 @@ public final class FabricCaptionKeys {
* Get an immutable collection containing all standard caption keys * Get an immutable collection containing all standard caption keys
* *
* @return Immutable collection of keys * @return Immutable collection of keys
* @since 1.5.0
*/ */
public static @NonNull Collection<@NonNull Caption> getFabricCaptionKeys() { public static @NonNull Collection<@NonNull Caption> getFabricCaptionKeys() {
return Collections.unmodifiableCollection(RECOGNIZED_CAPTIONS); return Collections.unmodifiableCollection(RECOGNIZED_CAPTIONS);

View file

@ -26,19 +26,38 @@ package cloud.commandframework.fabric;
import cloud.commandframework.captions.SimpleCaptionRegistry; import cloud.commandframework.captions.SimpleCaptionRegistry;
/**
* Caption registry that uses bi-functions to produce messages
*
* @param <C> Command sender type
* @since 1.5.0
*/
public class FabricCaptionRegistry<C> extends SimpleCaptionRegistry<C> { public class FabricCaptionRegistry<C> extends SimpleCaptionRegistry<C> {
/**
* Default caption for {@link FabricCaptionKeys#ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY}
*
* @since 1.5.0
*/
public static final String ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY = "Could not find key {id} in registry '{registry}'"; public static final String ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY = "Could not find key {id} in registry '{registry}'";
/**
public static final String ARGUMENT_PARSE_FAILURE_TEAM_UNKOWN = "Could not find any team named '{input}'!"; * Default caption for {@link FabricCaptionKeys#ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN}
*
* @since 1.5.0
*/
public static final String ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN = "Could not find any team named '{input}'!";
protected FabricCaptionRegistry() { protected FabricCaptionRegistry() {
super(); super();
this.registerMessageFactory(FabricCaptionKeys.ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY, this.registerMessageFactory(
(caption, sender) -> ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY); FabricCaptionKeys.ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY,
this.registerMessageFactory(FabricCaptionKeys.ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN, (caption, sender) -> ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY
(caption, sender) -> ARGUMENT_PARSE_FAILURE_TEAM_UNKOWN); );
this.registerMessageFactory(
FabricCaptionKeys.ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN,
(caption, sender) -> ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN
);
} }

View file

@ -53,6 +53,7 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
* @param execCoordinator Execution coordinator instance. * @param execCoordinator Execution coordinator instance.
* @return a new command manager * @return a new command manager
* @see #FabricClientCommandManager(Function, Function, Function) for a more thorough explanation * @see #FabricClientCommandManager(Function, Function, Function) for a more thorough explanation
* @since 1.5.0
*/ */
public static FabricClientCommandManager<FabricClientCommandSource> createNative( public static FabricClientCommandManager<FabricClientCommandSource> createNative(
final Function<CommandTree<FabricClientCommandSource>, CommandExecutionCoordinator<FabricClientCommandSource>> execCoordinator final Function<CommandTree<FabricClientCommandSource>, CommandExecutionCoordinator<FabricClientCommandSource>> execCoordinator
@ -73,6 +74,7 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
* {@link AsynchronousCommandExecutionCoordinator} * {@link AsynchronousCommandExecutionCoordinator}
* @param commandSourceMapper Function that maps {@link FabricClientCommandSource} to the command sender type * @param commandSourceMapper Function that maps {@link FabricClientCommandSource} to the command sender type
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link FabricClientCommandSource} * @param backwardsCommandSourceMapper Function that maps the command sender type to {@link FabricClientCommandSource}
* @since 1.5.0
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public FabricClientCommandManager( public FabricClientCommandManager(
@ -105,6 +107,7 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
* @param sender Command sender * @param sender Command sender
* @param permission Permission node * @param permission Permission node
* @return whether the sender has the specified permission * @return whether the sender has the specified permission
* @since 1.5.0
*/ */
@Override @Override
public boolean hasPermission(@NonNull final C sender, @NonNull final String permission) { public boolean hasPermission(@NonNull final C sender, @NonNull final String permission) {

View file

@ -32,12 +32,19 @@ import net.minecraft.command.CommandSource;
/** /**
* Keys used in {@link CommandContext}s available within a {@link FabricCommandManager} * Keys used in {@link CommandContext}s available within a {@link FabricCommandManager}
*
* @since 1.5.0
*/ */
public final class FabricCommandContextKeys { public final class FabricCommandContextKeys {
private FabricCommandContextKeys() { private FabricCommandContextKeys() {
} }
/**
* Key used to store the native {@link CommandSource} in the command context.
*
* @since 1.5.0
*/
public static final CloudKey<CommandSource> NATIVE_COMMAND_SOURCE = SimpleCloudKey.of( public static final CloudKey<CommandSource> NATIVE_COMMAND_SOURCE = SimpleCloudKey.of(
"cloud:fabric_command_source", "cloud:fabric_command_source",
TypeToken.get(CommandSource.class) TypeToken.get(CommandSource.class)

View file

@ -108,7 +108,9 @@ import java.util.function.Supplier;
* @see FabricServerCommandManager for server commands * @see FabricServerCommandManager for server commands
* @since 1.5.0 * @since 1.5.0
*/ */
public abstract class FabricCommandManager<C, S extends CommandSource> extends CommandManager<C> implements BrigadierManagerHolder<C> { public abstract class FabricCommandManager<C, S extends CommandSource> extends CommandManager<C> implements
BrigadierManagerHolder<C> {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
private static final int MOD_PUBLIC_STATIC_FINAL = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; private static final int MOD_PUBLIC_STATIC_FINAL = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
@ -120,18 +122,19 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
/** /**
* Create a new command manager instance. * Create a new command manager instance.
* *
* @param commandExecutionCoordinator Execution coordinator instance. The coordinator is in charge of executing incoming * @param commandExecutionCoordinator Execution coordinator instance. The coordinator is in charge of executing incoming
* commands. Some considerations must be made when picking a suitable execution coordinator * commands. Some considerations must be made when picking a suitable execution coordinator
* for your platform. For example, an entirely asynchronous coordinator is not suitable * for your platform. For example, an entirely asynchronous coordinator is not suitable
* when the parsers used in that particular platform are not thread safe. If you have * when the parsers used in that particular platform are not thread safe. If you have
* commands that perform blocking operations, however, it might not be a good idea to * commands that perform blocking operations, however, it might not be a good idea to
* use a synchronous execution coordinator. In most cases you will want to pick between * use a synchronous execution coordinator. In most cases you will want to pick between
* {@link CommandExecutionCoordinator#simpleCoordinator()} and * {@link CommandExecutionCoordinator#simpleCoordinator()} and
* {@link AsynchronousCommandExecutionCoordinator} * {@link AsynchronousCommandExecutionCoordinator}
* @param commandSourceMapper Function that maps {@link CommandSource} to the command sender type * @param commandSourceMapper Function that maps {@link CommandSource} to the command sender type
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link CommandSource} * @param backwardsCommandSourceMapper Function that maps the command sender type to {@link CommandSource}
* @param registrationHandler the handler accepting command registrations * @param registrationHandler the handler accepting command registrations
* @param dummyCommandSourceProvider a provider of a dummy command source, for use with brigadier registration * @param dummyCommandSourceProvider a provider of a dummy command source, for use with brigadier registration
* @since 1.5.0
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
FabricCommandManager( FabricCommandManager(
@ -140,7 +143,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
final Function<C, S> backwardsCommandSourceMapper, final Function<C, S> backwardsCommandSourceMapper,
final FabricCommandRegistrationHandler<C, S> registrationHandler, final FabricCommandRegistrationHandler<C, S> registrationHandler,
final Supplier<S> dummyCommandSourceProvider final Supplier<S> dummyCommandSourceProvider
) { ) {
super(commandExecutionCoordinator, registrationHandler); super(commandExecutionCoordinator, registrationHandler);
this.commandSourceMapper = commandSourceMapper; this.commandSourceMapper = commandSourceMapper;
this.backwardsCommandSourceMapper = backwardsCommandSourceMapper; this.backwardsCommandSourceMapper = backwardsCommandSourceMapper;
@ -151,7 +154,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
// See net.minecraft.server.function.FunctionLoader.reload for reference // See net.minecraft.server.function.FunctionLoader.reload for reference
this.commandSourceMapper.apply(dummyCommandSourceProvider.get()), this.commandSourceMapper.apply(dummyCommandSourceProvider.get()),
this this
)); ));
this.brigadierManager.backwardsBrigadierSenderMapper(this.backwardsCommandSourceMapper); this.brigadierManager.backwardsBrigadierSenderMapper(this.backwardsCommandSourceMapper);
this.brigadierManager.brigadierSenderMapper(this.commandSourceMapper); this.brigadierManager.brigadierSenderMapper(this.commandSourceMapper);
this.registerNativeBrigadierMappings(this.brigadierManager); this.registerNativeBrigadierMappings(this.brigadierManager);
@ -186,8 +189,10 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
this.registerConstantNativeParserSupplier(ItemStackArgument.class, ItemStackArgumentType.itemStack()); this.registerConstantNativeParserSupplier(ItemStackArgument.class, ItemStackArgumentType.itemStack());
/* Wrapped/Constant Brigadier types, mapped value type */ /* Wrapped/Constant Brigadier types, mapped value type */
this.registerConstantNativeParserSupplier(BlockPredicateArgumentType.BlockPredicate.class, this.registerConstantNativeParserSupplier(
BlockPredicateArgumentType.blockPredicate()); BlockPredicateArgumentType.BlockPredicate.class,
BlockPredicateArgumentType.blockPredicate()
);
this.registerConstantNativeParserSupplier(MessageArgumentType.MessageFormat.class, MessageArgumentType.message()); this.registerConstantNativeParserSupplier(MessageArgumentType.MessageFormat.class, MessageArgumentType.message());
/*this.registerConstantNativeParserSupplier(GameProfile.class, GameProfileArgumentType.gameProfile()); /*this.registerConstantNativeParserSupplier(GameProfile.class, GameProfileArgumentType.gameProfile());
this.registerConstantNativeParserSupplier(BlockPos.class, BlockPosArgumentType.blockPos()); this.registerConstantNativeParserSupplier(BlockPos.class, BlockPosArgumentType.blockPos());
@ -210,7 +215,9 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
private void registerRegistryEntryMappings() { private void registerRegistryEntryMappings() {
this.brigadierManager.registerMapping(new TypeToken<RegistryEntryArgument.RegistryEntryParser<C, ?>>() {}, this.brigadierManager.registerMapping(
new TypeToken<RegistryEntryArgument.RegistryEntryParser<C, ?>>() {
},
builder -> builder.to(argument -> { builder -> builder.to(argument -> {
/* several registries have specialized argument types, so let's use those where possible */ /* several registries have specialized argument types, so let's use those where possible */
final RegistryKey<? extends Registry<?>> registry = argument.getRegistry(); final RegistryKey<? extends Registry<?>> registry = argument.getRegistry();
@ -288,17 +295,20 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
seenClasses.add(GenericTypeReflector.erase(valueType)); seenClasses.add(GenericTypeReflector.erase(valueType));
/* and now, finally, we can register */ /* and now, finally, we can register */
this.getParserRegistry().registerParserSupplier(TypeToken.get(valueType), this.getParserRegistry().registerParserSupplier(
params -> new RegistryEntryArgument.RegistryEntryParser(key)); TypeToken.get(valueType),
params -> new RegistryEntryArgument.RegistryEntryParser(key)
);
} }
} }
/** /**
* Register a parser supplier for a brigadier type that has no options and whose output can be directly used. * Register a parser supplier for a brigadier type that has no options and whose output can be directly used.
* *
* @param type the Java type to map * @param type the Java type to map
* @param argument the Brigadier parser * @param argument the Brigadier parser
* @param <T> value type * @param <T> value type
* @since 1.5.0
*/ */
final <T> void registerConstantNativeParserSupplier(final Class<T> type, final ArgumentType<T> argument) { final <T> void registerConstantNativeParserSupplier(final Class<T> type, final ArgumentType<T> argument) {
this.registerConstantNativeParserSupplier(TypeToken.get(type), argument); this.registerConstantNativeParserSupplier(TypeToken.get(type), argument);
@ -307,9 +317,10 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
/** /**
* Register a parser supplier for a brigadier type that has no options and whose output can be directly used. * Register a parser supplier for a brigadier type that has no options and whose output can be directly used.
* *
* @param type the Java type to map * @param type the Java type to map
* @param argument the Brigadier parser * @param argument the Brigadier parser
* @param <T> value type * @param <T> value type
* @since 1.5.0
*/ */
final <T> void registerConstantNativeParserSupplier(final TypeToken<T> type, final ArgumentType<T> argument) { final <T> void registerConstantNativeParserSupplier(final TypeToken<T> type, final ArgumentType<T> argument) {
this.getParserRegistry().registerParserSupplier(type, params -> new WrappedBrigadierParser<>(argument)); this.getParserRegistry().registerParserSupplier(type, params -> new WrappedBrigadierParser<>(argument));
@ -324,6 +335,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
* Gets the mapper from a game {@link CommandSource} to the manager's {@code C} type. * Gets the mapper from a game {@link CommandSource} to the manager's {@code C} type.
* *
* @return Command source mapper * @return Command source mapper
* @since 1.5.0
*/ */
public final @NonNull Function<@NonNull S, @NonNull C> getCommandSourceMapper() { public final @NonNull Function<@NonNull S, @NonNull C> getCommandSourceMapper() {
return this.commandSourceMapper; return this.commandSourceMapper;
@ -333,6 +345,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
* Gets the mapper from the manager's {@code C} type to a game {@link CommandSource}. * Gets the mapper from the manager's {@code C} type to a game {@link CommandSource}.
* *
* @return Command source mapper * @return Command source mapper
* @since 1.5.0
*/ */
public final @NonNull Function<@NonNull C, @NonNull S> getBackwardsCommandSourceMapper() { public final @NonNull Function<@NonNull C, @NonNull S> getBackwardsCommandSourceMapper() {
return this.backwardsCommandSourceMapper; return this.backwardsCommandSourceMapper;

View file

@ -63,6 +63,8 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
* A meta attribute specifying which environments a command should be registered in. * A meta attribute specifying which environments a command should be registered in.
* *
* <p>The default value is {@link CommandManager.RegistrationEnvironment#ALL}.</p> * <p>The default value is {@link CommandManager.RegistrationEnvironment#ALL}.</p>
*
* @since 1.5.0
*/ */
public static final CommandMeta.Key<CommandManager.RegistrationEnvironment> META_REGISTRATION_ENVIRONMENT = CommandMeta.Key.of( public static final CommandMeta.Key<CommandManager.RegistrationEnvironment> META_REGISTRATION_ENVIRONMENT = CommandMeta.Key.of(
CommandManager.RegistrationEnvironment.class, CommandManager.RegistrationEnvironment.class,
@ -75,6 +77,7 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
* @param execCoordinator Execution coordinator instance. * @param execCoordinator Execution coordinator instance.
* @return a new command manager * @return a new command manager
* @see #FabricServerCommandManager(Function, Function, Function) for a more thorough explanation * @see #FabricServerCommandManager(Function, Function, Function) for a more thorough explanation
* @since 1.5.0
*/ */
public static FabricServerCommandManager<ServerCommandSource> createNative( public static FabricServerCommandManager<ServerCommandSource> createNative(
final Function<CommandTree<ServerCommandSource>, CommandExecutionCoordinator<ServerCommandSource>> execCoordinator final Function<CommandTree<ServerCommandSource>, CommandExecutionCoordinator<ServerCommandSource>> execCoordinator
@ -95,6 +98,7 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
* {@link AsynchronousCommandExecutionCoordinator} * {@link AsynchronousCommandExecutionCoordinator}
* @param commandSourceMapper Function that maps {@link ServerCommandSource} to the command sender type * @param commandSourceMapper Function that maps {@link ServerCommandSource} to the command sender type
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link ServerCommandSource} * @param backwardsCommandSourceMapper Function that maps the command sender type to {@link ServerCommandSource}
* @since 1.5.0
*/ */
public FabricServerCommandManager( public FabricServerCommandManager(
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator, final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
@ -152,6 +156,7 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
* @param sender Command sender * @param sender Command sender
* @param permission Permission node * @param permission Permission node
* @return whether the sender has the specified permission * @return whether the sender has the specified permission
* @since 1.5.0
*/ */
@Override @Override
public boolean hasPermission(@NonNull final C sender, @NonNull final String permission) { public boolean hasPermission(@NonNull final C sender, @NonNull final String permission) {

View file

@ -67,6 +67,7 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> AngleArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> AngleArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new AngleArgument.Builder<>(name); return new AngleArgument.Builder<>(name);
@ -78,29 +79,32 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull AngleArgument<C> of(final @NonNull String name) { public static <C> @NonNull AngleArgument<C> of(final @NonNull String name) {
return AngleArgument.<C>newBuilder(name).asRequired().build(); return AngleArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull AngleArgument<C> optional(final @NonNull String name) { public static <C> @NonNull AngleArgument<C> optional(final @NonNull String name) {
return AngleArgument.<C>newBuilder(name).asOptional().build(); return AngleArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultAngle Default angle, in degrees * @param defaultAngle Default angle, in degrees
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull AngleArgument<C> optional( public static <C> @NonNull AngleArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -110,6 +114,12 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
} }
/**
* Builder for {@link AngleArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, AngleArgumentType.Angle, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, AngleArgumentType.Angle, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -117,9 +127,10 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
} }
/** /**
* Build a new angle argument * Build a new angle argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull AngleArgument<C> build() { public @NonNull AngleArgument<C> build() {

View file

@ -45,7 +45,9 @@ import java.util.function.BiFunction;
* @since 1.5.0 * @since 1.5.0
*/ */
public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.Axis>> { public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.Axis>> {
private static final TypeToken<EnumSet<Direction.Axis>> TYPE = new TypeToken<EnumSet<Direction.Axis>>() {};
private static final TypeToken<EnumSet<Direction.Axis>> TYPE = new TypeToken<EnumSet<Direction.Axis>>() {
};
AxisArgument( AxisArgument(
final boolean required, final boolean required,
@ -69,6 +71,7 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> AxisArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> AxisArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new AxisArgument.Builder<>(name); return new AxisArgument.Builder<>(name);
@ -80,29 +83,32 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull AxisArgument<C> of(final @NonNull String name) { public static <C> @NonNull AxisArgument<C> of(final @NonNull String name) {
return AxisArgument.<C>newBuilder(name).asRequired().build(); return AxisArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull AxisArgument<C> optional(final @NonNull String name) { public static <C> @NonNull AxisArgument<C> optional(final @NonNull String name) {
return AxisArgument.<C>newBuilder(name).asOptional().build(); return AxisArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValues Default axes to include * @param defaultValues Default axes to include
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull AxisArgument<C> optional( public static <C> @NonNull AxisArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -116,6 +122,12 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
} }
/**
* Builder for {@link AxisArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, EnumSet<Direction.Axis>, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, EnumSet<Direction.Axis>, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -123,9 +135,10 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
} }
/** /**
* Build a new criterion argument * Build a new axis argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull AxisArgument<C> build() { public @NonNull AxisArgument<C> build() {

View file

@ -50,49 +50,54 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) { ) {
super(required, name, new WrappedBrigadierParser<>(ColorArgumentType.color()), defaultValue, Formatting.class, super(required, name, new WrappedBrigadierParser<>(ColorArgumentType.color()), defaultValue, Formatting.class,
suggestionsProvider); suggestionsProvider
);
} }
/** /**
* Create a new builder * Create a new builder.
* *
* @param name Name of the component * @param name Name of the component
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> ColorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> ColorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ColorArgument.Builder<>(name); return new ColorArgument.Builder<>(name);
} }
/** /**
* Create a new required command component * Create a new required command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created component * @return Created component
* @since 1.5.0
*/ */
public static <C> @NonNull ColorArgument<C> of(final @NonNull String name) { public static <C> @NonNull ColorArgument<C> of(final @NonNull String name) {
return ColorArgument.<C>newBuilder(name).asRequired().build(); return ColorArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command component * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created component * @return Created component
* @since 1.5.0
*/ */
public static <C> @NonNull ColorArgument<C> optional(final @NonNull String name) { public static <C> @NonNull ColorArgument<C> optional(final @NonNull String name) {
return ColorArgument.<C>newBuilder(name).asOptional().build(); return ColorArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Component name * @param name Component name
* @param defaultColor Default colour, must be {@link Formatting#isColor() a color} * @param defaultColor Default colour, must be {@link Formatting#isColor() a color}
* @param <C> Command sender type * @param <C> Command sender type
* @return Created component * @return Created component
* @since 1.5.0
*/ */
public static <C> @NonNull ColorArgument<C> optional( public static <C> @NonNull ColorArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -105,6 +110,12 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
} }
/**
* Builder for {@link ColorArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends CommandArgument.TypedBuilder<C, Formatting, Builder<C>> { public static final class Builder<C> extends CommandArgument.TypedBuilder<C, Formatting, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -112,9 +123,10 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
} }
/** /**
* Build a new argument * Build a new color argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull ColorArgument<C> build() { public @NonNull ColorArgument<C> build() {

View file

@ -60,45 +60,49 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
} }
/** /**
* Create a new builder * Create a new builder.
* *
* @param name Name of the component * @param name Name of the component
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> CompoundTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> CompoundTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new CompoundTagArgument.Builder<>(name); return new CompoundTagArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument * Create a new required command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull CompoundTagArgument<C> of(final @NonNull String name) { public static <C> @NonNull CompoundTagArgument<C> of(final @NonNull String name) {
return CompoundTagArgument.<C>newBuilder(name).asRequired().build(); return CompoundTagArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull CompoundTagArgument<C> optional(final @NonNull String name) { public static <C> @NonNull CompoundTagArgument<C> optional(final @NonNull String name) {
return CompoundTagArgument.<C>newBuilder(name).asOptional().build(); return CompoundTagArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Component name * @param name Component name
* @param defaultTag Default tag value * @param defaultTag Default tag value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created component * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull CompoundTagArgument<C> optional( public static <C> @NonNull CompoundTagArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -108,6 +112,12 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
} }
/**
* Builder for {@link CompoundTagArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, CompoundTag, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, CompoundTag, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -115,13 +125,19 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
} }
/** /**
* Builder a new example component * Build a new compound tag argument.
* *
* @return Constructed component * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull CompoundTagArgument<C> build() { public @NonNull CompoundTagArgument<C> build() {
return new CompoundTagArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new CompoundTagArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -64,6 +64,7 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> EntityAnchorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> EntityAnchorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new EntityAnchorArgument.Builder<>(name); return new EntityAnchorArgument.Builder<>(name);
@ -75,29 +76,32 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull EntityAnchorArgument<C> of(final @NonNull String name) { public static <C> @NonNull EntityAnchorArgument<C> of(final @NonNull String name) {
return EntityAnchorArgument.<C>newBuilder(name).asRequired().build(); return EntityAnchorArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull EntityAnchorArgument<C> optional(final @NonNull String name) { public static <C> @NonNull EntityAnchorArgument<C> optional(final @NonNull String name) {
return EntityAnchorArgument.<C>newBuilder(name).asOptional().build(); return EntityAnchorArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull EntityAnchorArgument<C> optional( public static <C> @NonNull EntityAnchorArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -107,6 +111,12 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
} }
/**
* Builder for {@link EntityAnchorArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, EntityAnchorArgumentType.EntityAnchor, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, EntityAnchorArgumentType.EntityAnchor, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -114,13 +124,19 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
} }
/** /**
* Build a new criterion argument * Build a new entity anchor argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull EntityAnchorArgument<C> build() { public @NonNull EntityAnchorArgument<C> build() {
return new EntityAnchorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new EntityAnchorArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -67,6 +67,7 @@ public final class FabricArgumentParsers {
* *
* @param <C> sender type * @param <C> sender type
* @return a parser instance * @return a parser instance
* @since 1.5.0
*/ */
public static <C> ArgumentParser<C, MinecraftTime> time() { public static <C> ArgumentParser<C, MinecraftTime> time() {
return new WrappedBrigadierParser<C, Integer>(TimeArgumentType.time()) return new WrappedBrigadierParser<C, Integer>(TimeArgumentType.time())
@ -78,6 +79,7 @@ public final class FabricArgumentParsers {
* *
* @param <C> sender type * @param <C> sender type
* @return a parser instance * @return a parser instance
* @since 1.5.0
*/ */
public static <C> ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() { public static <C> ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.player()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.player())
@ -103,6 +105,7 @@ public final class FabricArgumentParsers {
* *
* @param <C> sender type * @param <C> sender type
* @return a parser instance * @return a parser instance
* @since 1.5.0
*/ */
public static <C> ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() { public static <C> ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.players()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.players())
@ -128,6 +131,7 @@ public final class FabricArgumentParsers {
* *
* @param <C> sender type * @param <C> sender type
* @return a parser instance * @return a parser instance
* @since 1.5.0
*/ */
public static <C> ArgumentParser<C, SingleEntitySelector> singleEntitySelector() { public static <C> ArgumentParser<C, SingleEntitySelector> singleEntitySelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entity()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entity())
@ -153,6 +157,7 @@ public final class FabricArgumentParsers {
* *
* @param <C> sender type * @param <C> sender type
* @return a parser instance * @return a parser instance
* @since 1.5.0
*/ */
public static <C> ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() { public static <C> ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entities()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entities())
@ -178,6 +183,7 @@ public final class FabricArgumentParsers {
* *
* @param <C> sender type * @param <C> sender type
* @return a parser instance * @return a parser instance
* @since 1.5.0
*/ */
public static <C> ArgumentParser<C, Message> message() { public static <C> ArgumentParser<C, Message> message() {
return new WrappedBrigadierParser<C, MessageArgumentType.MessageFormat>(MessageArgumentType.message()) return new WrappedBrigadierParser<C, MessageArgumentType.MessageFormat>(MessageArgumentType.message())
@ -199,7 +205,7 @@ public final class FabricArgumentParsers {
} }
private static @NonNull IllegalStateException serverOnly() { private static @NonNull IllegalStateException serverOnly() {
return new IllegalStateException("This argument is server-only"); return new IllegalStateException("This command argument type is server-only.");
} }
static final class MessageImpl implements Message { static final class MessageImpl implements Message {

View file

@ -66,6 +66,7 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> FloatRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> FloatRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new FloatRangeArgument.Builder<>(name); return new FloatRangeArgument.Builder<>(name);
@ -77,33 +78,36 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull FloatRangeArgument<C> of(final @NonNull String name) { public static <C> @NonNull FloatRangeArgument<C> of(final @NonNull String name) {
return FloatRangeArgument.<C>newBuilder(name).asRequired().build(); return FloatRangeArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull FloatRangeArgument<C> optional(final @NonNull String name) { public static <C> @NonNull FloatRangeArgument<C> optional(final @NonNull String name) {
return FloatRangeArgument.<C>newBuilder(name).asOptional().build(); return FloatRangeArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull FloatRangeArgument<C> optional( public static <C> @NonNull FloatRangeArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final NumberRange.FloatRange defaultValue final NumberRange.@NonNull FloatRange defaultValue
) { ) {
final StringBuilder value = new StringBuilder(6); final StringBuilder value = new StringBuilder(6);
if (defaultValue.getMin() != null) { if (defaultValue.getMin() != null) {
@ -118,6 +122,12 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
} }
/**
* Builder for {@link FloatRangeArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, NumberRange.FloatRange, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, NumberRange.FloatRange, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -125,13 +135,19 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
} }
/** /**
* Build a new criterion argument * Build a new float range argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull FloatRangeArgument<C> build() { public @NonNull FloatRangeArgument<C> build() {
return new FloatRangeArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new FloatRangeArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -65,6 +65,7 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> IdentifierArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> IdentifierArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new IdentifierArgument.Builder<>(name); return new IdentifierArgument.Builder<>(name);
@ -76,29 +77,32 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull IdentifierArgument<C> of(final @NonNull String name) { public static <C> @NonNull IdentifierArgument<C> of(final @NonNull String name) {
return IdentifierArgument.<C>newBuilder(name).asRequired().build(); return IdentifierArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull IdentifierArgument<C> optional(final @NonNull String name) { public static <C> @NonNull IdentifierArgument<C> optional(final @NonNull String name) {
return IdentifierArgument.<C>newBuilder(name).asOptional().build(); return IdentifierArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull IdentifierArgument<C> optional( public static <C> @NonNull IdentifierArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -108,6 +112,12 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
} }
/**
* Builder for {@link IdentifierArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, Identifier, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, Identifier, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -115,13 +125,19 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
} }
/** /**
* Build a new criterion argument * Build a new identifier argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull IdentifierArgument<C> build() { public @NonNull IdentifierArgument<C> build() {
return new IdentifierArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new IdentifierArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -66,6 +66,7 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> IntRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> IntRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new IntRangeArgument.Builder<>(name); return new IntRangeArgument.Builder<>(name);
@ -77,29 +78,32 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull IntRangeArgument<C> of(final @NonNull String name) { public static <C> @NonNull IntRangeArgument<C> of(final @NonNull String name) {
return IntRangeArgument.<C>newBuilder(name).asRequired().build(); return IntRangeArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull IntRangeArgument<C> optional(final @NonNull String name) { public static <C> @NonNull IntRangeArgument<C> optional(final @NonNull String name) {
return IntRangeArgument.<C>newBuilder(name).asOptional().build(); return IntRangeArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull IntRangeArgument<C> optional( public static <C> @NonNull IntRangeArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -118,6 +122,12 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
} }
/**
* Builder for {@link IntRangeArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, NumberRange.IntRange, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, NumberRange.IntRange, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -125,13 +135,19 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
} }
/** /**
* Build a new criterion argument * Build a new int range argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull IntRangeArgument<C> build() { public @NonNull IntRangeArgument<C> build() {
return new IntRangeArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new IntRangeArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -38,7 +38,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument parsing an item identifier and optional NBT data * An argument parsing an item identifier and optional NBT data.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -67,6 +67,7 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> ItemDataArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> ItemDataArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ItemDataArgument.Builder<>(name); return new ItemDataArgument.Builder<>(name);
@ -78,33 +79,36 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ItemDataArgument<C> of(final @NonNull String name) { public static <C> @NonNull ItemDataArgument<C> of(final @NonNull String name) {
return ItemDataArgument.<C>newBuilder(name).asRequired().build(); return ItemDataArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ItemDataArgument<C> optional(final @NonNull String name) { public static <C> @NonNull ItemDataArgument<C> optional(final @NonNull String name) {
return ItemDataArgument.<C>newBuilder(name).asOptional().build(); return ItemDataArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ItemDataArgument<C> optional( public static <C> @NonNull ItemDataArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final ItemStack defaultValue final @NonNull ItemStack defaultValue
) { ) {
final String serializedDefault; final String serializedDefault;
if (defaultValue.hasTag()) { if (defaultValue.hasTag()) {
@ -116,6 +120,11 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
} }
/**
* Builder for {@link ItemDataArgument}.
*
* @param <C> sender type
*/
public static final class Builder<C> extends TypedBuilder<C, ItemStackArgument, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, ItemStackArgument, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -123,13 +132,19 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
} }
/** /**
* Build a new criterion argument * Build a new item data argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull ItemDataArgument<C> build() { public @NonNull ItemDataArgument<C> build() {
return new ItemDataArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new ItemDataArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -59,45 +59,49 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
} }
/** /**
* Create a new builder * Create a new builder.
* *
* @param name Name of the component * @param name Name of the component
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> NbtPathArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> NbtPathArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new NbtPathArgument.Builder<>(name); return new NbtPathArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument * Create a new required command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull NbtPathArgument<C> of(final @NonNull String name) { public static <C> @NonNull NbtPathArgument<C> of(final @NonNull String name) {
return NbtPathArgument.<C>newBuilder(name).asRequired().build(); return NbtPathArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull NbtPathArgument<C> optional(final @NonNull String name) { public static <C> @NonNull NbtPathArgument<C> optional(final @NonNull String name) {
return NbtPathArgument.<C>newBuilder(name).asOptional().build(); return NbtPathArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Component name * @param name Component name
* @param defaultTag Default tag value * @param defaultTag Default tag value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created component * @return Created component
* @since 1.5.0
*/ */
public static <C> @NonNull NbtPathArgument<C> optional( public static <C> @NonNull NbtPathArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -107,6 +111,12 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
} }
/**
* Builder for {@link NbtPathArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, NbtPathArgumentType.NbtPath, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, NbtPathArgumentType.NbtPath, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -114,13 +124,19 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
} }
/** /**
* Builder a new example component * Build a new nbt path argument.
* *
* @return Constructed component * @return Constructed component
* @since 1.5.0
*/ */
@Override @Override
public @NonNull NbtPathArgument<C> build() { public @NonNull NbtPathArgument<C> build() {
return new NbtPathArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new NbtPathArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -60,45 +60,49 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
} }
/** /**
* Create a new builder * Create a new builder.
* *
* @param name Name of the component * @param name Name of the component
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> NbtTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> NbtTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new NbtTagArgument.Builder<>(name); return new NbtTagArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument * Create a new required command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull NbtTagArgument<C> of(final @NonNull String name) { public static <C> @NonNull NbtTagArgument<C> of(final @NonNull String name) {
return NbtTagArgument.<C>newBuilder(name).asRequired().build(); return NbtTagArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull NbtTagArgument<C> optional(final @NonNull String name) { public static <C> @NonNull NbtTagArgument<C> optional(final @NonNull String name) {
return NbtTagArgument.<C>newBuilder(name).asOptional().build(); return NbtTagArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Component name * @param name Component name
* @param defaultTag Default tag value * @param defaultTag Default tag value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created component * @return Created component
* @since 1.5.0
*/ */
public static <C> @NonNull NbtTagArgument<C> optional( public static <C> @NonNull NbtTagArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -108,6 +112,12 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
} }
/**
* Builder for {@link NbtTagArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, Tag, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, Tag, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -115,9 +125,10 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
} }
/** /**
* Builder a new example component * Build a new nbt tag argument.
* *
* @return Constructed component * @return Constructed component
* @since 1.5.0
*/ */
@Override @Override
public @NonNull NbtTagArgument<C> build() { public @NonNull NbtTagArgument<C> build() {

View file

@ -36,7 +36,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for any {@link net.minecraft.particle.ParticleEffect} * An argument for any {@link net.minecraft.particle.ParticleEffect}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -65,6 +65,7 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> ParticleEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> ParticleEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ParticleEffectArgument.Builder<>(name); return new ParticleEffectArgument.Builder<>(name);
@ -76,38 +77,47 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ParticleEffectArgument<C> of(final @NonNull String name) { public static <C> @NonNull ParticleEffectArgument<C> of(final @NonNull String name) {
return ParticleEffectArgument.<C>newBuilder(name).asRequired().build(); return ParticleEffectArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ParticleEffectArgument<C> optional(final @NonNull String name) { public static <C> @NonNull ParticleEffectArgument<C> optional(final @NonNull String name) {
return ParticleEffectArgument.<C>newBuilder(name).asOptional().build(); return ParticleEffectArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default particle effect value * @param defaultValue Default particle effect value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ParticleEffectArgument<C> optional( public static <C> @NonNull ParticleEffectArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final ParticleEffect defaultValue final @NonNull ParticleEffect defaultValue
) { ) {
return ParticleEffectArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.asString()).build(); return ParticleEffectArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.asString()).build();
} }
/**
* Builder for {@link ParticleEffectArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, ParticleEffect, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, ParticleEffect, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -115,13 +125,19 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
} }
/** /**
* Build a new criterion argument * Build a new particle effect argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull ParticleEffectArgument<C> build() { public @NonNull ParticleEffectArgument<C> build() {
return new ParticleEffectArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider()); return new ParticleEffectArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
} }
} }

View file

@ -61,6 +61,7 @@ import static java.util.Objects.requireNonNull;
* @since 1.5.0 * @since 1.5.0
*/ */
public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> { public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
private static final String NAMESPACE_MINECRAFT = "minecraft"; private static final String NAMESPACE_MINECRAFT = "minecraft";
RegistryEntryArgument( RegistryEntryArgument(
@ -77,46 +78,51 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
/** /**
* Create a new builder. * Create a new builder.
* *
* @param name Name of the argument * @param name Name of the argument
* @param type The type of registry entry * @param type The type of registry entry
* @param registry A key for the registry to get values from * @param registry A key for the registry to get values from
* @param <C> Command sender type * @param <C> Command sender type
* @param <V> Registry entry type * @param <V> Registry entry type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder( public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder(
final @NonNull String name, final @NonNull String name,
final @NonNull Class<V> type, final @NonNull Class<V> type,
final @NonNull RegistryKey<? extends Registry<V>> registry) { final @NonNull RegistryKey<? extends Registry<V>> registry
) {
return new RegistryEntryArgument.Builder<>(registry, type, name); return new RegistryEntryArgument.Builder<>(registry, type, name);
} }
/** /**
* Create a new builder. * Create a new builder.
* *
* @param name Name of the argument * @param name Name of the argument
* @param type The type of registry entry * @param type The type of registry entry
* @param registry A key for the registry to get values from * @param registry A key for the registry to get values from
* @param <C> Command sender type * @param <C> Command sender type
* @param <V> Registry entry type * @param <V> Registry entry type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder( public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder(
final @NonNull String name, final @NonNull String name,
final @NonNull TypeToken<V> type, final @NonNull TypeToken<V> type,
final @NonNull RegistryKey<? extends Registry<V>> registry) { final @NonNull RegistryKey<? extends Registry<V>> registry
) {
return new RegistryEntryArgument.Builder<>(registry, type, name); return new RegistryEntryArgument.Builder<>(registry, type, name);
} }
/** /**
* Create a new required command argument. * Create a new required command argument.
* *
* @param name Argument name * @param name Argument name
* @param type The type of registry entry * @param type The type of registry entry
* @param registry A key for the registry to get values from * @param registry A key for the registry to get values from
* @param <C> Command sender type * @param <C> Command sender type
* @param <V> Registry entry type * @param <V> Registry entry type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C, V> @NonNull RegistryEntryArgument<C, V> of( public static <C, V> @NonNull RegistryEntryArgument<C, V> of(
final @NonNull String name, final @NonNull String name,
@ -127,14 +133,15 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Argument name * @param name Argument name
* @param type The type of registry entry * @param type The type of registry entry
* @param registry A key for the registry to get values from * @param registry A key for the registry to get values from
* @param <C> Command sender type * @param <C> Command sender type
* @param <V> Registry entry type * @param <V> Registry entry type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C, V> @NonNull RegistryEntryArgument<C, V> optional( public static <C, V> @NonNull RegistryEntryArgument<C, V> optional(
final @NonNull String name, final @NonNull String name,
@ -145,15 +152,16 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param type The type of registry entry * @param type The type of registry entry
* @param registry A key for the registry to get values from * @param registry A key for the registry to get values from
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @param <V> Registry entry type * @param <V> Registry entry type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C, V> @NonNull RegistryEntryArgument<C, V> optional( public static <C, V> @NonNull RegistryEntryArgument<C, V> optional(
final @NonNull String name, final @NonNull String name,
@ -167,18 +175,21 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* A parser for values stored in a {@link Registry} * A parser for values stored in a {@link Registry}.
* *
* @param <C> Command sender type * @param <C> Command sender type
* @param <V> Registry entry type * @param <V> Registry entry type
* @since 1.5.0
*/ */
public static final class RegistryEntryParser<C, V> implements ArgumentParser<C, V> { public static final class RegistryEntryParser<C, V> implements ArgumentParser<C, V> {
private final RegistryKey<? extends Registry<V>> registryIdent; private final RegistryKey<? extends Registry<V>> registryIdent;
/** /**
* Create a new parser for registry entries. * Create a new parser for registry entries.
* *
* @param registryIdent the registry identifier * @param registryIdent the registry identifier
* @since 1.5.0
*/ */
public RegistryEntryParser(final RegistryKey<? extends Registry<V>> registryIdent) { public RegistryEntryParser(final RegistryKey<? extends Registry<V>> registryIdent) {
this.registryIdent = requireNonNull(registryIdent, "registryIdent"); this.registryIdent = requireNonNull(registryIdent, "registryIdent");
@ -253,8 +264,10 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Get the registry associated with this parser * Get the registry associated with this parser.
*
* @return the registry * @return the registry
* @since 1.5.0
*/ */
public RegistryKey<? extends Registry<?>> getRegistry() { public RegistryKey<? extends Registry<?>> getRegistry() {
return this.registryIdent; return this.registryIdent;
@ -267,8 +280,10 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
* *
* @param <C> The sender type * @param <C> The sender type
* @param <V> The registry value type * @param <V> The registry value type
* @since 1.5.0
*/ */
public static final class Builder<C, V> extends CommandArgument.TypedBuilder<C, V, Builder<C, V>> { public static final class Builder<C, V> extends CommandArgument.TypedBuilder<C, V, Builder<C, V>> {
private final RegistryKey<? extends Registry<V>> registryIdent; private final RegistryKey<? extends Registry<V>> registryIdent;
Builder( Builder(
@ -300,10 +315,13 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
this.getSuggestionsProvider() this.getSuggestionsProvider()
); );
} }
} }
/** /**
* An exception thrown when an entry in a registry could not be found. * An exception thrown when an entry in a registry could not be found.
*
* @since 1.5.0
*/ */
private static final class UnknownEntryException extends ParserException { private static final class UnknownEntryException extends ParserException {

View file

@ -65,6 +65,7 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> ScoreboardCriterionArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> ScoreboardCriterionArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ScoreboardCriterionArgument.Builder<>(name); return new ScoreboardCriterionArgument.Builder<>(name);
@ -76,29 +77,32 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ScoreboardCriterionArgument<C> of(final @NonNull String name) { public static <C> @NonNull ScoreboardCriterionArgument<C> of(final @NonNull String name) {
return ScoreboardCriterionArgument.<C>newBuilder(name).asRequired().build(); return ScoreboardCriterionArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ScoreboardCriterionArgument<C> optional(final @NonNull String name) { public static <C> @NonNull ScoreboardCriterionArgument<C> optional(final @NonNull String name) {
return ScoreboardCriterionArgument.<C>newBuilder(name).asOptional().build(); return ScoreboardCriterionArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultCriterion Default criterion * @param defaultCriterion Default criterion
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ScoreboardCriterionArgument<C> optional( public static <C> @NonNull ScoreboardCriterionArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -108,6 +112,12 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
} }
/**
* Builder for {@link ScoreboardCriterionArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, ScoreboardCriterion, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, ScoreboardCriterion, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -115,9 +125,10 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
} }
/** /**
* Build a new criterion argument * Build a new criterion argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull ScoreboardCriterionArgument<C> build() { public @NonNull ScoreboardCriterionArgument<C> build() {

View file

@ -67,6 +67,7 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> ScoreboardOperationArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> ScoreboardOperationArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ScoreboardOperationArgument.Builder<>(name); return new ScoreboardOperationArgument.Builder<>(name);
@ -78,22 +79,30 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ScoreboardOperationArgument<C> of(final @NonNull String name) { public static <C> @NonNull ScoreboardOperationArgument<C> of(final @NonNull String name) {
return ScoreboardOperationArgument.<C>newBuilder(name).asRequired().build(); return ScoreboardOperationArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull ScoreboardOperationArgument<C> optional(final @NonNull String name) { public static <C> @NonNull ScoreboardOperationArgument<C> optional(final @NonNull String name) {
return ScoreboardOperationArgument.<C>newBuilder(name).asOptional().build(); return ScoreboardOperationArgument.<C>newBuilder(name).asOptional().build();
} }
/**
* Builder for {@link ScoreboardOperationArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, Operation, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, Operation, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -101,9 +110,10 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
} }
/** /**
* Build a new criterion argument * Build a new operation argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull ScoreboardOperationArgument<C> build() { public @NonNull ScoreboardOperationArgument<C> build() {

View file

@ -42,6 +42,7 @@ import java.util.Queue;
* @param <C> command sender type * @param <C> command sender type
* @param <I> intermediate type to resolve * @param <I> intermediate type to resolve
* @param <R> resolved type * @param <R> resolved type
* @since 1.5.0
*/ */
abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> { abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
@ -73,9 +74,10 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
* Resolve the final value for this argument when running on the client. * Resolve the final value for this argument when running on the client.
* *
* @param context Command context * @param context Command context
* @param source The command source * @param source The command source
* @param value parsed intermediate value * @param value parsed intermediate value
* @return a resolved value * @return a resolved value
* @since 1.5.0
*/ */
protected abstract ArgumentParseResult<R> resolveClient(CommandContext<C> context, CommandSource source, I value); protected abstract ArgumentParseResult<R> resolveClient(CommandContext<C> context, CommandSource source, I value);
@ -83,9 +85,10 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
* Resolve the final value for this argument when running on the server. * Resolve the final value for this argument when running on the server.
* *
* @param context Command context * @param context Command context
* @param source The command source * @param source The command source
* @param value Parsed intermediate value * @param value Parsed intermediate value
* @return a resolved value * @return a resolved value
* @since 1.5.0
*/ */
protected abstract ArgumentParseResult<R> resolveServer(CommandContext<C> context, CommandSource source, I value); protected abstract ArgumentParseResult<R> resolveServer(CommandContext<C> context, CommandSource source, I value);

View file

@ -37,7 +37,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument parsing a status effect from the {@link net.minecraft.util.registry.Registry#STATUS_EFFECT status effect registry} * An argument parsing a status effect from the {@link net.minecraft.util.registry.Registry#STATUS_EFFECT status effect registry}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -66,6 +66,7 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> StatusEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> StatusEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new StatusEffectArgument.Builder<>(name); return new StatusEffectArgument.Builder<>(name);
@ -77,29 +78,32 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull StatusEffectArgument<C> of(final @NonNull String name) { public static <C> @NonNull StatusEffectArgument<C> of(final @NonNull String name) {
return StatusEffectArgument.<C>newBuilder(name).asRequired().build(); return StatusEffectArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull StatusEffectArgument<C> optional(final @NonNull String name) { public static <C> @NonNull StatusEffectArgument<C> optional(final @NonNull String name) {
return StatusEffectArgument.<C>newBuilder(name).asOptional().build(); return StatusEffectArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull StatusEffectArgument<C> optional( public static <C> @NonNull StatusEffectArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -111,6 +115,12 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
} }
/**
* Builder for {@link StatusEffectArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, StatusEffect, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, StatusEffect, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -118,9 +128,10 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
} }
/** /**
* Build a new criterion argument * Build a new status effect argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull StatusEffectArgument<C> build() { public @NonNull StatusEffectArgument<C> build() {

View file

@ -75,6 +75,7 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> TeamArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> TeamArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new TeamArgument.Builder<>(name); return new TeamArgument.Builder<>(name);
@ -86,29 +87,32 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull TeamArgument<C> of(final @NonNull String name) { public static <C> @NonNull TeamArgument<C> of(final @NonNull String name) {
return TeamArgument.<C>newBuilder(name).asRequired().build(); return TeamArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull TeamArgument<C> optional(final @NonNull String name) { public static <C> @NonNull TeamArgument<C> optional(final @NonNull String name) {
return TeamArgument.<C>newBuilder(name).asOptional().build(); return TeamArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull TeamArgument<C> optional( public static <C> @NonNull TeamArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -117,6 +121,12 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
return TeamArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.name()).build(); return TeamArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.name()).build();
} }
/**
* Argument parser for {@link Team}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class TeamParser<C> extends SidedArgumentParser<C, String, Team> { public static final class TeamParser<C> extends SidedArgumentParser<C, String, Team> {
@Override @Override
@ -140,9 +150,11 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
@Override @Override
protected ArgumentParseResult<Team> resolveClient(final CommandContext<C> context, protected ArgumentParseResult<Team> resolveClient(
final CommandSource source, final @NonNull CommandContext<C> context,
final String value) { final @NonNull CommandSource source,
final @NonNull String value
) {
final Team result = MinecraftClient.getInstance().getNetworkHandler().getWorld().getScoreboard().getTeam(value); final Team result = MinecraftClient.getInstance().getNetworkHandler().getWorld().getScoreboard().getTeam(value);
if (result == null) { if (result == null) {
return ArgumentParseResult.failure(new UnknownTeamException(context, value)); return ArgumentParseResult.failure(new UnknownTeamException(context, value));
@ -151,9 +163,11 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
@Override @Override
protected ArgumentParseResult<Team> resolveServer(final CommandContext<C> context, protected ArgumentParseResult<Team> resolveServer(
final CommandSource source, final @NonNull CommandContext<C> context,
final String value) { final @NonNull CommandSource source,
final @NonNull String value
) {
final Team result = ((ServerCommandSource) source).getWorld().getScoreboard().getTeam(value); final Team result = ((ServerCommandSource) source).getWorld().getScoreboard().getTeam(value);
if (result == null) { if (result == null) {
return ArgumentParseResult.failure(new UnknownTeamException(context, value)); return ArgumentParseResult.failure(new UnknownTeamException(context, value));
@ -163,6 +177,12 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
/**
* Builder for {@link TeamArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, Team, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, Team, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -170,9 +190,10 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
/** /**
* Build a new criterion argument * Build a new team argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull TeamArgument<C> build() { public @NonNull TeamArgument<C> build() {
@ -181,7 +202,13 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
/**
* Exception for when a team cannot be found for supplied input.
*
* @since 1.5.0
*/
public static final class UnknownTeamException extends ParserException { public static final class UnknownTeamException extends ParserException {
private static final long serialVersionUID = 4249139487412603424L; private static final long serialVersionUID = 4249139487412603424L;
UnknownTeamException( UnknownTeamException(

View file

@ -34,7 +34,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for in-game time * An argument for in-game time.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -63,6 +63,7 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> TimeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> TimeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new TimeArgument.Builder<>(name); return new TimeArgument.Builder<>(name);
@ -74,29 +75,32 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull TimeArgument<C> of(final @NonNull String name) { public static <C> @NonNull TimeArgument<C> of(final @NonNull String name) {
return TimeArgument.<C>newBuilder(name).asRequired().build(); return TimeArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull TimeArgument<C> optional(final @NonNull String name) { public static <C> @NonNull TimeArgument<C> optional(final @NonNull String name) {
return TimeArgument.<C>newBuilder(name).asOptional().build(); return TimeArgument.<C>newBuilder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional command argument with a default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultTime Default time, in ticks * @param defaultTime Default time, in ticks
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull TimeArgument<C> optional( public static <C> @NonNull TimeArgument<C> optional(
final @NonNull String name, final @NonNull String name,
@ -106,6 +110,12 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
} }
/**
* Builder for {@link TimeArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, MinecraftTime, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, MinecraftTime, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -113,9 +123,10 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
} }
/** /**
* Build a new time argument * Build a new time argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull TimeArgument<C> build() { public @NonNull TimeArgument<C> build() {

View file

@ -24,5 +24,7 @@
/** /**
* Arguments for the Fabric environment. * Arguments for the Fabric environment.
*
* @since 1.5.0
*/ */
package cloud.commandframework.fabric.argument; package cloud.commandframework.fabric.argument;

View file

@ -64,6 +64,7 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> MessageArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> MessageArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new MessageArgument.Builder<>(name); return new MessageArgument.Builder<>(name);
@ -75,6 +76,7 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull MessageArgument<C> of(final @NonNull String name) { public static <C> @NonNull MessageArgument<C> of(final @NonNull String name) {
return MessageArgument.<C>newBuilder(name).asRequired().build(); return MessageArgument.<C>newBuilder(name).asRequired().build();
@ -86,6 +88,7 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull MessageArgument<C> optional(final @NonNull String name) { public static <C> @NonNull MessageArgument<C> optional(final @NonNull String name) {
return MessageArgument.<C>newBuilder(name).asOptional().build(); return MessageArgument.<C>newBuilder(name).asOptional().build();
@ -98,15 +101,22 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
* @param defaultValue Default value * @param defaultValue Default value
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull MessageArgument<C> optional( public static <C> @NonNull MessageArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final String defaultValue final @NonNull String defaultValue
) { ) {
return MessageArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build(); return MessageArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
} }
/**
* Builder for {@link MessageArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, Message, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, Message, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -114,9 +124,10 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
} }
/** /**
* Build a new criterion argument * Build a new message argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull MessageArgument<C> build() { public @NonNull MessageArgument<C> build() {

View file

@ -63,6 +63,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> MultipleEntitySelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> MultipleEntitySelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new MultipleEntitySelectorArgument.Builder<>(name); return new MultipleEntitySelectorArgument.Builder<>(name);
@ -74,6 +75,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull MultipleEntitySelectorArgument<C> of(final @NonNull String name) { public static <C> @NonNull MultipleEntitySelectorArgument<C> of(final @NonNull String name) {
return MultipleEntitySelectorArgument.<C>newBuilder(name).asRequired().build(); return MultipleEntitySelectorArgument.<C>newBuilder(name).asRequired().build();
@ -85,11 +87,18 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull MultipleEntitySelectorArgument<C> optional(final @NonNull String name) { public static <C> @NonNull MultipleEntitySelectorArgument<C> optional(final @NonNull String name) {
return MultipleEntitySelectorArgument.<C>newBuilder(name).asOptional().build(); return MultipleEntitySelectorArgument.<C>newBuilder(name).asOptional().build();
} }
/**
* Builder for {@link MultipleEntitySelectorArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, MultipleEntitySelector, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, MultipleEntitySelector, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -97,9 +106,10 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
} }
/** /**
* Build a multiple entity selector argument * Build a multiple entity selector argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull MultipleEntitySelectorArgument<C> build() { public @NonNull MultipleEntitySelectorArgument<C> build() {

View file

@ -63,6 +63,7 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> MultiplePlayerSelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> MultiplePlayerSelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new MultiplePlayerSelectorArgument.Builder<>(name); return new MultiplePlayerSelectorArgument.Builder<>(name);
@ -74,22 +75,30 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull MultiplePlayerSelectorArgument<C> of(final @NonNull String name) { public static <C> @NonNull MultiplePlayerSelectorArgument<C> of(final @NonNull String name) {
return MultiplePlayerSelectorArgument.<C>newBuilder(name).asRequired().build(); return MultiplePlayerSelectorArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull MultiplePlayerSelectorArgument<C> optional(final @NonNull String name) { public static <C> @NonNull MultiplePlayerSelectorArgument<C> optional(final @NonNull String name) {
return MultiplePlayerSelectorArgument.<C>newBuilder(name).asOptional().build(); return MultiplePlayerSelectorArgument.<C>newBuilder(name).asOptional().build();
} }
/**
* Builder for {@link MultiplePlayerSelectorArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, MultiplePlayerSelector, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, MultiplePlayerSelector, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -97,9 +106,10 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
} }
/** /**
* Build a multiple player selector argument * Build a multiple player selector argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull MultiplePlayerSelectorArgument<C> build() { public @NonNull MultiplePlayerSelectorArgument<C> build() {

View file

@ -63,6 +63,7 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> SingleEntitySelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> SingleEntitySelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new SingleEntitySelectorArgument.Builder<>(name); return new SingleEntitySelectorArgument.Builder<>(name);
@ -74,22 +75,30 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull SingleEntitySelectorArgument<C> of(final @NonNull String name) { public static <C> @NonNull SingleEntitySelectorArgument<C> of(final @NonNull String name) {
return SingleEntitySelectorArgument.<C>newBuilder(name).asRequired().build(); return SingleEntitySelectorArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull SingleEntitySelectorArgument<C> optional(final @NonNull String name) { public static <C> @NonNull SingleEntitySelectorArgument<C> optional(final @NonNull String name) {
return SingleEntitySelectorArgument.<C>newBuilder(name).asOptional().build(); return SingleEntitySelectorArgument.<C>newBuilder(name).asOptional().build();
} }
/**
* Builder for {@link SingleEntitySelectorArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, SingleEntitySelector, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, SingleEntitySelector, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -97,9 +106,10 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
} }
/** /**
* Build a single entity selector argument * Build a single entity selector argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull SingleEntitySelectorArgument<C> build() { public @NonNull SingleEntitySelectorArgument<C> build() {

View file

@ -63,6 +63,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
* @param name Name of the argument * @param name Name of the argument
* @param <C> Command sender type * @param <C> Command sender type
* @return Created builder * @return Created builder
* @since 1.5.0
*/ */
public static <C> SinglePlayerSelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> SinglePlayerSelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new SinglePlayerSelectorArgument.Builder<>(name); return new SinglePlayerSelectorArgument.Builder<>(name);
@ -74,22 +75,30 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull SinglePlayerSelectorArgument<C> of(final @NonNull String name) { public static <C> @NonNull SinglePlayerSelectorArgument<C> of(final @NonNull String name) {
return SinglePlayerSelectorArgument.<C>newBuilder(name).asRequired().build(); return SinglePlayerSelectorArgument.<C>newBuilder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional command argument.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0
*/ */
public static <C> @NonNull SinglePlayerSelectorArgument<C> optional(final @NonNull String name) { public static <C> @NonNull SinglePlayerSelectorArgument<C> optional(final @NonNull String name) {
return SinglePlayerSelectorArgument.<C>newBuilder(name).asOptional().build(); return SinglePlayerSelectorArgument.<C>newBuilder(name).asOptional().build();
} }
/**
* Builder for {@link SinglePlayerSelectorArgument}.
*
* @param <C> sender type
* @since 1.5.0
*/
public static final class Builder<C> extends TypedBuilder<C, SinglePlayerSelector, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, SinglePlayerSelector, Builder<C>> {
Builder(final @NonNull String name) { Builder(final @NonNull String name) {
@ -97,9 +106,10 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
} }
/** /**
* Build a single player selector argument * Build a single player selector argument.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0
*/ */
@Override @Override
public @NonNull SinglePlayerSelectorArgument<C> build() { public @NonNull SinglePlayerSelectorArgument<C> build() {

View file

@ -32,6 +32,8 @@ import java.util.Collection;
/** /**
* A parsed message. * A parsed message.
*
* @since 1.5.0
*/ */
public interface Message { public interface Message {
@ -39,6 +41,7 @@ public interface Message {
* Get the collection of entities mentioned in this message. * Get the collection of entities mentioned in this message.
* *
* @return the mentioned entities * @return the mentioned entities
* @since 1.5.0
*/ */
@NonNull Collection<Entity> getMentionedEntities(); @NonNull Collection<Entity> getMentionedEntities();
@ -46,6 +49,7 @@ public interface Message {
* Get the parsed text contents of this message. * Get the parsed text contents of this message.
* *
* @return the parsed text * @return the parsed text
* @since 1.5.0
*/ */
@NonNull Text getContents(); @NonNull Text getContents();

View file

@ -38,6 +38,7 @@ import static java.util.Objects.requireNonNull;
* @since 1.5.0 * @since 1.5.0
*/ */
public final class MinecraftTime { public final class MinecraftTime {
private static final MinecraftTime ZERO = new MinecraftTime(0); private static final MinecraftTime ZERO = new MinecraftTime(0);
private final long ticks; private final long ticks;
@ -47,6 +48,7 @@ public final class MinecraftTime {
* *
* @param ticks the number of ticks * @param ticks the number of ticks
* @return a time holder * @return a time holder
* @since 1.5.0
*/ */
public static MinecraftTime of(final long ticks) { public static MinecraftTime of(final long ticks) {
return ticks == 0 ? ZERO : new MinecraftTime(ticks); return ticks == 0 ? ZERO : new MinecraftTime(ticks);
@ -56,8 +58,9 @@ public final class MinecraftTime {
* Given an amount of time in another unit, create a game time holding the number of ticks expected to pass in that time. * Given an amount of time in another unit, create a game time holding the number of ticks expected to pass in that time.
* *
* @param amount the amount of time * @param amount the amount of time
* @param unit the unit * @param unit the unit
* @return a time holder * @return a time holder
* @since 1.5.0
*/ */
public static MinecraftTime of(final long amount, final TemporalUnit unit) { public static MinecraftTime of(final long amount, final TemporalUnit unit) {
requireNonNull(unit, "unit"); requireNonNull(unit, "unit");
@ -68,8 +71,9 @@ public final class MinecraftTime {
* Given an amount of time in another unit, create a game time holding the number of ticks expected to pass in that time. * Given an amount of time in another unit, create a game time holding the number of ticks expected to pass in that time.
* *
* @param amount the amount of time * @param amount the amount of time
* @param unit the unit * @param unit the unit
* @return a time holder * @return a time holder
* @since 1.5.0
*/ */
public static MinecraftTime of(final long amount, final TimeUnit unit) { public static MinecraftTime of(final long amount, final TimeUnit unit) {
requireNonNull(unit, "unit"); requireNonNull(unit, "unit");
@ -87,6 +91,7 @@ public final class MinecraftTime {
* See {@link #getLongTicks()} for the full contents.</p> * See {@link #getLongTicks()} for the full contents.</p>
* *
* @return the time in ticks * @return the time in ticks
* @since 1.5.0
*/ */
public int getTicks() { public int getTicks() {
return (int) this.ticks; return (int) this.ticks;
@ -96,6 +101,7 @@ public final class MinecraftTime {
* Get the number of in-game ticks represented by this time. * Get the number of in-game ticks represented by this time.
* *
* @return the time in ticks * @return the time in ticks
* @since 1.5.0
*/ */
public long getLongTicks() { public long getLongTicks() {
return this.ticks; return this.ticks;
@ -106,6 +112,7 @@ public final class MinecraftTime {
* *
* @param unit the target unit * @param unit the target unit
* @return the target duration, as represented by the provided unit * @return the target duration, as represented by the provided unit
* @since 1.5.0
*/ */
public long convertTo(final TemporalUnit unit) { public long convertTo(final TemporalUnit unit) {
return this.ticks * 50 / unit.getDuration().toMillis(); return this.ticks * 50 / unit.getDuration().toMillis();
@ -116,6 +123,7 @@ public final class MinecraftTime {
* *
* @param unit the target unit * @param unit the target unit
* @return the target duration, as represented by the provided unit * @return the target duration, as represented by the provided unit
* @since 1.5.0
*/ */
public long convertTo(final TimeUnit unit) { public long convertTo(final TimeUnit unit) {
return unit.convert(this.ticks * 50, TimeUnit.MILLISECONDS); return unit.convert(this.ticks * 50, TimeUnit.MILLISECONDS);

View file

@ -31,6 +31,8 @@ import java.util.Collection;
/** /**
* A selector for multiple entities. * A selector for multiple entities.
*
* @since 1.5.0
*/ */
public final class MultipleEntitySelector implements Selector<Entity> { public final class MultipleEntitySelector implements Selector<Entity> {
@ -44,6 +46,7 @@ public final class MultipleEntitySelector implements Selector<Entity> {
* @param inputString input string * @param inputString input string
* @param entitySelector entity selector * @param entitySelector entity selector
* @param selectedEntities selected entities * @param selectedEntities selected entities
* @since 1.5.0
*/ */
public MultipleEntitySelector( public MultipleEntitySelector(
final @NonNull String inputString, final @NonNull String inputString,

View file

@ -31,6 +31,8 @@ import java.util.Collection;
/** /**
* A selector for multiple players. * A selector for multiple players.
*
* @since 1.5.0
*/ */
public final class MultiplePlayerSelector implements Selector<ServerPlayerEntity> { public final class MultiplePlayerSelector implements Selector<ServerPlayerEntity> {
@ -44,6 +46,7 @@ public final class MultiplePlayerSelector implements Selector<ServerPlayerEntity
* @param inputString input string * @param inputString input string
* @param entitySelector entity selector * @param entitySelector entity selector
* @param selectedPlayers selected players * @param selectedPlayers selected players
* @since 1.5.0
*/ */
public MultiplePlayerSelector( public MultiplePlayerSelector(
final @NonNull String inputString, final @NonNull String inputString,

View file

@ -34,6 +34,7 @@ import java.util.Collections;
* A selector string to query multiple entity-like values * A selector string to query multiple entity-like values
* *
* @param <V> Value type * @param <V> Value type
* @since 1.5.0
*/ */
public interface Selector<V> { public interface Selector<V> {
@ -41,6 +42,7 @@ public interface Selector<V> {
* Get the raw string associated with the selector. * Get the raw string associated with the selector.
* *
* @return the input * @return the input
* @since 1.5.0
*/ */
String getInput(); String getInput();
@ -48,6 +50,7 @@ public interface Selector<V> {
* If this value came from a parsed selector, this will provide the details of that selector. * If this value came from a parsed selector, this will provide the details of that selector.
* *
* @return the selector * @return the selector
* @since 1.5.0
*/ */
@Nullable EntitySelector getSelector(); @Nullable EntitySelector getSelector();
@ -57,6 +60,7 @@ public interface Selector<V> {
* <p>A successfully parsed selector must match one or more values</p> * <p>A successfully parsed selector must match one or more values</p>
* *
* @return all matched entities * @return all matched entities
* @since 1.5.0
*/ */
Collection<V> get(); Collection<V> get();
@ -64,6 +68,7 @@ public interface Selector<V> {
* A specialized selector that can only return one value. * A specialized selector that can only return one value.
* *
* @param <V> the value type * @param <V> the value type
* @since 1.5.0
*/ */
interface Single<V> extends Selector<V> { interface Single<V> extends Selector<V> {
@ -72,7 +77,14 @@ public interface Selector<V> {
return Collections.singletonList(this.getSingle()); return Collections.singletonList(this.getSingle());
} }
/**
* Get the single value from this selector.
*
* @return the value
* @since 1.5.0
*/
V getSingle(); V getSingle();
} }
} }

View file

@ -29,6 +29,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
/** /**
* A selector for a single entity. * A selector for a single entity.
*
* @since 1.5.0
*/ */
public final class SingleEntitySelector implements Selector.Single<Entity> { public final class SingleEntitySelector implements Selector.Single<Entity> {
@ -42,6 +44,7 @@ public final class SingleEntitySelector implements Selector.Single<Entity> {
* @param inputString input string * @param inputString input string
* @param entitySelector entity selector * @param entitySelector entity selector
* @param selectedEntity selected entity * @param selectedEntity selected entity
* @since 1.5.0
*/ */
public SingleEntitySelector( public SingleEntitySelector(
final @NonNull String inputString, final @NonNull String inputString,

View file

@ -29,6 +29,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
/** /**
* A selector for a single player. * A selector for a single player.
*
* @since 1.5.0
*/ */
public final class SinglePlayerSelector implements Selector.Single<ServerPlayerEntity> { public final class SinglePlayerSelector implements Selector.Single<ServerPlayerEntity> {
@ -42,6 +44,7 @@ public final class SinglePlayerSelector implements Selector.Single<ServerPlayerE
* @param inputString input string * @param inputString input string
* @param entitySelector entity selector * @param entitySelector entity selector
* @param selectedPlayer selected player * @param selectedPlayer selected player
* @since 1.5.0
*/ */
public SinglePlayerSelector( public SinglePlayerSelector(
final @NonNull String inputString, final @NonNull String inputString,

View file

@ -24,5 +24,7 @@
/** /**
* Data holders for representing Vanilla argument type values. * Data holders for representing Vanilla argument type values.
*
* @since 1.5.0
*/ */
package cloud.commandframework.fabric.data; package cloud.commandframework.fabric.data;

View file

@ -23,6 +23,8 @@
// //
/** /**
* Fabric API-based implementation of Cloud * Fabric API-based implementation of Cloud.
*
* @since 1.5.0
*/ */
package cloud.commandframework.fabric; package cloud.commandframework.fabric;