fabric: add more nullability annotations

This commit is contained in:
jmp 2021-03-12 14:47:18 -08:00 committed by Jason
parent ddf16373fb
commit c95d0c70cd
11 changed files with 77 additions and 51 deletions

View file

@ -55,8 +55,9 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
* @see #FabricClientCommandManager(Function, Function, Function) for a more thorough explanation * @see #FabricClientCommandManager(Function, Function, Function) for a more thorough explanation
* @since 1.5.0 * @since 1.5.0
*/ */
public static FabricClientCommandManager<FabricClientCommandSource> createNative( public static @NonNull FabricClientCommandManager<@NonNull FabricClientCommandSource> createNative(
final Function<CommandTree<FabricClientCommandSource>, CommandExecutionCoordinator<FabricClientCommandSource>> execCoordinator final @NonNull Function<@NonNull CommandTree<@NonNull FabricClientCommandSource>,
@NonNull CommandExecutionCoordinator<@NonNull FabricClientCommandSource>> execCoordinator
) { ) {
return new FabricClientCommandManager<>(execCoordinator, Function.identity(), Function.identity()); return new FabricClientCommandManager<>(execCoordinator, Function.identity(), Function.identity());
} }
@ -76,11 +77,11 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link FabricClientCommandSource} * @param backwardsCommandSourceMapper Function that maps the command sender type to {@link FabricClientCommandSource}
* @since 1.5.0 * @since 1.5.0
*/ */
@SuppressWarnings("unchecked")
public FabricClientCommandManager( public FabricClientCommandManager(
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator, final @NonNull Function<@NonNull CommandTree<@NonNull C>,
final Function<FabricClientCommandSource, C> commandSourceMapper, @NonNull CommandExecutionCoordinator<@NonNull C>> commandExecutionCoordinator,
final Function<C, FabricClientCommandSource> backwardsCommandSourceMapper final @NonNull Function<@NonNull FabricClientCommandSource, @NonNull C> commandSourceMapper,
final @NonNull Function<@NonNull C, @NonNull FabricClientCommandSource> backwardsCommandSourceMapper
) { ) {
super( super(
commandExecutionCoordinator, commandExecutionCoordinator,
@ -110,7 +111,7 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
* @since 1.5.0 * @since 1.5.0
*/ */
@Override @Override
public boolean hasPermission(@NonNull final C sender, @NonNull final String permission) { public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) {
return true; return true;
} }

View file

@ -139,10 +139,10 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
FabricCommandManager( FabricCommandManager(
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator, final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final Function<S, C> commandSourceMapper, final @NonNull Function<S, C> commandSourceMapper,
final Function<C, S> backwardsCommandSourceMapper, final @NonNull Function<C, S> backwardsCommandSourceMapper,
final FabricCommandRegistrationHandler<C, S> registrationHandler, final @NonNull FabricCommandRegistrationHandler<C, S> registrationHandler,
final Supplier<S> dummyCommandSourceProvider final @NonNull Supplier<S> dummyCommandSourceProvider
) { ) {
super(commandExecutionCoordinator, registrationHandler); super(commandExecutionCoordinator, registrationHandler);
this.commandSourceMapper = commandSourceMapper; this.commandSourceMapper = commandSourceMapper;
@ -164,11 +164,13 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
((FabricCommandRegistrationHandler<C, S>) this.getCommandRegistrationHandler()).initialize(this); ((FabricCommandRegistrationHandler<C, S>) this.getCommandRegistrationHandler()).initialize(this);
} }
private void registerNativeBrigadierMappings(final CloudBrigadierManager<C, S> brigadier) { private void registerNativeBrigadierMappings(final @NonNull CloudBrigadierManager<C, S> brigadier) {
/* Cloud-native argument types */ /* Cloud-native argument types */
brigadier.registerMapping(new TypeToken<UUIDArgument.UUIDParser<C>>() {}, builder -> builder.toConstant(UuidArgumentType.uuid())); brigadier.registerMapping(new TypeToken<UUIDArgument.UUIDParser<C>>() {
}, builder -> builder.toConstant(UuidArgumentType.uuid()));
this.registerRegistryEntryMappings(); this.registerRegistryEntryMappings();
brigadier.registerMapping(new TypeToken<TeamArgument.TeamParser<C>>() {}, builder -> builder.toConstant(TeamArgumentType.team())); brigadier.registerMapping(new TypeToken<TeamArgument.TeamParser<C>>() {
}, builder -> builder.toConstant(TeamArgumentType.team()));
this.getParserRegistry().registerParserSupplier(TypeToken.get(Team.class), params -> new TeamArgument.TeamParser<>()); this.getParserRegistry().registerParserSupplier(TypeToken.get(Team.class), params -> new TeamArgument.TeamParser<>());
/* Wrapped/Constant Brigadier types, native value type */ /* Wrapped/Constant Brigadier types, native value type */
@ -180,9 +182,13 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
this.registerConstantNativeParserSupplier(OperationArgumentType.Operation.class, OperationArgumentType.operation()); this.registerConstantNativeParserSupplier(OperationArgumentType.Operation.class, OperationArgumentType.operation());
this.registerConstantNativeParserSupplier(ParticleEffect.class, ParticleArgumentType.particle()); this.registerConstantNativeParserSupplier(ParticleEffect.class, ParticleArgumentType.particle());
this.registerConstantNativeParserSupplier(AngleArgumentType.Angle.class, AngleArgumentType.angle()); this.registerConstantNativeParserSupplier(AngleArgumentType.Angle.class, AngleArgumentType.angle());
this.registerConstantNativeParserSupplier(new TypeToken<EnumSet<Direction.Axis>>() {}, SwizzleArgumentType.swizzle()); this.registerConstantNativeParserSupplier(new TypeToken<EnumSet<Direction.Axis>>() {
}, SwizzleArgumentType.swizzle());
this.registerConstantNativeParserSupplier(Identifier.class, IdentifierArgumentType.identifier()); this.registerConstantNativeParserSupplier(Identifier.class, IdentifierArgumentType.identifier());
this.registerConstantNativeParserSupplier(EntityAnchorArgumentType.EntityAnchor.class, EntityAnchorArgumentType.entityAnchor()); this.registerConstantNativeParserSupplier(
EntityAnchorArgumentType.EntityAnchor.class,
EntityAnchorArgumentType.entityAnchor()
);
this.registerConstantNativeParserSupplier(NumberRange.IntRange.class, NumberRangeArgumentType.numberRange()); this.registerConstantNativeParserSupplier(NumberRange.IntRange.class, NumberRangeArgumentType.numberRange());
this.registerConstantNativeParserSupplier(NumberRange.FloatRange.class, NumberRangeArgumentType.method_30918()); this.registerConstantNativeParserSupplier(NumberRange.FloatRange.class, NumberRangeArgumentType.method_30918());
// todo: can we add a compound argument -- MC `ItemStackArgument` is just type and tag, and count is separate // todo: can we add a compound argument -- MC `ItemStackArgument` is just type and tag, and count is separate
@ -207,7 +213,10 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
this.registerConstantNativeParserSupplier(Team.class, TeamArgumentType.team()); this.registerConstantNativeParserSupplier(Team.class, TeamArgumentType.team());
this.registerConstantNativeParserSupplier(/* slot *, ItemSlotArgumentType.itemSlot()); this.registerConstantNativeParserSupplier(/* slot *, ItemSlotArgumentType.itemSlot());
this.registerConstantNativeParserSupplier(CommandFunction.class, FunctionArgumentType.function()); */ this.registerConstantNativeParserSupplier(CommandFunction.class, FunctionArgumentType.function()); */
this.getParserRegistry().registerParserSupplier(TypeToken.get(MinecraftTime.class), params -> FabricArgumentParsers.time()); this.getParserRegistry().registerParserSupplier(
TypeToken.get(MinecraftTime.class),
params -> FabricArgumentParsers.time()
);
/* Wrapped brigadier requiring parameters */ /* Wrapped brigadier requiring parameters */
// score holder: single vs multiple // score holder: single vs multiple
@ -310,7 +319,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
* @param <T> value type * @param <T> value type
* @since 1.5.0 * @since 1.5.0
*/ */
final <T> void registerConstantNativeParserSupplier(final Class<T> type, final ArgumentType<T> argument) { final <T> void registerConstantNativeParserSupplier(final @NonNull Class<T> type, final @NonNull ArgumentType<T> argument) {
this.registerConstantNativeParserSupplier(TypeToken.get(type), argument); this.registerConstantNativeParserSupplier(TypeToken.get(type), argument);
} }
@ -322,7 +331,10 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
* @param <T> value type * @param <T> value type
* @since 1.5.0 * @since 1.5.0
*/ */
final <T> void registerConstantNativeParserSupplier(final TypeToken<T> type, final ArgumentType<T> argument) { final <T> void registerConstantNativeParserSupplier(
final @NonNull TypeToken<T> type,
final @NonNull ArgumentType<T> argument
) {
this.getParserRegistry().registerParserSupplier(type, params -> new WrappedBrigadierParser<>(argument)); this.getParserRegistry().registerParserSupplier(type, params -> new WrappedBrigadierParser<>(argument));
} }

View file

@ -79,8 +79,9 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
* @see #FabricServerCommandManager(Function, Function, Function) for a more thorough explanation * @see #FabricServerCommandManager(Function, Function, Function) for a more thorough explanation
* @since 1.5.0 * @since 1.5.0
*/ */
public static FabricServerCommandManager<ServerCommandSource> createNative( public static @NonNull FabricServerCommandManager<@NonNull ServerCommandSource> createNative(
final Function<CommandTree<ServerCommandSource>, CommandExecutionCoordinator<ServerCommandSource>> execCoordinator final @NonNull Function<@NonNull CommandTree<@NonNull ServerCommandSource>,
@NonNull CommandExecutionCoordinator<@NonNull ServerCommandSource>> execCoordinator
) { ) {
return new FabricServerCommandManager<>(execCoordinator, Function.identity(), Function.identity()); return new FabricServerCommandManager<>(execCoordinator, Function.identity(), Function.identity());
} }
@ -101,9 +102,10 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
* @since 1.5.0 * @since 1.5.0
*/ */
public FabricServerCommandManager( public FabricServerCommandManager(
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator, final @NonNull Function<@NonNull CommandTree<@NonNull C>,
final Function<ServerCommandSource, C> commandSourceMapper, @NonNull CommandExecutionCoordinator<@NonNull C>> commandExecutionCoordinator,
final Function<C, ServerCommandSource> backwardsCommandSourceMapper final @NonNull Function<@NonNull ServerCommandSource, @NonNull C> commandSourceMapper,
final @NonNull Function<@NonNull C, @NonNull ServerCommandSource> backwardsCommandSourceMapper
) { ) {
super( super(
commandExecutionCoordinator, commandExecutionCoordinator,
@ -159,7 +161,7 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
* @since 1.5.0 * @since 1.5.0
*/ */
@Override @Override
public boolean hasPermission(@NonNull final C sender, @NonNull final String permission) { public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) {
final ServerCommandSource source = this.getBackwardsCommandSourceMapper().apply(sender); final ServerCommandSource source = this.getBackwardsCommandSourceMapper().apply(sender);
return Permissions.check(source, permission, source.getMinecraftServer().getOpPermissionLevel()); return Permissions.check(source, permission, source.getMinecraftServer().getOpPermissionLevel());
} }

View file

@ -69,7 +69,7 @@ public final class FabricArgumentParsers {
* @return a parser instance * @return a parser instance
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> ArgumentParser<C, MinecraftTime> time() { public static <C> @NonNull ArgumentParser<C, MinecraftTime> time() {
return new WrappedBrigadierParser<C, Integer>(TimeArgumentType.time()) return new WrappedBrigadierParser<C, Integer>(TimeArgumentType.time())
.map((ctx, val) -> ArgumentParseResult.success(MinecraftTime.of(val))); .map((ctx, val) -> ArgumentParseResult.success(MinecraftTime.of(val)));
} }
@ -81,7 +81,7 @@ public final class FabricArgumentParsers {
* @return a parser instance * @return a parser instance
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() { public static <C> @NonNull ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.player()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.player())
.map((ctx, entitySelector) -> { .map((ctx, entitySelector) -> {
final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE); final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
@ -107,7 +107,7 @@ public final class FabricArgumentParsers {
* @return a parser instance * @return a parser instance
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() { public static <C> @NonNull ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.players()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.players())
.map((ctx, entitySelector) -> { .map((ctx, entitySelector) -> {
final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE); final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
@ -133,7 +133,7 @@ public final class FabricArgumentParsers {
* @return a parser instance * @return a parser instance
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> ArgumentParser<C, SingleEntitySelector> singleEntitySelector() { public static <C> @NonNull ArgumentParser<C, SingleEntitySelector> singleEntitySelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entity()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entity())
.map((ctx, entitySelector) -> { .map((ctx, entitySelector) -> {
final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE); final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
@ -159,7 +159,7 @@ public final class FabricArgumentParsers {
* @return a parser instance * @return a parser instance
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() { public static <C> @NonNull ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entities()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entities())
.map((ctx, entitySelector) -> { .map((ctx, entitySelector) -> {
final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE); final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
@ -185,7 +185,7 @@ public final class FabricArgumentParsers {
* @return a parser instance * @return a parser instance
* @since 1.5.0 * @since 1.5.0
*/ */
public static <C> ArgumentParser<C, Message> message() { public static <C> @NonNull ArgumentParser<C, Message> message() {
return new WrappedBrigadierParser<C, MessageArgumentType.MessageFormat>(MessageArgumentType.message()) return new WrappedBrigadierParser<C, MessageArgumentType.MessageFormat>(MessageArgumentType.message())
.map((ctx, format) -> { .map((ctx, format) -> {
final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE); final CommandSource either = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
@ -213,8 +213,8 @@ public final class FabricArgumentParsers {
private final Text contents; private final Text contents;
static MessageImpl from( static MessageImpl from(
final ServerCommandSource source, final @NonNull ServerCommandSource source,
final MessageArgumentType.MessageFormat message, final MessageArgumentType.@NonNull MessageFormat message,
final boolean useSelectors final boolean useSelectors
) throws CommandSyntaxException { ) throws CommandSyntaxException {
final Text contents = message.format(source, useSelectors); final Text contents = message.format(source, useSelectors);

View file

@ -107,7 +107,7 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
*/ */
public static <C> @NonNull IntRangeArgument<C> optional( public static <C> @NonNull IntRangeArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final NumberRange.IntRange defaultValue final NumberRange.@NonNull IntRange defaultValue
) { ) {
final StringBuilder value = new StringBuilder(6); final StringBuilder value = new StringBuilder(6);
if (defaultValue.getMin() != null) { if (defaultValue.getMin() != null) {

View file

@ -106,7 +106,7 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
*/ */
public static <C> @NonNull ScoreboardCriterionArgument<C> optional( public static <C> @NonNull ScoreboardCriterionArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final ScoreboardCriterion defaultCriterion final @NonNull ScoreboardCriterion defaultCriterion
) { ) {
return ScoreboardCriterionArgument.<C>newBuilder(name).asOptionalWithDefault(defaultCriterion.getName()).build(); return ScoreboardCriterionArgument.<C>newBuilder(name).asOptionalWithDefault(defaultCriterion.getName()).build();
} }

View file

@ -65,7 +65,7 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
}); });
} }
protected abstract ArgumentParseResult<I> parseIntermediate( protected abstract @NonNull ArgumentParseResult<@NonNull I> parseIntermediate(
@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandContext<@NonNull C> commandContext,
@NonNull Queue<@NonNull String> inputQueue @NonNull Queue<@NonNull String> inputQueue
); );
@ -79,7 +79,11 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
* @return a resolved value * @return a resolved value
* @since 1.5.0 * @since 1.5.0
*/ */
protected abstract ArgumentParseResult<R> resolveClient(CommandContext<C> context, CommandSource source, I value); protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveClient(
@NonNull CommandContext<@NonNull C> context,
@NonNull CommandSource source,
@NonNull I value
);
/** /**
* Resolve the final value for this argument when running on the server. * Resolve the final value for this argument when running on the server.
@ -90,6 +94,10 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
* @return a resolved value * @return a resolved value
* @since 1.5.0 * @since 1.5.0
*/ */
protected abstract ArgumentParseResult<R> resolveServer(CommandContext<C> context, CommandSource source, I value); protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveServer(
@NonNull CommandContext<@NonNull C> context,
@NonNull CommandSource source,
@NonNull I value
);
} }

View file

@ -138,7 +138,7 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
@Override @Override
protected ArgumentParseResult<String> parseIntermediate( protected @NonNull ArgumentParseResult<String> parseIntermediate(
@NonNull final CommandContext<@NonNull C> commandContext, @NonNull final CommandContext<@NonNull C> commandContext,
@NonNull final Queue<@NonNull String> inputQueue @NonNull final Queue<@NonNull String> inputQueue
) { ) {
@ -150,7 +150,7 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
@Override @Override
protected ArgumentParseResult<Team> resolveClient( protected @NonNull ArgumentParseResult<Team> resolveClient(
final @NonNull CommandContext<C> context, final @NonNull CommandContext<C> context,
final @NonNull CommandSource source, final @NonNull CommandSource source,
final @NonNull String value final @NonNull String value
@ -163,7 +163,7 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
} }
@Override @Override
protected ArgumentParseResult<Team> resolveServer( protected @NonNull ArgumentParseResult<Team> resolveServer(
final @NonNull CommandContext<C> context, final @NonNull CommandContext<C> context,
final @NonNull CommandSource source, final @NonNull CommandSource source,
final @NonNull String value final @NonNull String value

View file

@ -104,7 +104,7 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
*/ */
public static <C> @NonNull TimeArgument<C> optional( public static <C> @NonNull TimeArgument<C> optional(
final @NonNull String name, final @NonNull String name,
final MinecraftTime defaultTime final @NonNull MinecraftTime defaultTime
) { ) {
return TimeArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTime.toString()).build(); return TimeArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTime.toString()).build();
} }

View file

@ -24,6 +24,8 @@
package cloud.commandframework.fabric.data; package cloud.commandframework.fabric.data;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.time.temporal.TemporalUnit; import java.time.temporal.TemporalUnit;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -50,7 +52,7 @@ public final class MinecraftTime {
* @return a time holder * @return a time holder
* @since 1.5.0 * @since 1.5.0
*/ */
public static MinecraftTime of(final long ticks) { public static @NonNull MinecraftTime of(final long ticks) {
return ticks == 0 ? ZERO : new MinecraftTime(ticks); return ticks == 0 ? ZERO : new MinecraftTime(ticks);
} }
@ -62,7 +64,7 @@ public final class MinecraftTime {
* @return a time holder * @return a time holder
* @since 1.5.0 * @since 1.5.0
*/ */
public static MinecraftTime of(final long amount, final TemporalUnit unit) { public static @NonNull MinecraftTime of(final long amount, final @NonNull TemporalUnit unit) {
requireNonNull(unit, "unit"); requireNonNull(unit, "unit");
return new MinecraftTime(Math.round(amount / 50d * unit.getDuration().toMillis())); return new MinecraftTime(Math.round(amount / 50d * unit.getDuration().toMillis()));
} }
@ -75,7 +77,7 @@ public final class MinecraftTime {
* @return a time holder * @return a time holder
* @since 1.5.0 * @since 1.5.0
*/ */
public static MinecraftTime of(final long amount, final TimeUnit unit) { public static @NonNull MinecraftTime of(final long amount, final @NonNull TimeUnit unit) {
requireNonNull(unit, "unit"); requireNonNull(unit, "unit");
return amount == 0 ? ZERO : new MinecraftTime(TimeUnit.MILLISECONDS.convert(amount, unit) / 50); return amount == 0 ? ZERO : new MinecraftTime(TimeUnit.MILLISECONDS.convert(amount, unit) / 50);
} }
@ -114,7 +116,7 @@ public final class MinecraftTime {
* @return the target duration, as represented by the provided unit * @return the target duration, as represented by the provided unit
* @since 1.5.0 * @since 1.5.0
*/ */
public long convertTo(final TemporalUnit unit) { public long convertTo(final @NonNull TemporalUnit unit) {
return this.ticks * 50 / unit.getDuration().toMillis(); return this.ticks * 50 / unit.getDuration().toMillis();
} }
@ -125,7 +127,7 @@ public final class MinecraftTime {
* @return the target duration, as represented by the provided unit * @return the target duration, as represented by the provided unit
* @since 1.5.0 * @since 1.5.0
*/ */
public long convertTo(final TimeUnit unit) { public long convertTo(final @NonNull TimeUnit unit) {
return unit.convert(this.ticks * 50, TimeUnit.MILLISECONDS); return unit.convert(this.ticks * 50, TimeUnit.MILLISECONDS);
} }

View file

@ -25,6 +25,7 @@
package cloud.commandframework.fabric.data; package cloud.commandframework.fabric.data;
import net.minecraft.command.EntitySelector; import net.minecraft.command.EntitySelector;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection; import java.util.Collection;
@ -44,7 +45,7 @@ public interface Selector<V> {
* @return the input * @return the input
* @since 1.5.0 * @since 1.5.0
*/ */
String getInput(); @NonNull String getInput();
/** /**
* If this value came from a parsed selector, this will provide the details of that selector. * If this value came from a parsed selector, this will provide the details of that selector.
@ -62,7 +63,7 @@ public interface Selector<V> {
* @return all matched entities * @return all matched entities
* @since 1.5.0 * @since 1.5.0
*/ */
Collection<V> get(); @NonNull Collection<V> get();
/** /**
* A specialized selector that can only return one value. * A specialized selector that can only return one value.
@ -73,7 +74,7 @@ public interface Selector<V> {
interface Single<V> extends Selector<V> { interface Single<V> extends Selector<V> {
@Override @Override
default Collection<V> get() { default @NonNull Collection<V> get() {
return Collections.singletonList(this.getSingle()); return Collections.singletonList(this.getSingle());
} }
@ -83,7 +84,7 @@ public interface Selector<V> {
* @return the value * @return the value
* @since 1.5.0 * @since 1.5.0
*/ */
V getSingle(); @NonNull V getSingle();
} }