fabric: General cleanup and javadoc improvements

This commit is contained in:
jmp 2021-05-03 20:39:04 -07:00 committed by Jason
parent f90db1c648
commit ab86332990
37 changed files with 752 additions and 539 deletions

View file

@ -26,7 +26,7 @@ package cloud.commandframework.fabric;
import cloud.commandframework.captions.SimpleCaptionRegistry; import cloud.commandframework.captions.SimpleCaptionRegistry;
/** /**
* Caption registry that uses bi-functions to produce messages * Caption registry that uses bi-functions to produce messages.
* *
* @param <C> Command sender type * @param <C> Command sender type
* @since 1.5.0 * @since 1.5.0
@ -38,7 +38,9 @@ public class FabricCaptionRegistry<C> extends SimpleCaptionRegistry<C> {
* *
* @since 1.5.0 * @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 value with key '{id}' in registry '{registry}'.";
/** /**
* Default caption for {@link FabricCaptionKeys#ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN} * Default caption for {@link FabricCaptionKeys#ARGUMENT_PARSE_FAILURE_TEAM_UNKNOWN}
* *

View file

@ -208,7 +208,7 @@ 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( this.brigadierManager.registerMapping(
new TypeToken<RegistryEntryArgument.RegistryEntryParser<C, ?>>() { new TypeToken<RegistryEntryArgument.Parser<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 */
@ -289,7 +289,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
/* and now, finally, we can register */ /* and now, finally, we can register */
this.getParserRegistry().registerParserSupplier( this.getParserRegistry().registerParserSupplier(
TypeToken.get(valueType), TypeToken.get(valueType),
params -> new RegistryEntryArgument.RegistryEntryParser(key) params -> new RegistryEntryArgument.Parser(key)
); );
} }
} }

View file

