fabric: Add builders for many of the basic argument types

This commit is contained in:
Zach Levis 2021-01-03 23:22:02 -08:00 committed by Jason
parent 48181164b0
commit 0af44e2406
19 changed files with 2242 additions and 3 deletions

View file

@ -50,6 +50,7 @@ import net.minecraft.command.argument.MessageArgumentType;
import net.minecraft.command.argument.MobEffectArgumentType;
import net.minecraft.command.argument.NbtCompoundTagArgumentType;
import net.minecraft.command.argument.NbtPathArgumentType;
import net.minecraft.command.argument.NbtTagArgumentType;
import net.minecraft.command.argument.NumberRangeArgumentType;
import net.minecraft.command.argument.ObjectiveCriteriaArgumentType;
import net.minecraft.command.argument.OperationArgumentType;
@ -59,6 +60,7 @@ import net.minecraft.command.argument.UuidArgumentType;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.predicate.NumberRange;
import net.minecraft.scoreboard.ScoreboardCriterion;
@ -84,6 +86,7 @@ import java.util.function.Supplier;
* @param <C> the manager's sender type
* @param <S> the platform sender type
* @see FabricServerCommandManager for server commands
* @since 1.4.0
*/
public abstract class FabricCommandManager<C, S extends CommandSource> extends CommandManager<C> implements BrigadierManagerHolder<C> {
@ -139,10 +142,8 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
/* Wrapped/Constant Brigadier types, native value type */
this.registerConstantNativeParserSupplier(Formatting.class, ColorArgumentType.color());
this.registerConstantNativeParserSupplier(BlockPredicateArgumentType.BlockPredicate.class,
BlockPredicateArgumentType.blockPredicate());
this.registerConstantNativeParserSupplier(MessageArgumentType.MessageFormat.class, MessageArgumentType.message());
this.registerConstantNativeParserSupplier(CompoundTag.class, NbtCompoundTagArgumentType.nbtCompound());
this.registerConstantNativeParserSupplier(Tag.class, NbtTagArgumentType.nbtTag());
this.registerConstantNativeParserSupplier(NbtPathArgumentType.NbtPath.class, NbtPathArgumentType.nbtPath());
this.registerConstantNativeParserSupplier(ScoreboardCriterion.class, ObjectiveCriteriaArgumentType.objectiveCriteria());
this.registerConstantNativeParserSupplier(OperationArgumentType.Operation.class, OperationArgumentType.operation());
@ -159,6 +160,9 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
this.registerConstantNativeParserSupplier(ItemStackArgument.class, ItemStackArgumentType.itemStack());
/* Wrapped/Constant Brigadier types, mapped value type */
this.registerConstantNativeParserSupplier(BlockPredicateArgumentType.BlockPredicate.class,
BlockPredicateArgumentType.blockPredicate());
this.registerConstantNativeParserSupplier(MessageArgumentType.MessageFormat.class, MessageArgumentType.message());
/*this.registerConstantNativeParserSupplier(GameProfile.class, GameProfileArgumentType.gameProfile());
this.registerConstantNativeParserSupplier(BlockPos.class, BlockPosArgumentType.blockPos());
this.registerConstantNativeParserSupplier(ColumnPos.class, ColumnPosArgumentType.columnPos());

View file

@ -0,0 +1,131 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.AngleArgumentType;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for an angle, specified in degrees.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType.Angle> {
// todo: This angle is relative to a certain entity
// Vanilla only supports this on the server, we should be able to make it work on the client just fine too.
AngleArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(AngleArgumentType.angle()),
defaultValue,
AngleArgumentType.Angle.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> AngleArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new AngleArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull AngleArgument<C> of(final @NonNull String name) {
return AngleArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull AngleArgument<C> optional(final @NonNull String name) {
return AngleArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultAngle Default angle, in degrees
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull AngleArgument<C> optional(
final @NonNull String name,
final float defaultAngle
) {
return AngleArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultAngle)).build();
}
public static final class Builder<C> extends TypedBuilder<C, AngleArgumentType.Angle, Builder<C>> {
Builder(final @NonNull String name) {
super(AngleArgumentType.Angle.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull AngleArgument<C> build() {
return new AngleArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,137 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import io.leangen.geantyref.TypeToken;
import net.minecraft.command.argument.SwizzleArgumentType;
import net.minecraft.util.math.Direction;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
/**
* An argument for a set of axes, described in Vanilla as a "swizzle".
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.Axis>> {
private static final TypeToken<EnumSet<Direction.Axis>> TYPE = new TypeToken<EnumSet<Direction.Axis>>() {};
AxisArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(SwizzleArgumentType.swizzle()),
defaultValue,
TYPE,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> AxisArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new AxisArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull AxisArgument<C> of(final @NonNull String name) {
return AxisArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull AxisArgument<C> optional(final @NonNull String name) {
return AxisArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValues Default axes to include
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull AxisArgument<C> optional(
final @NonNull String name,
final @NonNull Set<Direction.@NonNull Axis> defaultValues
) {
final StringBuilder builder = new StringBuilder();
for (final Direction.Axis axis : defaultValues) {
builder.append(axis.getName());
}
return AxisArgument.<C>newBuilder(name).asOptionalWithDefault(builder.toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, EnumSet<Direction.Axis>, Builder<C>> {
Builder(final @NonNull String name) {
super(TYPE, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull AxisArgument<C> build() {
return new AxisArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,126 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.ColorArgumentType;
import net.minecraft.util.Formatting;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for named colors in the {@link Formatting} enum.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
ColorArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(required, name, new WrappedBrigadierParser<>(ColorArgumentType.color()), defaultValue, Formatting.class,
suggestionsProvider);
}
/**
* Create a new builder
*
* @param name Name of the component
* @param <C> Command sender type
* @return Created builder
*/
public static <C> ColorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ColorArgument.Builder<>(name);
}
/**
* Create a new required command component
*
* @param name Component name
* @param <C> Command sender type
* @return Created component
*/
public static <C> @NonNull ColorArgument<C> of(final @NonNull String name) {
return ColorArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command component
*
* @param name Component name
* @param <C> Command sender type
* @return Created component
*/
public static <C> @NonNull ColorArgument<C> optional(final @NonNull String name) {
return ColorArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Component name
* @param defaultColor Default colour, must be {@link Formatting#isColor() a color}
* @param <C> Command sender type
* @return Created component
*/
public static <C> @NonNull ColorArgument<C> optional(
final @NonNull String name,
final @NonNull Formatting defaultColor
) {
if (!defaultColor.isColor()) {
throw new IllegalArgumentException("Only color types are allowed but " + defaultColor + " was provided");
}
return ColorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultColor.toString()).build();
}
public static final class Builder<C> extends CommandArgument.TypedBuilder<C, Formatting, Builder<C>> {
Builder(final @NonNull String name) {
super(Formatting.class, name);
}
/**
* Build a new argument
*
* @return Constructed argument
*/
@Override
public @NonNull ColorArgument<C> build() {
return new ColorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,129 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.NbtCompoundTagArgumentType;
import net.minecraft.nbt.CompoundTag;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for the string representation of an NBT {@link CompoundTag}.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag> {
CompoundTagArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(NbtCompoundTagArgumentType.nbtCompound()),
defaultValue,
CompoundTag.class,
suggestionsProvider
);
}
/**
* Create a new builder
*
* @param name Name of the component
* @param <C> Command sender type
* @return Created builder
*/
public static <C> CompoundTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new CompoundTagArgument.Builder<>(name);
}
/**
* Create a new required command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CompoundTagArgument<C> of(final @NonNull String name) {
return CompoundTagArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CompoundTagArgument<C> optional(final @NonNull String name) {
return CompoundTagArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Component name
* @param defaultTag Default tag value
* @param <C> Command sender type
* @return Created component
*/
public static <C> @NonNull CompoundTagArgument<C> optional(
final @NonNull String name,
final @NonNull CompoundTag defaultTag
) {
return CompoundTagArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, CompoundTag, Builder<C>> {
Builder(final @NonNull String name) {
super(CompoundTag.class, name);
}
/**
* Builder a new example component
*
* @return Constructed component
*/
@Override
public @NonNull CompoundTagArgument<C> build() {
return new CompoundTagArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,130 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.ItemEnchantmentArgumentType;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.util.registry.Registry;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument parsing enchantment identifier from the {@link Registry#ENCHANTMENT enchantments registry}.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class EnchantmentArgument<C> extends CommandArgument<C, Enchantment> {
EnchantmentArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(ItemEnchantmentArgumentType.itemEnchantment()),
defaultValue,
Enchantment.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> EnchantmentArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new EnchantmentArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull EnchantmentArgument<C> of(final @NonNull String name) {
return EnchantmentArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull EnchantmentArgument<C> optional(final @NonNull String name) {
return EnchantmentArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull EnchantmentArgument<C> optional(
final @NonNull String name,
final Enchantment defaultValue
) {
return EnchantmentArgument.<C>newBuilder(name).asOptionalWithDefault(Registry.ENCHANTMENT.getId(defaultValue).toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, Enchantment, Builder<C>> {
Builder(final @NonNull String name) {
super(Enchantment.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull EnchantmentArgument<C> build() {
return new EnchantmentArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,128 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.EntityAnchorArgumentType;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument parsing an entity anchor.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnchorArgumentType.EntityAnchor> {
EntityAnchorArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(EntityAnchorArgumentType.entityAnchor()),
defaultValue,
EntityAnchorArgumentType.EntityAnchor.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> EntityAnchorArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new EntityAnchorArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull EntityAnchorArgument<C> of(final @NonNull String name) {
return EntityAnchorArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull EntityAnchorArgument<C> optional(final @NonNull String name) {
return EntityAnchorArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull EntityAnchorArgument<C> optional(
final @NonNull String name,
final EntityAnchorArgumentType.@NonNull EntityAnchor defaultValue
) {
return EntityAnchorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.name()).build();
}
public static final class Builder<C> extends TypedBuilder<C, EntityAnchorArgumentType.EntityAnchor, Builder<C>> {
Builder(final @NonNull String name) {
super(EntityAnchorArgumentType.EntityAnchor.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull EntityAnchorArgument<C> build() {
return new EntityAnchorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,139 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.NumberRangeArgumentType;
import net.minecraft.predicate.NumberRange;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
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
* optional.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.FloatRange> {
FloatRangeArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(NumberRangeArgumentType.method_30918()),
defaultValue,
NumberRange.FloatRange.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> FloatRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new FloatRangeArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull FloatRangeArgument<C> of(final @NonNull String name) {
return FloatRangeArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull FloatRangeArgument<C> optional(final @NonNull String name) {
return FloatRangeArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull FloatRangeArgument<C> optional(
final @NonNull String name,
final NumberRange.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 FloatRangeArgument.<C>newBuilder(name).asOptionalWithDefault(value.toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, NumberRange.FloatRange, Builder<C>> {
Builder(final @NonNull String name) {
super(NumberRange.FloatRange.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull FloatRangeArgument<C> build() {
return new FloatRangeArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,129 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.util.Identifier;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument parsing an identifier, or "resource location".
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class IdentifierArgument<C> extends CommandArgument<C, Identifier> {
IdentifierArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(IdentifierArgumentType.identifier()),
defaultValue,
Identifier.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> IdentifierArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new IdentifierArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull IdentifierArgument<C> of(final @NonNull String name) {
return IdentifierArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull IdentifierArgument<C> optional(final @NonNull String name) {
return IdentifierArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull IdentifierArgument<C> optional(
final @NonNull String name,
final @NonNull Identifier defaultValue
) {
return IdentifierArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, Identifier, Builder<C>> {
Builder(final @NonNull String name) {
super(Identifier.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull IdentifierArgument<C> build() {
return new IdentifierArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,139 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.NumberRangeArgumentType;
import net.minecraft.predicate.NumberRange;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
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
* optional.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.IntRange> {
IntRangeArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(NumberRangeArgumentType.numberRange()),
defaultValue,
NumberRange.IntRange.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> IntRangeArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new IntRangeArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull IntRangeArgument<C> of(final @NonNull String name) {
return IntRangeArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull IntRangeArgument<C> optional(final @NonNull String name) {
return IntRangeArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull IntRangeArgument<C> optional(
final @NonNull String name,
final NumberRange.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 IntRangeArgument.<C>newBuilder(name).asOptionalWithDefault(value.toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, NumberRange.IntRange, Builder<C>> {
Builder(final @NonNull String name) {
super(NumberRange.IntRange.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull IntRangeArgument<C> build() {
return new IntRangeArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,137 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.ItemStackArgument;
import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.item.ItemStack;
import net.minecraft.util.registry.Registry;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument parsing an item identifier and optional NBT data
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgument> {
ItemDataArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(ItemStackArgumentType.itemStack()),
defaultValue,
ItemStackArgument.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> ItemDataArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ItemDataArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ItemDataArgument<C> of(final @NonNull String name) {
return ItemDataArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ItemDataArgument<C> optional(final @NonNull String name) {
return ItemDataArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ItemDataArgument<C> optional(
final @NonNull String name,
final 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();
}
public static final class Builder<C> extends TypedBuilder<C, ItemStackArgument, Builder<C>> {
Builder(final @NonNull String name) {
super(ItemStackArgument.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull ItemDataArgument<C> build() {
return new ItemDataArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,128 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.NbtPathArgumentType;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for NBT paths to locations within {@link net.minecraft.nbt.Tag Tags}.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgumentType.NbtPath> {
NbtPathArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(NbtPathArgumentType.nbtPath()),
defaultValue,
NbtPathArgumentType.NbtPath.class,
suggestionsProvider
);
}
/**
* Create a new builder
*
* @param name Name of the component
* @param <C> Command sender type
* @return Created builder
*/
public static <C> NbtPathArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new NbtPathArgument.Builder<>(name);
}
/**
* Create a new required command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull NbtPathArgument<C> of(final @NonNull String name) {
return NbtPathArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull NbtPathArgument<C> optional(final @NonNull String name) {
return NbtPathArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Component name
* @param defaultTag Default tag value
* @param <C> Command sender type
* @return Created component
*/
public static <C> @NonNull NbtPathArgument<C> optional(
final @NonNull String name,
final NbtPathArgumentType.@NonNull NbtPath defaultTag
) {
return NbtPathArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, NbtPathArgumentType.NbtPath, Builder<C>> {
Builder(final @NonNull String name) {
super(NbtPathArgumentType.NbtPath.class, name);
}
/**
* Builder a new example component
*
* @return Constructed component
*/
@Override
public @NonNull NbtPathArgument<C> build() {
return new NbtPathArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,129 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.NbtTagArgumentType;
import net.minecraft.nbt.Tag;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for the string representation of an NBT {@link Tag}.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
NbtTagArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(NbtTagArgumentType.nbtTag()),
defaultValue,
Tag.class,
suggestionsProvider
);
}
/**
* Create a new builder
*
* @param name Name of the component
* @param <C> Command sender type
* @return Created builder
*/
public static <C> NbtTagArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new NbtTagArgument.Builder<>(name);
}
/**
* Create a new required command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull NbtTagArgument<C> of(final @NonNull String name) {
return NbtTagArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull NbtTagArgument<C> optional(final @NonNull String name) {
return NbtTagArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Component name
* @param defaultTag Default tag value
* @param <C> Command sender type
* @return Created component
*/
public static <C> @NonNull NbtTagArgument<C> optional(
final @NonNull String name,
final @NonNull Tag defaultTag
) {
return NbtTagArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, Tag, Builder<C>> {
Builder(final @NonNull String name) {
super(Tag.class, name);
}
/**
* Builder a new example component
*
* @return Constructed component
*/
@Override
public @NonNull NbtTagArgument<C> build() {
return new NbtTagArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,131 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.ParticleArgumentType;
import net.minecraft.particle.ParticleEffect;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for any {@link net.minecraft.particle.ParticleEffect}
*
* <p>These operations can be used to compare scores on a {@link net.minecraft.scoreboard.Scoreboard}.</p>
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class ParticleEffectArgument<C> extends CommandArgument<C, ParticleEffect> {
ParticleEffectArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(ParticleArgumentType.particle()),
defaultValue,
ParticleEffect.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> ParticleEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ParticleEffectArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ParticleEffectArgument<C> of(final @NonNull String name) {
return ParticleEffectArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ParticleEffectArgument<C> optional(final @NonNull String name) {
return ParticleEffectArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default particle effect value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ParticleEffectArgument<C> optional(
final @NonNull String name,
final ParticleEffect defaultValue
) {
return ParticleEffectArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue.asString()).build();
}
public static final class Builder<C> extends TypedBuilder<C, ParticleEffect, Builder<C>> {
Builder(final @NonNull String name) {
super(ParticleEffect.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull ParticleEffectArgument<C> build() {
return new ParticleEffectArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
}
}
}

View file

@ -0,0 +1,134 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.ObjectiveCriteriaArgumentType;
import net.minecraft.scoreboard.ScoreboardCriterion;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for a {@linkplain ScoreboardCriterion criterion} in a scoreboard.
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, ScoreboardCriterion> {
ScoreboardCriterionArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(ObjectiveCriteriaArgumentType.objectiveCriteria()),
defaultValue,
ScoreboardCriterion.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> ScoreboardCriterionArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ScoreboardCriterionArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ScoreboardCriterionArgument<C> of(final @NonNull String name) {
return ScoreboardCriterionArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ScoreboardCriterionArgument<C> optional(final @NonNull String name) {
return ScoreboardCriterionArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultCriterion Default criterion
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ScoreboardCriterionArgument<C> optional(
final @NonNull String name,
final ScoreboardCriterion defaultCriterion
) {
return ScoreboardCriterionArgument.<C>newBuilder(name).asOptionalWithDefault(defaultCriterion.getName()).build();
}
public static final class Builder<C> extends TypedBuilder<C, ScoreboardCriterion, Builder<C>> {
Builder(final @NonNull String name) {
super(ScoreboardCriterion.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull ScoreboardCriterionArgument<C> build() {
return new ScoreboardCriterionArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
}
}
}

View file

@ -0,0 +1,135 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.OperationArgumentType;
import net.minecraft.command.argument.OperationArgumentType.Operation;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument for selecting any of the logical operations in {@link Operation}.
*
* <p>These operations can be used to compare scores on a {@link net.minecraft.scoreboard.Scoreboard}.</p>
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Operation> {
ScoreboardOperationArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(OperationArgumentType.operation()),
defaultValue,
Operation.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> ScoreboardOperationArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new ScoreboardOperationArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ScoreboardOperationArgument<C> of(final @NonNull String name) {
return ScoreboardOperationArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull ScoreboardOperationArgument<C> optional(final @NonNull String name) {
return ScoreboardOperationArgument.<C>newBuilder(name).asOptional().build();
}
/* (todo: there's no way to get a parseable form from an unknown Operation)
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultTag Default tag value
* @param <C> Command sender type
* @return Created argument
*
public static <C> @NonNull ScoreboardOperationArgument<C> optional(
final @NonNull String name,
final Operation defaultTag
) {
return ScoreboardOperationArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build();
}*/
public static final class Builder<C> extends TypedBuilder<C, Operation, Builder<C>> {
Builder(final @NonNull String name) {
super(Operation.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull ScoreboardOperationArgument<C> build() {
return new ScoreboardOperationArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
}
}
}

View file

@ -0,0 +1,137 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.fabric.argument;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
import cloud.commandframework.context.CommandContext;
import net.minecraft.command.argument.MobEffectArgumentType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.util.registry.Registry;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.function.BiFunction;
/**
* An argument parsing a status effect from the {@link net.minecraft.util.registry.Registry#STATUS_EFFECT status effect registry}
*
* @param <C> the sender type
* @since 1.4.0
*/
public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffect> {
StatusEffectArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
super(
required,
name,
new WrappedBrigadierParser<>(MobEffectArgumentType.mobEffect()),
defaultValue,
StatusEffect.class,
suggestionsProvider
);
}
/**
* Create a new builder.
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
public static <C> StatusEffectArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new StatusEffectArgument.Builder<>(name);
}
/**
* Create a new required command argument.
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull StatusEffectArgument<C> of(final @NonNull String name) {
return StatusEffectArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional command argument
*
* @param name Component name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull StatusEffectArgument<C> optional(final @NonNull String name) {
return StatusEffectArgument.<C>newBuilder(name).asOptional().build();
}
/**
* Create a new optional command argument with a default value
*
* @param name Argument name
* @param defaultValue Default value
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull StatusEffectArgument<C> optional(
final @NonNull String name,
final @NonNull StatusEffect defaultValue
) {
return StatusEffectArgument.<C>newBuilder(name)
.asOptionalWithDefault(Registry.STATUS_EFFECT.getId(defaultValue).toString())
.build();
}
public static final class Builder<C> extends TypedBuilder<C, StatusEffect, Builder<C>> {
Builder(final @NonNull String name) {
super(StatusEffect.class, name);
}
/**
* Build a new criterion argument
*
* @return Constructed argument
*/
@Override
public @NonNull StatusEffectArgument<C> build() {
return new StatusEffectArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
}
}
}

View file

@ -0,0 +1,28 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
/**
* Arguments for the Fabric environment.
*/
package cloud.commandframework.fabric.argument;