@ -29,7 +29,6 @@ import cloud.commandframework.exceptions.InvalidCommandSenderException;
import cloud.commandframework.exceptions.InvalidSyntaxException; import cloud.commandframework.exceptions.InvalidSyntaxException;
import cloud.commandframework.exceptions.NoPermissionException; import cloud.commandframework.exceptions.NoPermissionException;
import cloud.commandframework.exceptions.NoSuchCommandException; import cloud.commandframework.exceptions.NoSuchCommandException;
import cloud.commandframework.execution.CommandResult;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
@ -52,6 +51,7 @@ import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
final class FabricExecutor<C, S extends CommandSource> implements Command<S> { final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
private static final Text NEWLINE = new LiteralText("\n"); private static final Text NEWLINE = new LiteralText("\n");
@ -80,104 +80,96 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
final S source = ctx.getSource(); final S source = ctx.getSource();
final String input = ctx.getInput().substring(ctx.getLastChild().getNodes().get(0).getRange().getStart()); final String input = ctx.getInput().substring(ctx.getLastChild().getNodes().get(0).getRange().getStart());
final C sender = this.manager.getCommandSourceMapper().apply(source); final C sender = this.manager.getCommandSourceMapper().apply(source);
this.manager.executeCommand(sender, input).whenComplete(this.getResultConsumer(source, sender)); this.manager.executeCommand(sender, input).whenComplete((result, throwable) -> {
if (throwable == null) {
return;
}
if (throwable instanceof CompletionException) {
throwable = throwable.getCause();
}
this.handleThrowable(source, sender, throwable);
});
return com.mojang.brigadier.Command.SINGLE_SUCCESS; return com.mojang.brigadier.Command.SINGLE_SUCCESS;
} }
private @NonNull BiConsumer<@NonNull CommandResult<C>, ? super Throwable> getResultConsumer( private void handleThrowable(final @NonNull S source, final @NonNull C sender, final @NonNull Throwable throwable) {
final @NonNull S source, if (throwable instanceof InvalidSyntaxException) {
final @NonNull C sender this.manager.handleException(
) { sender,
return (result, throwable) -> { InvalidSyntaxException.class,
if (throwable != null) { (InvalidSyntaxException) throwable,
if (throwable instanceof CompletionException) { (c, e) -> this.sendError.accept(
throwable = throwable.getCause(); source,
} new LiteralText("Invalid Command Syntax. Correct command syntax is: ")
final Throwable finalThrowable = throwable; .append(new LiteralText(String.format("/%s", e.getCorrectSyntax()))
if (throwable instanceof InvalidSyntaxException) { .styled(style -> style.withColor(Formatting.GRAY)))
this.manager.handleException( )
sender, );
InvalidSyntaxException.class, } else if (throwable instanceof InvalidCommandSenderException) {
(InvalidSyntaxException) throwable, this.manager.handleException(
(c, e) -> sender,
this.sendError.accept( InvalidCommandSenderException.class,
source, (InvalidCommandSenderException) throwable,
new LiteralText("Invalid Command Syntax. Correct command syntax is: ") (c, e) -> this.sendError.accept(source, new LiteralText(throwable.getMessage()))
.append(new LiteralText(String.format("/%s", e.getCorrectSyntax())) );
.styled(style -> style.withColor(Formatting.GRAY)))) } else if (throwable instanceof NoPermissionException) {
); this.manager.handleException(
} else if (throwable instanceof InvalidCommandSenderException) { sender,
this.manager.handleException( NoPermissionException.class,
sender, (NoPermissionException) throwable,
InvalidCommandSenderException.class, (c, e) -> this.sendError.accept(source, new LiteralText(MESSAGE_NO_PERMS))
(InvalidCommandSenderException) throwable, );
(c, e) -> } else if (throwable instanceof NoSuchCommandException) {
this.sendError.accept(source, new LiteralText(finalThrowable.getMessage())) this.manager.handleException(
); sender,
} else if (throwable instanceof NoPermissionException) { NoSuchCommandException.class,
this.manager.handleException( (NoSuchCommandException) throwable,
sender, (c, e) -> this.sendError.accept(source, new LiteralText(MESSAGE_UNKNOWN_COMMAND))
NoPermissionException.class, );
(NoPermissionException) throwable, } else if (throwable instanceof ArgumentParseException) {
(c, e) -> this.sendError.accept(source, new LiteralText(MESSAGE_NO_PERMS)) this.manager.handleException(
); sender,
} else if (throwable instanceof NoSuchCommandException) { ArgumentParseException.class,
this.manager.handleException( (ArgumentParseException) throwable,
sender, (c, e) -> {
NoSuchCommandException.class, if (throwable.getCause() instanceof CommandSyntaxException) {
(NoSuchCommandException) throwable, this.sendError.accept(source, new LiteralText("Invalid Command Argument: ")
(c, e) -> this.sendError.accept(source, new LiteralText(MESSAGE_UNKNOWN_COMMAND)) .append(new LiteralText("")
); .append(Texts.toText(((CommandSyntaxException) throwable.getCause()).getRawMessage()))
} else if (throwable instanceof ArgumentParseException) {
this.manager.handleException(
sender,
ArgumentParseException.class,
(ArgumentParseException) throwable,
(c, e) -> {
if (finalThrowable.getCause() instanceof CommandSyntaxException) {
this.sendError.accept(source, new LiteralText("Invalid Command Argument: ")
.append(new LiteralText("")
.append(Texts.toText(((CommandSyntaxException) finalThrowable.getCause()).getRawMessage()))
.formatted(Formatting.GRAY))); .formatted(Formatting.GRAY)));
} else { } else {
this.sendError.accept(source, new LiteralText("Invalid Command Argument: ") this.sendError.accept(source, new LiteralText("Invalid Command Argument: ")
.append(new LiteralText(finalThrowable.getCause().getMessage()) .append(new LiteralText(throwable.getCause().getMessage())
.formatted(Formatting.GRAY))); .formatted(Formatting.GRAY)));
} }
} }
); );
} else if (throwable instanceof CommandExecutionException) { } else if (throwable instanceof CommandExecutionException) {
this.manager.handleException( this.manager.handleException(
sender, sender,
CommandExecutionException.class, CommandExecutionException.class,
(CommandExecutionException) throwable, (CommandExecutionException) throwable,
(c, e) -> { (c, e) -> {
this.sendError.accept(source, this.decorateHoverStacktrace( this.sendError.accept(source, this.decorateHoverStacktrace(
new LiteralText(MESSAGE_INTERNAL_ERROR), new LiteralText(MESSAGE_INTERNAL_ERROR),
finalThrowable.getCause(), throwable.getCause(),
sender sender
)); ));
LOGGER.warn( LOGGER.warn(
"Error occurred while executing command for user {}:", "Error occurred while executing command for user {}:",
this.getName.apply(source), this.getName.apply(source),
finalThrowable throwable
); );
} }
); );
} else { } else {
this.sendError.accept(source, this.decorateHoverStacktrace( this.sendError.accept(source, this.decorateHoverStacktrace(
new LiteralText(MESSAGE_INTERNAL_ERROR), new LiteralText(MESSAGE_INTERNAL_ERROR),
throwable, throwable,
sender sender
)); ));
LOGGER.warn( LOGGER.warn("Error occurred while executing command for user {}:", this.getName.apply(source), throwable);
"Error occurred while executing command for user {}:", }
this.getName.apply(source),
throwable
);
}
}
};
} }
private MutableText decorateHoverStacktrace(final MutableText input, final Throwable cause, final C sender) { private MutableText decorateHoverStacktrace(final MutableText input, final Throwable cause, final C sender) {
@ -189,13 +181,12 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
cause.printStackTrace(new PrintWriter(writer)); cause.printStackTrace(new PrintWriter(writer));
final String stackTrace = writer.toString().replace("\t", " "); final String stackTrace = writer.toString().replace("\t", " ");
return input.styled(style -> style return input.styled(style -> style
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, .withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new LiteralText(stackTrace) new LiteralText(stackTrace)
.append(NEWLINE) .append(NEWLINE)
.append(new LiteralText(" Click to copy") .append(new LiteralText(" Click to copy")
.styled(s2 -> s2 .styled(s2 -> s2.withColor(Formatting.GRAY).withItalic(true)))
.withColor(Formatting.GRAY)
.withItalic(true)))
)) ))
.withClickEvent(new ClickEvent( .withClickEvent(new ClickEvent(
ClickEvent.Action.COPY_TO_CLIPBOARD, ClickEvent.Action.COPY_TO_CLIPBOARD,

View file

@ -189,7 +189,8 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
/** /**
* Check if a sender has a certain permission. * Check if a sender has a certain permission.
* *
* <p>The current implementation checks op level, pending a full Fabric permissions api.</p> * <p>The current implementation checks permissions using {@code fabric-permissions-api-v0},
* falling back to op level checks.</p>
* *
* @param sender Command sender * @param sender Command sender
* @param permission Permission node * @param permission Permission node

View file

@ -23,8 +23,8 @@
// //
package cloud.commandframework.fabric.annotations.specifier; package cloud.commandframework.fabric.annotations.specifier;
import cloud.commandframework.fabric.argument.server.Vec2Argument; import cloud.commandframework.fabric.argument.server.Vec2dArgument;
import cloud.commandframework.fabric.argument.server.Vec3Argument; import cloud.commandframework.fabric.argument.server.Vec3dArgument;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -32,7 +32,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Annotation used to enable coordinate centering for {@link Vec3Argument} and {@link Vec2Argument}. * Annotation used to enable coordinate centering for {@link Vec3dArgument} and {@link Vec2dArgument}.
* *
* @since 1.5.0 * @since 1.5.0
*/ */

View file

@ -61,19 +61,19 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> AngleArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new AngleArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link AngleArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +81,11 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link AngleArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,11 +93,11 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link AngleArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultAngle Default angle, in degrees * @param defaultAngle Default angle, in degrees
@ -109,7 +109,7 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
final @NonNull String name, final @NonNull String name,
final float defaultAngle final float defaultAngle
) { ) {
return AngleArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultAngle)).build(); return AngleArgument.<C>builder(name).asOptionalWithDefault(defaultAngle).build();
} }
@ -126,7 +126,7 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
} }
/** /**
* Build a new angle argument. * Build a new {@link AngleArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -142,6 +142,18 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final float defaultValue) {
return this.asOptionalWithDefault(Float.toString(defaultValue));
}
} }
} }

View file

@ -39,7 +39,7 @@ import java.util.Set;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for a set of axes, described in Vanilla as a "swizzle". * An argument for a set of {@link net.minecraft.util.math.Direction.Axis axes}, described in Vanilla as a "swizzle".
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -68,19 +68,19 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> AxisArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new AxisArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link AxisArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -88,11 +88,11 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link AxisArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -100,27 +100,23 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link AxisArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValues Default axes to include * @param defaultValue Default axes to include
* @param <C> Command sender type * @param <C> Command sender type
* @return Created argument * @return Created argument
* @since 1.5.0 * @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,
final @NonNull Set<Direction.@NonNull Axis> defaultValues final @NonNull Set<Direction.@NonNull Axis> defaultValue
) { ) {
final StringBuilder builder = new StringBuilder(); return AxisArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
for (final Direction.Axis axis : defaultValues) {
builder.append(axis.getName());
}
return AxisArgument.<C>newBuilder(name).asOptionalWithDefault(builder.toString()).build();
} }
@ -137,7 +133,7 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
} }
/** /**
* Build a new axis argument. * Build a new {@link AxisArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -153,6 +149,25 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Set<Direction.@NonNull Axis> defaultValue) {
if (defaultValue.isEmpty()) {
throw new IllegalArgumentException("Default value must include at least one Axis!");
}
final StringBuilder builder = new StringBuilder();
for (final Direction.Axis axis : defaultValue) {
builder.append(axis.getName());
}
return this.asOptionalWithDefault(builder.toString());
}
} }
} }

View file

@ -62,19 +62,19 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
} }
/** /**
* Create a new builder. * Create a new {@link 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 * @since 1.5.0
*/ */
public static <C> ColorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new ColorArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link ColorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link ColorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link ColorArgument} with the specified 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}
@ -110,10 +110,7 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
final @NonNull String name, final @NonNull String name,
final @NonNull Formatting defaultColor final @NonNull Formatting defaultColor
) { ) {
if (!defaultColor.isColor()) { return ColorArgument.<C>builder(name).asOptionalWithDefault(defaultColor).build();
throw new IllegalArgumentException("Only color types are allowed but " + defaultColor + " was provided");
}
return ColorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultColor.toString()).build();
} }
@ -130,7 +127,7 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
} }
/** /**
* Build a new color argument. * Build a new {@link ColorArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -146,6 +143,21 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultColor default value, must be {@link Formatting#isColor() a color}
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Formatting defaultColor) {
if (!defaultColor.isColor()) {
throw new IllegalArgumentException("Only color types are allowed but " + defaultColor + " was provided");
}
return this.asOptionalWithDefault(defaultColor.toString());
}
} }
} }

View file

@ -62,19 +62,19 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
} }
/** /**
* Create a new builder. * Create a new {@link 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 * @since 1.5.0
*/ */
public static <C> CompoundTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new CompoundTagArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link CompoundTagArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link CompoundTagArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link CompoundTagArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultTag Default tag value * @param defaultTag Default tag value
@ -110,7 +110,7 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
final @NonNull String name, final @NonNull String name,
final @NonNull CompoundTag defaultTag final @NonNull CompoundTag defaultTag
) { ) {
return CompoundTagArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build(); return CompoundTagArgument.<C>builder(name).asOptionalWithDefault(defaultTag).build();
} }
@ -127,7 +127,7 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
} }
/** /**
* Build a new compound tag argument. * Build a new {@link CompoundTagArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -143,6 +143,18 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull CompoundTag defaultValue) {
return this.asOptionalWithDefault(defaultValue.toString());
}
} }
} }

View file

@ -35,7 +35,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument parsing an entity anchor. * An argument parsing an {@link net.minecraft.command.argument.EntityAnchorArgumentType.EntityAnchor}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -61,19 +61,19 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> EntityAnchorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new EntityAnchorArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link EntityAnchorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +81,11 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link EntityAnchorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,11 +93,11 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link EntityAnchorArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -109,7 +109,7 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
final @NonNull String name, final @NonNull String name,
final EntityAnchorArgumentType.@NonNull EntityAnchor defaultValue final EntityAnchorArgumentType.@NonNull EntityAnchor defaultValue
) { ) {
return EntityAnchorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.name()).build(); return EntityAnchorArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
} }
@ -126,7 +126,7 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
} }
/** /**
* Build a new entity anchor argument. * Build a new {@link EntityAnchorArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -142,6 +142,18 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final EntityAnchorArgumentType.@NonNull EntityAnchor defaultValue) {
return this.asOptionalWithDefault(defaultValue.name());
}
} }
} }

View file

@ -366,7 +366,7 @@ public final class FabricArgumentParsers {
} }
@Override @Override
public @NonNull PosArgument getWrappedCoordinates() { public @NonNull PosArgument wrappedCoordinates() {
return this.posArgument; return this.posArgument;
} }
@ -389,12 +389,12 @@ public final class FabricArgumentParsers {
} }
@Override @Override
public @NonNull String getInput() { public @NonNull String inputString() {
return this.inputString; return this.inputString;
} }
@Override @Override
public @NonNull EntitySelector getSelector() { public @NonNull EntitySelector selector() {
return this.entitySelector; return this.entitySelector;
} }
@ -422,12 +422,12 @@ public final class FabricArgumentParsers {
} }
@Override @Override
public @NonNull String getInput() { public @NonNull String inputString() {
return this.inputString; return this.inputString;
} }
@Override @Override
public @NonNull EntitySelector getSelector() { public @NonNull EntitySelector selector() {
return this.entitySelector; return this.entitySelector;
} }
@ -455,12 +455,12 @@ public final class FabricArgumentParsers {
} }
@Override @Override
public @NonNull String getInput() { public @NonNull String inputString() {
return this.inputString; return this.inputString;
} }
@Override @Override
public @NonNull EntitySelector getSelector() { public @NonNull EntitySelector selector() {
return this.entitySelector; return this.entitySelector;
} }
@ -488,12 +488,12 @@ public final class FabricArgumentParsers {
} }
@Override @Override
public @NonNull String getInput() { public @NonNull String inputString() {
return this.inputString; return this.inputString;
} }
@Override @Override
public @NonNull EntitySelector getSelector() { public @NonNull EntitySelector selector() {
return this.entitySelector; return this.entitySelector;
} }

View file

@ -36,8 +36,8 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument parsing an unbounded float range, in the form {@code [min]..[max] }, where both lower and upper bounds are * An argument parsing an unbounded {@link net.minecraft.predicate.NumberRange.FloatRange float range}, in the form
* optional. * {@code [min]..[max]}, where both lower and upper bounds are optional.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -63,19 +63,19 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> FloatRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new FloatRangeArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link FloatRangeArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -83,11 +83,11 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link FloatRangeArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -95,11 +95,11 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link FloatRangeArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -111,16 +111,7 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
final @NonNull String name, final @NonNull String name,
final NumberRange.@NonNull FloatRange defaultValue final NumberRange.@NonNull FloatRange defaultValue
) { ) {
final StringBuilder value = new StringBuilder(6); return FloatRangeArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
if (defaultValue.getMin() != null) {
value.append(defaultValue.getMin());
}
value.append("..");
if (defaultValue.getMax() != null) {
value.append(defaultValue.getMax());
}
return FloatRangeArgument.<C>newBuilder(name).asOptionalWithDefault(value.toString()).build();
} }
@ -137,7 +128,7 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
} }
/** /**
* Build a new float range argument. * Build a new {@link FloatRangeArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -153,6 +144,26 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final NumberRange.@NonNull FloatRange defaultValue) {
final StringBuilder value = new StringBuilder(6);
if (defaultValue.getMin() != null) {
value.append(defaultValue.getMin());
}
value.append("..");
if (defaultValue.getMax() != null) {
value.append(defaultValue.getMax());
}
return this.asOptionalWithDefault(value.toString());
}
} }
} }

View file

@ -36,7 +36,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument parsing an identifier, or "resource location". * An argument parsing an {@link Identifier}, or "resource location".
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -62,19 +62,19 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> IdentifierArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new IdentifierArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link IdentifierArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link IdentifierArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link IdentifierArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -110,7 +110,7 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
final @NonNull String name, final @NonNull String name,
final @NonNull Identifier defaultValue final @NonNull Identifier defaultValue
) { ) {
return IdentifierArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.toString()).build(); return IdentifierArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
} }
@ -127,7 +127,7 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
} }
/** /**
* Build a new identifier argument. * Build a new {@link IdentifierArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -143,6 +143,18 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Identifier defaultValue) {
return this.asOptionalWithDefault(defaultValue.toString());
}
} }
} }

View file

@ -36,8 +36,8 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument parsing an unbounded number range, in the form {@code [min]..[max] }, where both lower and upper bounds are * An argument parsing an unbounded {@link net.minecraft.predicate.NumberRange.IntRange integer range}, in the form
* optional. * {@code [min]..[max]}, where both lower and upper bounds are optional.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -63,19 +63,19 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> IntRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new IntRangeArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link IntRangeArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -83,11 +83,11 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link IntRangeArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -95,11 +95,11 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link IntRangeArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -111,16 +111,7 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
final @NonNull String name, final @NonNull String name,
final NumberRange.@NonNull IntRange defaultValue final NumberRange.@NonNull IntRange defaultValue
) { ) {
final StringBuilder value = new StringBuilder(6); return IntRangeArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
if (defaultValue.getMin() != null) {
value.append(defaultValue.getMin());
}
value.append("..");
if (defaultValue.getMax() != null) {
value.append(defaultValue.getMax());
}
return IntRangeArgument.<C>newBuilder(name).asOptionalWithDefault(value.toString()).build();
} }
@ -137,7 +128,7 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
} }
/** /**
* Build a new int range argument. * Build a new {@link IntRangeArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -153,6 +144,26 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final NumberRange.@NonNull IntRange defaultValue) {
final StringBuilder value = new StringBuilder(6);
if (defaultValue.getMin() != null) {
value.append(defaultValue.getMin());
}
value.append("..");
if (defaultValue.getMax() != null) {
value.append(defaultValue.getMax());
}
return this.asOptionalWithDefault(value.toString());
}
} }
} }

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 extra NBT data into an {@link ItemStackArgument}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -64,19 +64,19 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> ItemDataArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new ItemDataArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link ItemDataArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -84,11 +84,11 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link ItemDataArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -96,11 +96,11 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link ItemDataArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -108,17 +108,8 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull ItemDataArgument<C> optional( public static <C> @NonNull ItemDataArgument<C> optional(final @NonNull String name, final @NonNull ItemStack defaultValue) {
final @NonNull String name, return ItemDataArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
final @NonNull ItemStack defaultValue
) {
final String serializedDefault;
if (defaultValue.hasTag()) {
serializedDefault = Registry.ITEM.getId(defaultValue.getItem()).toString() + defaultValue.getTag().toString();
} else {
serializedDefault = Registry.ITEM.getId(defaultValue.getItem()).toString();
}
return ItemDataArgument.<C>newBuilder(name).asOptionalWithDefault(serializedDefault).build();
} }
@ -134,7 +125,7 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
} }
/** /**
* Build a new item data argument. * Build a new {@link ItemDataArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -150,6 +141,24 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ItemStack defaultValue) {
final String serializedDefault;
if (defaultValue.hasTag()) {
serializedDefault = Registry.ITEM.getId(defaultValue.getItem()) + defaultValue.getTag().toString();
} else {
serializedDefault = Registry.ITEM.getId(defaultValue.getItem()).toString();
}
return this.asOptionalWithDefault(serializedDefault);
}
} }
} }

View file

@ -35,7 +35,8 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for NBT paths to locations within {@link net.minecraft.nbt.Tag Tags}. * An argument for {@link net.minecraft.command.argument.NbtPathArgumentType.NbtPath NBT paths} to locations within
* {@link net.minecraft.nbt.Tag Tags}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -61,19 +62,19 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
} }
/** /**
* Create a new builder. * Create a new {@link 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 * @since 1.5.0
*/ */
public static <C> NbtPathArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new NbtPathArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link NbtPathArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +82,11 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link NbtPathArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,11 +94,11 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link NbtPathArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultTag Default tag value * @param defaultTag Default tag value
@ -109,7 +110,7 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
final @NonNull String name, final @NonNull String name,
final NbtPathArgumentType.@NonNull NbtPath defaultTag final NbtPathArgumentType.@NonNull NbtPath defaultTag
) { ) {
return NbtPathArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build(); return NbtPathArgument.<C>builder(name).asOptionalWithDefault(defaultTag).build();
} }
@ -142,6 +143,18 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final NbtPathArgumentType.@NonNull NbtPath defaultValue) {
return this.asOptionalWithDefault(defaultValue.toString());
}
} }
} }

View file

@ -62,19 +62,19 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
} }
/** /**
* Create a new builder. * Create a new {@link 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 * @since 1.5.0
*/ */
public static <C> NbtTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> NbtTagArgument.@NonNull Builder<C> builder(final @NonNull String name) {
return new NbtTagArgument.Builder<>(name); return new NbtTagArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link NbtTagArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link NbtTagArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link NbtTagArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultTag Default tag value * @param defaultTag Default tag value
@ -106,11 +106,8 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
* @return Created component * @return Created component
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull NbtTagArgument<C> optional( public static <C> @NonNull NbtTagArgument<C> optional(final @NonNull String name, final @NonNull Tag defaultTag) {
final @NonNull String name, return NbtTagArgument.<C>builder(name).asOptionalWithDefault(defaultTag).build();
final @NonNull Tag defaultTag
) {
return NbtTagArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build();
} }
@ -127,7 +124,7 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
} }
/** /**
* Build a new nbt tag argument. * Build a new {@link NbtTagArgument}.
* *
* @return Constructed component * @return Constructed component
* @since 1.5.0 * @since 1.5.0
@ -143,6 +140,18 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Tag defaultValue) {
return this.asOptionalWithDefault(defaultValue.toString());
}
} }
} }

View file

@ -62,19 +62,19 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> ParticleEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new ParticleEffectArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link ParticleEffectArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link ParticleEffectArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link ParticleEffectArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default particle effect value * @param defaultValue Default particle effect value
@ -110,7 +110,7 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
final @NonNull String name, final @NonNull String name,
final @NonNull ParticleEffect defaultValue final @NonNull ParticleEffect defaultValue
) { ) {
return ParticleEffectArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.asString()).build(); return ParticleEffectArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
} }
@ -143,6 +143,18 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ParticleEffect defaultValue) {
return this.asOptionalWithDefault(defaultValue.asString());
}
} }
} }

View file

@ -52,7 +52,7 @@ import java.util.function.BiFunction;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
/** /**
* Get a value from a registry. * Argument for getting a values from a {@link Registry}.
* *
* <p>Both static and dynamic registries are supported.</p> * <p>Both static and dynamic registries are supported.</p>
* *
@ -76,7 +76,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
super( super(
required, required,
name, name,
new RegistryEntryParser<>(registry), new Parser<>(registry),
defaultValue, defaultValue,
valueType, valueType,
suggestionsProvider, suggestionsProvider,
@ -85,7 +85,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Create a new builder. * Create a new {@link 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
@ -104,7 +104,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Create a new builder. * Create a new {@link 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
@ -123,7 +123,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Create a new required command argument. * Create a new required {@link RegistryEntryArgument}.
* *
* @param name Argument name * @param name Argument name
* @param type The type of registry entry * @param type The type of registry entry
@ -142,7 +142,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link RegistryEntryArgument}.
* *
* @param name Argument name * @param name Argument name
* @param type The type of registry entry * @param type The type of registry entry
@ -161,7 +161,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link RegistryEntryArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param type The type of registry entry * @param type The type of registry entry
@ -179,7 +179,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
final @NonNull RegistryKey<V> defaultValue final @NonNull RegistryKey<V> defaultValue
) { ) {
return RegistryEntryArgument.<C, V>newBuilder(name, type, registry) return RegistryEntryArgument.<C, V>newBuilder(name, type, registry)
.asOptionalWithDefault(defaultValue.getValue().toString()) .asOptionalWithDefault(defaultValue)
.build(); .build();
} }
@ -190,17 +190,17 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
* @param <V> Registry entry type * @param <V> Registry entry type
* @since 1.5.0 * @since 1.5.0
*/ */
public static final class RegistryEntryParser<C, V> implements ArgumentParser<C, V> { public static final class Parser<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 {@link Parser}.
* *
* @param registryIdent the registry identifier * @param registryIdent the registry identifier
* @since 1.5.0 * @since 1.5.0
*/ */
public RegistryEntryParser(final RegistryKey<? extends Registry<V>> registryIdent) { public Parser(final RegistryKey<? extends Registry<V>> registryIdent) {
this.registryIdent = requireNonNull(registryIdent, "registryIdent"); this.registryIdent = requireNonNull(registryIdent, "registryIdent");
} }
@ -211,10 +211,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
) { ) {
final String possibleIdentifier = inputQueue.peek(); final String possibleIdentifier = inputQueue.peek();
if (possibleIdentifier == null) { if (possibleIdentifier == null) {
return ArgumentParseResult.failure(new NoInputProvidedException( return ArgumentParseResult.failure(new NoInputProvidedException(RegistryEntryArgument.class, commandContext));
RegistryEntryArgument.class,
commandContext
));
} }
final Identifier key; final Identifier key;
@ -285,7 +282,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
/** /**
* A builder for registry entry arguments. * A builder for {@link RegistryEntryArgument}.
* *
* @param <C> The sender type * @param <C> The sender type
* @param <V> The registry value type * @param <V> The registry value type
@ -326,6 +323,18 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C, V> asOptionalWithDefault(final @NonNull RegistryKey<V> defaultValue) {
return this.asOptionalWithDefault(defaultValue.getValue().toString());
}
} }
/** /**

View file

@ -62,19 +62,19 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> ScoreboardCriterionArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new ScoreboardCriterionArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link ScoreboardCriterionArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link ScoreboardCriterionArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link ScoreboardCriterionArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultCriterion Default criterion * @param defaultCriterion Default criterion
@ -110,7 +110,7 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
final @NonNull String name, final @NonNull String name,
final @NonNull ScoreboardCriterion defaultCriterion final @NonNull ScoreboardCriterion defaultCriterion
) { ) {
return ScoreboardCriterionArgument.<C>newBuilder(name).asOptionalWithDefault(defaultCriterion.getName()).build(); return ScoreboardCriterionArgument.<C>builder(name).asOptionalWithDefault(defaultCriterion).build();
} }
@ -127,7 +127,7 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
} }
/** /**
* Build a new criterion argument. * Build a new {@link ScoreboardCriterionArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -143,6 +143,18 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ScoreboardCriterion defaultValue) {
return this.asOptionalWithDefault(defaultValue.getName());
}
} }
} }

View file

@ -64,19 +64,19 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> ScoreboardOperationArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new ScoreboardOperationArgument.Builder<>(name); return new ScoreboardOperationArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link ScoreboardOperationArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -84,11 +84,11 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link ScoreboardOperationArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -96,7 +96,7 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
@ -112,7 +112,7 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
} }
/** /**
* Build a new operation argument. * Build a new {@link ScoreboardOperationArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0

View file

@ -27,8 +27,7 @@ import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser; import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.context.CommandContext; import cloud.commandframework.context.CommandContext;
import cloud.commandframework.fabric.FabricCommandContextKeys; import cloud.commandframework.fabric.FabricCommandContextKeys;
import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@ -55,9 +54,9 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
return intermediate.flatMapParsedValue(value -> { return intermediate.flatMapParsedValue(value -> {
if (source instanceof ServerCommandSource) { if (source instanceof ServerCommandSource) {
return this.resolveServer(commandContext, source, value); return this.resolveServer(commandContext, (ServerCommandSource) source, value);
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { } else if (source instanceof FabricClientCommandSource) {
return this.resolveClient(commandContext, source, value); return this.resolveClient(commandContext, (FabricClientCommandSource) source, value);
} else { } else {
throw new IllegalStateException("Cannot have non-server command source when not on client"); throw new IllegalStateException("Cannot have non-server command source when not on client");
} }
@ -80,7 +79,7 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
*/ */
protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveClient( protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveClient(
@NonNull CommandContext<@NonNull C> context, @NonNull CommandContext<@NonNull C> context,
@NonNull CommandSource source, @NonNull FabricClientCommandSource source,
@NonNull I value @NonNull I value
); );
@ -95,7 +94,7 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
*/ */
protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveServer( protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveServer(
@NonNull CommandContext<@NonNull C> context, @NonNull CommandContext<@NonNull C> context,
@NonNull CommandSource source, @NonNull ServerCommandSource source,
@NonNull I value @NonNull I value
); );

View file

@ -63,19 +63,19 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> StatusEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new StatusEffectArgument.Builder<>(name); return new StatusEffectArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link StatusEffectArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -83,11 +83,11 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link StatusEffectArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -95,11 +95,11 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link StatusEffectArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -111,9 +111,7 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
final @NonNull String name, final @NonNull String name,
final @NonNull StatusEffect defaultValue final @NonNull StatusEffect defaultValue
) { ) {
return StatusEffectArgument.<C>newBuilder(name) return StatusEffectArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
.asOptionalWithDefault(Registry.STATUS_EFFECT.getId(defaultValue).toString())
.build();
} }
@ -130,7 +128,7 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
} }
/** /**
* Build a new status effect argument. * Build a new {@link StatusEffectArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -146,6 +144,18 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull StatusEffect defaultValue) {
return this.asOptionalWithDefault(Registry.STATUS_EFFECT.getId(defaultValue).toString());
}
} }
} }

View file

@ -32,9 +32,7 @@ import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import cloud.commandframework.exceptions.parsing.ParserException; import cloud.commandframework.exceptions.parsing.ParserException;
import cloud.commandframework.fabric.FabricCaptionKeys; import cloud.commandframework.fabric.FabricCaptionKeys;
import cloud.commandframework.fabric.FabricCommandContextKeys; import cloud.commandframework.fabric.FabricCommandContextKeys;
import net.minecraft.client.MinecraftClient; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.EntityAnchorArgumentType;
import net.minecraft.scoreboard.Team; import net.minecraft.scoreboard.Team;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@ -46,7 +44,7 @@ import java.util.Queue;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument parsing an entity anchor. * An argument for parsing {@link Team Teams}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -72,19 +70,19 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> TeamArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new TeamArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link TeamArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -92,11 +90,11 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link TeamArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -104,11 +102,11 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link TeamArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -118,13 +116,13 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
*/ */
public static <C> @NonNull TeamArgument<C> optional( public static <C> @NonNull TeamArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final EntityAnchorArgumentType.@NonNull EntityAnchor defaultValue final @NonNull Team defaultValue
) { ) {
return TeamArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.name()).build(); return TeamArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
} }
/** /**
* Argument parser for {@link Team}. * Argument parser for {@link Team Teams}.
* *
* @param <C> sender type * @param <C> sender type
* @since 1.5.0 * @since 1.5.0
@ -154,10 +152,10 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
@Override @Override
protected @NonNull ArgumentParseResult<Team> resolveClient( protected @NonNull ArgumentParseResult<Team> resolveClient(
final @NonNull CommandContext<C> context, final @NonNull CommandContext<C> context,
final @NonNull CommandSource source, final @NonNull FabricClientCommandSource source,
final @NonNull String value final @NonNull String value
) { ) {
final Team result = MinecraftClient.getInstance().getNetworkHandler().getWorld().getScoreboard().getTeam(value); final Team result = source.getClient().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));
} }
@ -167,10 +165,10 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
@Override @Override
protected @NonNull ArgumentParseResult<Team> resolveServer( protected @NonNull ArgumentParseResult<Team> resolveServer(
final @NonNull CommandContext<C> context, final @NonNull CommandContext<C> context,
final @NonNull CommandSource source, final @NonNull ServerCommandSource source,
final @NonNull String value final @NonNull String value
) { ) {
final Team result = ((ServerCommandSource) source).getWorld().getScoreboard().getTeam(value); final Team result = 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));
} }
@ -192,7 +190,7 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
/** /**
* Build a new team argument. * Build a new {@link TeamArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -208,6 +206,18 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Team defaultValue) {
return this.asOptionalWithDefault(defaultValue.getName());
}
} }
/** /**

View file

@ -60,19 +60,19 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> TimeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new TimeArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link TimeArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -80,11 +80,11 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link TimeArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -92,11 +92,11 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value. * Create a new optional {@link TimeArgument} with the specified default value.
* *
* @param name Argument name * @param name Argument name
* @param defaultTime Default time, in ticks * @param defaultTime Default time, in ticks
@ -108,7 +108,7 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
final @NonNull String name, final @NonNull String name,
final @NonNull MinecraftTime defaultTime final @NonNull MinecraftTime defaultTime
) { ) {
return TimeArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTime.toString()).build(); return TimeArgument.<C>builder(name).asOptionalWithDefault(defaultTime).build();
} }
@ -125,7 +125,7 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
} }
/** /**
* Build a new time argument. * Build a new {@link TimeArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -141,6 +141,18 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull MinecraftTime defaultValue) {
return this.asOptionalWithDefault(defaultValue.toString());
}
} }
} }

View file

@ -36,7 +36,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for resolving block coordinates. * An argument for resolving {@link BlockCoordinates}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -62,19 +62,19 @@ public final class BlockPosArgument<C> extends CommandArgument<C, BlockCoordinat
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> BlockPosArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> BlockPosArgument.@NonNull Builder<C> builder(final @NonNull String name) {
return new BlockPosArgument.Builder<>(name); return new BlockPosArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link BlockPosArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class BlockPosArgument<C> extends CommandArgument<C, BlockCoordinat
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull BlockPosArgument<C> of(final @NonNull String name) { public static <C> @NonNull BlockPosArgument<C> of(final @NonNull String name) {
return BlockPosArgument.<C>newBuilder(name).asRequired().build(); return BlockPosArgument.<C>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link BlockPosArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class BlockPosArgument<C> extends CommandArgument<C, BlockCoordinat
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull BlockPosArgument<C> optional(final @NonNull String name) { public static <C> @NonNull BlockPosArgument<C> optional(final @NonNull String name) {
return BlockPosArgument.<C>newBuilder(name).asOptional().build(); return BlockPosArgument.<C>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link BlockPosArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultValue default value * @param defaultValue default value
@ -107,20 +107,11 @@ public final class BlockPosArgument<C> extends CommandArgument<C, BlockCoordinat
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull BlockPosArgument<C> optional(final @NonNull String name, final @NonNull BlockPos defaultValue) { public static <C> @NonNull BlockPosArgument<C> optional(final @NonNull String name, final @NonNull BlockPos defaultValue) {
return BlockPosArgument.<C>newBuilder(name) return BlockPosArgument.<C>builder(name)
.asOptionalWithDefault(serializeBlockPos(defaultValue)) .asOptionalWithDefault(defaultValue)
.build(); .build();
} }
private static @NonNull String serializeBlockPos(final @NonNull BlockPos pos) {
return String.format(
"%s %s %s",
pos.getX(),
pos.getY(),
pos.getZ()
);
}
/** /**
* Builder for {@link BlockPosArgument}. * Builder for {@link BlockPosArgument}.
* *
@ -134,7 +125,7 @@ public final class BlockPosArgument<C> extends CommandArgument<C, BlockCoordinat
} }
/** /**
* Build a block position argument. * Build a new {@link BlockPosArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -150,6 +141,23 @@ public final class BlockPosArgument<C> extends CommandArgument<C, BlockCoordinat
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull BlockPos defaultValue) {
return this.asOptionalWithDefault(String.format(
"%s %s %s",
defaultValue.getX(),
defaultValue.getY(),
defaultValue.getZ()
));
}
} }
} }

View file

@ -36,7 +36,7 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for resolving column (xz) coordinates. * An argument for resolving {@link ColumnCoordinates column (xz) coordinates}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -62,19 +62,19 @@ public final class ColumnPosArgument<C> extends CommandArgument<C, ColumnCoordin
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> ColumnPosArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> ColumnPosArgument.@NonNull Builder<C> builder(final @NonNull String name) {
return new ColumnPosArgument.Builder<>(name); return new ColumnPosArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link ColumnPosArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -82,11 +82,11 @@ public final class ColumnPosArgument<C> extends CommandArgument<C, ColumnCoordin
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull ColumnPosArgument<C> of(final @NonNull String name) { public static <C> @NonNull ColumnPosArgument<C> of(final @NonNull String name) {
return ColumnPosArgument.<C>newBuilder(name).asRequired().build(); return ColumnPosArgument.<C>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link ColumnPosArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -94,11 +94,11 @@ public final class ColumnPosArgument<C> extends CommandArgument<C, ColumnCoordin
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull ColumnPosArgument<C> optional(final @NonNull String name) { public static <C> @NonNull ColumnPosArgument<C> optional(final @NonNull String name) {
return ColumnPosArgument.<C>newBuilder(name).asOptional().build(); return ColumnPosArgument.<C>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link ColumnPosArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultValue default value, y coordinate will be ignored as it is always 0 * @param defaultValue default value, y coordinate will be ignored as it is always 0
@ -107,19 +107,11 @@ public final class ColumnPosArgument<C> extends CommandArgument<C, ColumnCoordin
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull ColumnPosArgument<C> optional(final @NonNull String name, final @NonNull BlockPos defaultValue) { public static <C> @NonNull ColumnPosArgument<C> optional(final @NonNull String name, final @NonNull BlockPos defaultValue) {
return ColumnPosArgument.<C>newBuilder(name) return ColumnPosArgument.<C>builder(name)
.asOptionalWithDefault(serializeColumnPos(defaultValue)) .asOptionalWithDefault(defaultValue)
.build(); .build();
} }
private static @NonNull String serializeColumnPos(final @NonNull BlockPos pos) {
return String.format(
"%s %s",
pos.getX(),
pos.getZ()
);
}
/** /**
* Builder for {@link ColumnPosArgument}. * Builder for {@link ColumnPosArgument}.
* *
@ -133,7 +125,7 @@ public final class ColumnPosArgument<C> extends CommandArgument<C, ColumnCoordin
} }
/** /**
* Build a column position argument. * Build a new {@link ColumnPosArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
@ -149,6 +141,22 @@ public final class ColumnPosArgument<C> extends CommandArgument<C, ColumnCoordin
); );
} }
/**
* Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull BlockPos defaultValue) {
return this.asOptionalWithDefault(String.format(
"%s %s",
defaultValue.getX(),
defaultValue.getZ()
));
}
} }
} }

View file

@ -61,19 +61,19 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> MessageArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> MessageArgument.@NonNull Builder<C> builder(final @NonNull String name) {
return new MessageArgument.Builder<>(name); return new MessageArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link MessageArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +81,11 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link MessageArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,11 +93,11 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument with a default value * Create a new optional {@link MessageArgument} with the specified value.
* *
* @param name Argument name * @param name Argument name
* @param defaultValue Default value * @param defaultValue Default value
@ -109,7 +109,7 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
final @NonNull String name, final @NonNull String name,
final @NonNull String defaultValue final @NonNull String defaultValue
) { ) {
return MessageArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build(); return MessageArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
} }
@ -126,7 +126,7 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
} }
/** /**
* Build a new message argument. * Build a new {@link MessageArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0

View file

@ -35,7 +35,8 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for selecting multiple entities * An argument for selecting multiple {@link net.minecraft.entity.Entity entities} using an
* {@link net.minecraft.command.EntitySelector}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -61,19 +62,19 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> MultipleEntitySelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new MultipleEntitySelectorArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link MultipleEntitySelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +82,11 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link MultipleEntitySelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,7 +94,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
@ -109,7 +110,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
} }
/** /**
* Build a multiple entity selector argument. * Build a new {@link MultipleEntitySelectorArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0

View file

@ -35,7 +35,8 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for selecting multiple players * An argument for selecting multiple {@link net.minecraft.server.network.ServerPlayerEntity players} using an
* {@link net.minecraft.command.EntitySelector}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -61,19 +62,19 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> MultiplePlayerSelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new MultiplePlayerSelectorArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link MultiplePlayerSelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +82,11 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link MultiplePlayerSelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,7 +94,7 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
@ -109,7 +110,7 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
} }
/** /**
* Build a multiple player selector argument. * Build a new {@link MultiplePlayerSelectorArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0

View file

@ -35,7 +35,8 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for selecting a single entity * An argument for selecting a single {@link net.minecraft.entity.Entity entity} using an
* {@link net.minecraft.command.EntitySelector}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -61,19 +62,19 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> SingleEntitySelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> SingleEntitySelectorArgument.@NonNull Builder<C> builder(final @NonNull String name) {
return new SingleEntitySelectorArgument.Builder<>(name); return new SingleEntitySelectorArgument.Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link SingleEntitySelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +82,11 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link SingleEntitySelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,7 +94,7 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
@ -109,7 +110,7 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
} }
/** /**
* Build a single entity selector argument. * Build a new {@link SingleEntitySelectorArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0

View file

@ -35,7 +35,8 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for selecting a single player * An argument for selecting a single {@link net.minecraft.server.network.ServerPlayerEntity player} using an
* {@link net.minecraft.command.EntitySelector}.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
@ -61,19 +62,19 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> SinglePlayerSelectorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new SinglePlayerSelectorArgument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link SinglePlayerSelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -81,11 +82,11 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
* @since 1.5.0 * @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>builder(name).asRequired().build();
} }
/** /**
* Create a new optional command argument. * Create a new optional {@link SinglePlayerSelectorArgument}.
* *
* @param name Component name * @param name Component name
* @param <C> Command sender type * @param <C> Command sender type
@ -93,7 +94,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
* @since 1.5.0 * @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>builder(name).asOptional().build();
} }
/** /**
@ -109,7 +110,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
} }
/** /**
* Build a single player selector argument. * Build a new {@link SinglePlayerSelectorArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0

View file

@ -36,16 +36,16 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for resolving x and z coordinates from 2 doubles. * An argument for resolving {@link cloud.commandframework.fabric.data.Coordinates.CoordinatesXZ} from 2 doubles.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
*/ */
public final class Vec2Argument<C> extends CommandArgument<C, Coordinates.CoordinatesXZ> { public final class Vec2dArgument<C> extends CommandArgument<C, Coordinates.CoordinatesXZ> {
private final boolean centerIntegers; private final boolean centerIntegers;
Vec2Argument( Vec2dArgument(
final boolean required, final boolean required,
final @NonNull String name, final @NonNull String name,
final @NonNull String defaultValue, final @NonNull String defaultValue,
@ -76,31 +76,31 @@ public final class Vec2Argument<C> extends CommandArgument<C, Coordinates.Coordi
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> Vec2Argument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new Vec2Argument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link Vec2dArgument}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> @NonNull Vec2Argument<C> of(final @NonNull String name) { public static <C> @NonNull Vec2dArgument<C> of(final @NonNull String name) {
return Vec2Argument.<C>newBuilder(name).asRequired().build(); return Vec2dArgument.<C>builder(name).asRequired().build();
} }
/** /**
* Create a new required command argument. * Create a new required {@link Vec2dArgument}.
* *
* @param name Component name * @param name Component name
* @param centerIntegers whether to center integers to x.5. * @param centerIntegers whether to center integers to x.5.
@ -108,24 +108,24 @@ public final class Vec2Argument<C> extends CommandArgument<C, Coordinates.Coordi
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec2Argument<C> of(final @NonNull String name, final boolean centerIntegers) { public static <C> @NonNull Vec2dArgument<C> of(final @NonNull String name, final boolean centerIntegers) {
return Vec2Argument.<C>newBuilder(name).centerIntegers(centerIntegers).asRequired().build(); return Vec2dArgument.<C>builder(name).centerIntegers(centerIntegers).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec2dArgument}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> @NonNull Vec2Argument<C> optional(final @NonNull String name) { public static <C> @NonNull Vec2dArgument<C> optional(final @NonNull String name) {
return Vec2Argument.<C>newBuilder(name).asOptional().build(); return Vec2dArgument.<C>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec2dArgument}.
* *
* @param name Component name * @param name Component name
* @param centerIntegers whether to center integers to x.5. * @param centerIntegers whether to center integers to x.5.
@ -133,12 +133,12 @@ public final class Vec2Argument<C> extends CommandArgument<C, Coordinates.Coordi
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec2Argument<C> optional(final @NonNull String name, final boolean centerIntegers) { public static <C> @NonNull Vec2dArgument<C> optional(final @NonNull String name, final boolean centerIntegers) {
return Vec2Argument.<C>newBuilder(name).centerIntegers(centerIntegers).asOptional().build(); return Vec2dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptional().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec2dArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultValue default value, y will be ignored as it is always 0 * @param defaultValue default value, y will be ignored as it is always 0
@ -146,14 +146,12 @@ public final class Vec2Argument<C> extends CommandArgument<C, Coordinates.Coordi
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec2Argument<C> optional(final @NonNull String name, final @NonNull Vec3d defaultValue) { public static <C> @NonNull Vec2dArgument<C> optional(final @NonNull String name, final @NonNull Vec3d defaultValue) {
return Vec2Argument.<C>newBuilder(name) return Vec2dArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
.asOptionalWithDefault(serializeXandZ(defaultValue))
.build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec2dArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultValue default value, y will be ignored as it is always 0 * @param defaultValue default value, y will be ignored as it is always 0
@ -162,27 +160,16 @@ public final class Vec2Argument<C> extends CommandArgument<C, Coordinates.Coordi
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec2Argument<C> optional( public static <C> @NonNull Vec2dArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final boolean centerIntegers, final boolean centerIntegers,
final @NonNull Vec3d defaultValue final @NonNull Vec3d defaultValue
) { ) {
return Vec2Argument.<C>newBuilder(name) return Vec2dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptionalWithDefault(defaultValue).build();
.centerIntegers(centerIntegers)
.asOptionalWithDefault(serializeXandZ(defaultValue))
.build();
}
private static @NonNull String serializeXandZ(final @NonNull Vec3d vec3d) {
return String.format(
"%.10f %.10f",
vec3d.x,
vec3d.z
);
} }
/** /**
* Builder for {@link Vec2Argument}. * Builder for {@link Vec2dArgument}.
* *
* @param <C> sender type * @param <C> sender type
* @since 1.5.0 * @since 1.5.0
@ -218,14 +205,30 @@ public final class Vec2Argument<C> extends CommandArgument<C, Coordinates.Coordi
} }
/** /**
* Build a vec2 argument. * Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value, y will be ignored as it is always 0
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Vec3d defaultValue) {
return this.asOptionalWithDefault(String.format(
"%.10f %.10f",
defaultValue.x,
defaultValue.z
));
}
/**
* Build a new {@link Vec2dArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
*/ */
@Override @Override
public @NonNull Vec2Argument<C> build() { public @NonNull Vec2dArgument<C> build() {
return new Vec2Argument<>( return new Vec2dArgument<>(
this.isRequired(), this.isRequired(),
this.getName(), this.getName(),
this.getDefaultValue(), this.getDefaultValue(),

View file

@ -36,16 +36,16 @@ import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
* An argument for resolving coordinates from 3 doubles. * An argument for resolving {@link Coordinates} from 3 doubles.
* *
* @param <C> the sender type * @param <C> the sender type
* @since 1.5.0 * @since 1.5.0
*/ */
public final class Vec3Argument<C> extends CommandArgument<C, Coordinates> { public final class Vec3dArgument<C> extends CommandArgument<C, Coordinates> {
private final boolean centerIntegers; private final boolean centerIntegers;
Vec3Argument( Vec3dArgument(
final boolean required, final boolean required,
final @NonNull String name, final @NonNull String name,
final @NonNull String defaultValue, final @NonNull String defaultValue,
@ -76,31 +76,31 @@ public final class Vec3Argument<C> extends CommandArgument<C, Coordinates> {
} }
/** /**
* Create a new builder. * Create a new {@link Builder}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> Vec3Argument.@NonNull Builder<C> newBuilder(final @NonNull String name) { public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new Vec3Argument.Builder<>(name); return new Builder<>(name);
} }
/** /**
* Create a new required command argument. * Create a new required {@link Vec3dArgument}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> @NonNull Vec3Argument<C> of(final @NonNull String name) { public static <C> @NonNull Vec3dArgument<C> of(final @NonNull String name) {
return Vec3Argument.<C>newBuilder(name).asRequired().build(); return Vec3dArgument.<C>builder(name).asRequired().build();
} }
/** /**
* Create a new required command argument. * Create a new required {@link Vec3dArgument}.
* *
* @param name Component name * @param name Component name
* @param centerIntegers whether to center integers to x.5. * @param centerIntegers whether to center integers to x.5.
@ -108,24 +108,24 @@ public final class Vec3Argument<C> extends CommandArgument<C, Coordinates> {
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec3Argument<C> of(final @NonNull String name, final boolean centerIntegers) { public static <C> @NonNull Vec3dArgument<C> of(final @NonNull String name, final boolean centerIntegers) {
return Vec3Argument.<C>newBuilder(name).centerIntegers(centerIntegers).asRequired().build(); return Vec3dArgument.<C>builder(name).centerIntegers(centerIntegers).asRequired().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec3dArgument}.
* *
* @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 * @since 1.5.0
*/ */
public static <C> @NonNull Vec3Argument<C> optional(final @NonNull String name) { public static <C> @NonNull Vec3dArgument<C> optional(final @NonNull String name) {
return Vec3Argument.<C>newBuilder(name).asOptional().build(); return Vec3dArgument.<C>builder(name).asOptional().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec3dArgument}.
* *
* @param name Component name * @param name Component name
* @param centerIntegers whether to center integers to x.5. * @param centerIntegers whether to center integers to x.5.
@ -133,12 +133,12 @@ public final class Vec3Argument<C> extends CommandArgument<C, Coordinates> {
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec3Argument<C> optional(final @NonNull String name, final boolean centerIntegers) { public static <C> @NonNull Vec3dArgument<C> optional(final @NonNull String name, final boolean centerIntegers) {
return Vec3Argument.<C>newBuilder(name).centerIntegers(centerIntegers).asOptional().build(); return Vec3dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptional().build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec3dArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultValue default value * @param defaultValue default value
@ -146,14 +146,12 @@ public final class Vec3Argument<C> extends CommandArgument<C, Coordinates> {
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec3Argument<C> optional(final @NonNull String name, final @NonNull Vec3d defaultValue) { public static <C> @NonNull Vec3dArgument<C> optional(final @NonNull String name, final @NonNull Vec3d defaultValue) {
return Vec3Argument.<C>newBuilder(name) return Vec3dArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
.asOptionalWithDefault(serializeVec3(defaultValue))
.build();
} }
/** /**
* Create a new optional command argument * Create a new optional {@link Vec3dArgument} with the specified default value.
* *
* @param name Component name * @param name Component name
* @param defaultValue default value * @param defaultValue default value
@ -162,28 +160,16 @@ public final class Vec3Argument<C> extends CommandArgument<C, Coordinates> {
* @return Created argument * @return Created argument
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> @NonNull Vec3Argument<C> optional( public static <C> @NonNull Vec3dArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final boolean centerIntegers, final boolean centerIntegers,
final @NonNull Vec3d defaultValue final @NonNull Vec3d defaultValue
) { ) {
return Vec3Argument.<C>newBuilder(name) return Vec3dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptionalWithDefault(defaultValue).build();
.centerIntegers(centerIntegers)
.asOptionalWithDefault(serializeVec3(defaultValue))
.build();
}
private static @NonNull String serializeVec3(final @NonNull Vec3d vec3d) {
return String.format(
"%.10f %.10f %.10f",
vec3d.x,
vec3d.y,
vec3d.z
);
} }
/** /**
* Builder for {@link Vec3Argument}. * Builder for {@link Vec3dArgument}.
* *
* @param <C> sender type * @param <C> sender type
* @since 1.5.0 * @since 1.5.0
@ -219,14 +205,31 @@ public final class Vec3Argument<C> extends CommandArgument<C, Coordinates> {
} }
/** /**
* Build a vec3 argument. * Sets the command argument to be optional, with the specified default value.
*
* @param defaultValue default value
* @return this builder
* @see CommandArgument.Builder#asOptionalWithDefault(String)
* @since 1.5.0
*/
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Vec3d defaultValue) {
return this.asOptionalWithDefault(String.format(
"%.10f %.10f %.10f",
defaultValue.x,
defaultValue.y,
defaultValue.z
));
}
/**
* Build a new {@link Vec3dArgument}.
* *
* @return Constructed argument * @return Constructed argument
* @since 1.5.0 * @since 1.5.0
*/ */
@Override @Override
public @NonNull Vec3Argument<C> build() { public @NonNull Vec3dArgument<C> build() {
return new Vec3Argument<>( return new Vec3dArgument<>(
this.isRequired(), this.isRequired(),
this.getName(), this.getName(),
this.getDefaultValue(), this.getDefaultValue(),

View file

@ -84,7 +84,7 @@ public interface Coordinates {
* @return the base coordinates * @return the base coordinates
* @since 1.5.0 * @since 1.5.0
*/ */
@NonNull PosArgument getWrappedCoordinates(); @NonNull PosArgument wrappedCoordinates();
/** /**
* A specialized version of {@link Coordinates} for representing the result of the vanilla {@link Vec2ArgumentType}, * A specialized version of {@link Coordinates} for representing the result of the vanilla {@link Vec2ArgumentType},

View file

@ -44,15 +44,15 @@ public interface Selector<V> {
* @return the input * @return the input
* @since 1.5.0 * @since 1.5.0
*/ */
@NonNull String getInput(); @NonNull String inputString();
/** /**
* If this value came from a parsed selector, this will provide the details of that selector. * If this value came from a parsed {@link EntitySelector}, this will provide the details of that selector.
* *
* @return the selector * @return the selector
* @since 1.5.0 * @since 1.5.0
*/ */
@Nullable EntitySelector getSelector(); @Nullable EntitySelector selector();
/** /**
* Resolve the value of this selector. * Resolve the value of this selector.

View file

@ -35,7 +35,7 @@ import cloud.commandframework.fabric.argument.ItemDataArgument;
import cloud.commandframework.fabric.argument.server.ColumnPosArgument; import cloud.commandframework.fabric.argument.server.ColumnPosArgument;
import cloud.commandframework.fabric.argument.server.MultipleEntitySelectorArgument; import cloud.commandframework.fabric.argument.server.MultipleEntitySelectorArgument;
import cloud.commandframework.fabric.argument.server.MultiplePlayerSelectorArgument; import cloud.commandframework.fabric.argument.server.MultiplePlayerSelectorArgument;
import cloud.commandframework.fabric.argument.server.Vec3Argument; import cloud.commandframework.fabric.argument.server.Vec3dArgument;
import cloud.commandframework.fabric.data.Coordinates; import cloud.commandframework.fabric.data.Coordinates;
import cloud.commandframework.fabric.data.Coordinates.ColumnCoordinates; import cloud.commandframework.fabric.data.Coordinates.ColumnCoordinates;
import cloud.commandframework.fabric.data.MultipleEntitySelector; import cloud.commandframework.fabric.data.MultipleEntitySelector;
@ -56,6 +56,7 @@ import net.minecraft.text.HoverEvent;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.TextColor; import net.minecraft.text.TextColor;
import net.minecraft.text.Texts;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
@ -118,7 +119,7 @@ public final class FabricExample implements ModInitializer {
)); ));
ctx.getSender().sendFeedback( ctx.getSender().sendFeedback(
new LiteralText(String.format("Waved at %d players (%s)", selected.size(), new LiteralText(String.format("Waved at %d players (%s)", selected.size(),
selector.getInput() selector.inputString()
)), )),
false false
); );
@ -229,7 +230,7 @@ public final class FabricExample implements ModInitializer {
manager.command(base.literal("teleport") manager.command(base.literal("teleport")
.permission("cloud.teleport") .permission("cloud.teleport")
.argument(MultipleEntitySelectorArgument.of("targets")) .argument(MultipleEntitySelectorArgument.of("targets"))
.argument(Vec3Argument.of("location")) .argument(Vec3dArgument.of("location"))
.handler(ctx -> { .handler(ctx -> {
final MultipleEntitySelector selector = ctx.get("targets"); final MultipleEntitySelector selector = ctx.get("targets");
final Vec3d location = ctx.<Coordinates>get("location").position(); final Vec3d location = ctx.<Coordinates>get("location").position();
@ -245,7 +246,7 @@ public final class FabricExample implements ModInitializer {
try { try {
player = ctx.getSender().getPlayer(); player = ctx.getSender().getPlayer();
} catch (final CommandSyntaxException e) { } catch (final CommandSyntaxException e) {
ctx.getSender().sendFeedback(new LiteralText("Must be a player to use this command"), false); ctx.getSender().sendFeedback(Texts.toText(e.getRawMessage()), false);
return; return;
} }
final Vec3d vec = ctx.<ColumnCoordinates>get("chunk_position").position(); final Vec3d vec = ctx.<ColumnCoordinates>get("chunk_position").position();