fabric: Remap to Mojang names
This commit is contained in:
parent
7dd9517795
commit
28821b5ff1
51 changed files with 656 additions and 670 deletions
|
|
@ -25,7 +25,6 @@ object Versions {
|
||||||
const val guava = "21.0-jre"
|
const val guava = "21.0-jre"
|
||||||
const val fabricLoader = "0.11.1"
|
const val fabricLoader = "0.11.1"
|
||||||
const val fabricMc = "1.16.5"
|
const val fabricMc = "1.16.5"
|
||||||
const val fabricYarn = "1"
|
|
||||||
const val fabricApi = "0.31.0+1.16"
|
const val fabricApi = "0.31.0+1.16"
|
||||||
|
|
||||||
// IRC DEPENDENCIES
|
// IRC DEPENDENCIES
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ tasks {
|
||||||
|
|
||||||
withType(Javadoc::class).configureEach {
|
withType(Javadoc::class).configureEach {
|
||||||
(options as? StandardJavadocDocletOptions)?.apply {
|
(options as? StandardJavadocDocletOptions)?.apply {
|
||||||
links("https://maven.fabricmc.net/docs/yarn-${Versions.fabricMc}+build.${Versions.fabricYarn}/")
|
//links("https://maven.fabricmc.net/docs/yarn-${Versions.fabricMc}+build.${Versions.fabricYarn}/") // todo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ tasks {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft("com.mojang", "minecraft", Versions.fabricMc)
|
minecraft("com.mojang", "minecraft", Versions.fabricMc)
|
||||||
mappings("net.fabricmc", "yarn", "${Versions.fabricMc}+build.${Versions.fabricYarn}", classifier = "v2")
|
mappings(minecraft.officialMojangMappings())
|
||||||
modImplementation("net.fabricmc", "fabric-loader", Versions.fabricLoader)
|
modImplementation("net.fabricmc", "fabric-loader", Versions.fabricLoader)
|
||||||
modImplementation(fabricApi.module("fabric-command-api-v1", Versions.fabricApi))
|
modImplementation(fabricApi.module("fabric-command-api-v1", Versions.fabricApi))
|
||||||
modImplementation(fabricApi.module("fabric-lifecycle-events-v1", Versions.fabricApi))
|
modImplementation(fabricApi.module("fabric-lifecycle-events-v1", Versions.fabricApi))
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.permission.PredicatePermission;
|
import cloud.commandframework.permission.PredicatePermission;
|
||||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.network.ClientCommandSource;
|
import net.minecraft.client.multiplayer.ClientSuggestionProvider;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -88,9 +88,9 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
|
||||||
commandSourceMapper,
|
commandSourceMapper,
|
||||||
backwardsCommandSourceMapper,
|
backwardsCommandSourceMapper,
|
||||||
new FabricCommandRegistrationHandler.Client<>(),
|
new FabricCommandRegistrationHandler.Client<>(),
|
||||||
() -> (FabricClientCommandSource) new ClientCommandSource(
|
() -> (FabricClientCommandSource) new ClientSuggestionProvider(
|
||||||
MinecraftClient.getInstance().getNetworkHandler(),
|
Minecraft.getInstance().getConnection(),
|
||||||
MinecraftClient.getInstance()
|
Minecraft.getInstance()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull PredicatePermission<C> integratedServerRunning() {
|
public static <C> @NonNull PredicatePermission<C> integratedServerRunning() {
|
||||||
return sender -> MinecraftClient.getInstance().isIntegratedServerRunning();
|
return sender -> Minecraft.getInstance().hasSingleplayerServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -134,7 +134,7 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull PredicatePermission<C> integratedServerNotRunning() {
|
public static <C> @NonNull PredicatePermission<C> integratedServerNotRunning() {
|
||||||
return sender -> !MinecraftClient.getInstance().isIntegratedServerRunning();
|
return sender -> !Minecraft.getInstance().hasSingleplayerServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -163,10 +163,10 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull PredicatePermission<C> cheatsAllowed(final boolean allowOnMultiplayer) {
|
public static <C> @NonNull PredicatePermission<C> cheatsAllowed(final boolean allowOnMultiplayer) {
|
||||||
return sender -> {
|
return sender -> {
|
||||||
if (!MinecraftClient.getInstance().isIntegratedServerRunning()) {
|
if (!Minecraft.getInstance().hasSingleplayerServer()) {
|
||||||
return allowOnMultiplayer;
|
return allowOnMultiplayer;
|
||||||
}
|
}
|
||||||
return MinecraftClient.getInstance().getServer().getPlayerManager().areCheatsAllowed();
|
return Minecraft.getInstance().getSingleplayerServer().getPlayerList().isAllowCheatsForAllPlayers();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,10 +196,10 @@ public final class FabricClientCommandManager<C> extends FabricCommandManager<C,
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull PredicatePermission<C> cheatsDisallowed(final boolean allowOnMultiplayer) {
|
public static <C> @NonNull PredicatePermission<C> cheatsDisallowed(final boolean allowOnMultiplayer) {
|
||||||
return sender -> {
|
return sender -> {
|
||||||
if (!MinecraftClient.getInstance().isIntegratedServerRunning()) {
|
if (!Minecraft.getInstance().hasSingleplayerServer()) {
|
||||||
return allowOnMultiplayer;
|
return allowOnMultiplayer;
|
||||||
}
|
}
|
||||||
return !MinecraftClient.getInstance().getServer().getPlayerManager().areCheatsAllowed();
|
return !Minecraft.getInstance().getSingleplayerServer().getPlayerList().isAllowCheatsForAllPlayers();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.keys.CloudKey;
|
import cloud.commandframework.keys.CloudKey;
|
||||||
import cloud.commandframework.keys.SimpleCloudKey;
|
import cloud.commandframework.keys.SimpleCloudKey;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keys used in {@link CommandContext}s available within a {@link FabricCommandManager}
|
* Keys used in {@link CommandContext}s available within a {@link FabricCommandManager}
|
||||||
|
|
@ -40,13 +40,13 @@ public final class FabricCommandContextKeys {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key used to store the native {@link CommandSource} in the command context.
|
* Key used to store the native {@link SharedSuggestionProvider} in the command context.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final CloudKey<CommandSource> NATIVE_COMMAND_SOURCE = SimpleCloudKey.of(
|
public static final CloudKey<SharedSuggestionProvider> NATIVE_COMMAND_SOURCE = SimpleCloudKey.of(
|
||||||
"cloud:fabric_command_source",
|
"cloud:fabric_command_source",
|
||||||
TypeToken.get(CommandSource.class)
|
TypeToken.get(SharedSuggestionProvider.class)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,41 +44,40 @@ import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import io.leangen.geantyref.GenericTypeReflector;
|
import io.leangen.geantyref.GenericTypeReflector;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.command.argument.AngleArgumentType;
|
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||||
import net.minecraft.command.argument.BlockPredicateArgumentType;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import net.minecraft.command.argument.ColorArgumentType;
|
import net.minecraft.commands.arguments.AngleArgument;
|
||||||
import net.minecraft.command.argument.DimensionArgumentType;
|
import net.minecraft.commands.arguments.ColorArgument;
|
||||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
import net.minecraft.commands.arguments.CompoundTagArgument;
|
||||||
import net.minecraft.command.argument.EntitySummonArgumentType;
|
import net.minecraft.commands.arguments.DimensionArgument;
|
||||||
import net.minecraft.command.argument.IdentifierArgumentType;
|
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||||
import net.minecraft.command.argument.ItemEnchantmentArgumentType;
|
import net.minecraft.commands.arguments.EntitySummonArgument;
|
||||||
import net.minecraft.command.argument.ItemStackArgument;
|
import net.minecraft.commands.arguments.ItemEnchantmentArgument;
|
||||||
import net.minecraft.command.argument.ItemStackArgumentType;
|
import net.minecraft.commands.arguments.MessageArgument;
|
||||||
import net.minecraft.command.argument.MessageArgumentType;
|
import net.minecraft.commands.arguments.MobEffectArgument;
|
||||||
import net.minecraft.command.argument.MobEffectArgumentType;
|
import net.minecraft.commands.arguments.NbtPathArgument;
|
||||||
import net.minecraft.command.argument.NbtCompoundTagArgumentType;
|
import net.minecraft.commands.arguments.NbtTagArgument;
|
||||||
import net.minecraft.command.argument.NbtPathArgumentType;
|
import net.minecraft.commands.arguments.ObjectiveCriteriaArgument;
|
||||||
import net.minecraft.command.argument.NbtTagArgumentType;
|
import net.minecraft.commands.arguments.OperationArgument;
|
||||||
import net.minecraft.command.argument.NumberRangeArgumentType;
|
import net.minecraft.commands.arguments.ParticleArgument;
|
||||||
import net.minecraft.command.argument.ObjectiveCriteriaArgumentType;
|
import net.minecraft.commands.arguments.RangeArgument;
|
||||||
import net.minecraft.command.argument.OperationArgumentType;
|
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||||
import net.minecraft.command.argument.ParticleArgumentType;
|
import net.minecraft.commands.arguments.UuidArgument;
|
||||||
import net.minecraft.command.argument.SwizzleArgumentType;
|
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument;
|
||||||
import net.minecraft.command.argument.TeamArgumentType;
|
import net.minecraft.commands.arguments.coordinates.SwizzleArgument;
|
||||||
import net.minecraft.command.argument.UuidArgumentType;
|
import net.minecraft.commands.arguments.item.ItemArgument;
|
||||||
import net.minecraft.command.suggestion.SuggestionProviders;
|
import net.minecraft.commands.arguments.item.ItemInput;
|
||||||
|
import net.minecraft.commands.synchronization.SuggestionProviders;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.particle.ParticleEffect;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.predicate.NumberRange;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.scoreboard.ScoreboardCriterion;
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
import net.minecraft.scoreboard.Team;
|
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||||
import net.minecraft.util.Formatting;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import net.minecraft.util.registry.RegistryKey;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
@ -108,7 +107,7 @@ import java.util.function.Supplier;
|
||||||
* @see FabricServerCommandManager for server commands
|
* @see FabricServerCommandManager for server commands
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public abstract class FabricCommandManager<C, S extends CommandSource> extends CommandManager<C> implements
|
public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider> extends CommandManager<C> implements
|
||||||
BrigadierManagerHolder<C> {
|
BrigadierManagerHolder<C> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
@ -130,8 +129,8 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
* use a synchronous execution coordinator. In most cases you will want to pick between
|
* use a synchronous execution coordinator. In most cases you will want to pick between
|
||||||
* {@link CommandExecutionCoordinator#simpleCoordinator()} and
|
* {@link CommandExecutionCoordinator#simpleCoordinator()} and
|
||||||
* {@link AsynchronousCommandExecutionCoordinator}
|
* {@link AsynchronousCommandExecutionCoordinator}
|
||||||
* @param commandSourceMapper Function that maps {@link CommandSource} to the command sender type
|
* @param commandSourceMapper Function that maps {@link SharedSuggestionProvider} to the command sender type
|
||||||
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link CommandSource}
|
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link SharedSuggestionProvider}
|
||||||
* @param registrationHandler the handler accepting command registrations
|
* @param registrationHandler the handler accepting command registrations
|
||||||
* @param dummyCommandSourceProvider a provider of a dummy command source, for use with brigadier registration
|
* @param dummyCommandSourceProvider a provider of a dummy command source, for use with brigadier registration
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
@ -167,38 +166,38 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
private void registerNativeBrigadierMappings(final @NonNull 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>>() {
|
brigadier.registerMapping(new TypeToken<UUIDArgument.UUIDParser<C>>() {
|
||||||
}, builder -> builder.toConstant(UuidArgumentType.uuid()));
|
}, builder -> builder.toConstant(UuidArgument.uuid()));
|
||||||
this.registerRegistryEntryMappings();
|
this.registerRegistryEntryMappings();
|
||||||
brigadier.registerMapping(new TypeToken<TeamArgument.TeamParser<C>>() {
|
brigadier.registerMapping(new TypeToken<TeamArgument.TeamParser<C>>() {
|
||||||
}, builder -> builder.toConstant(TeamArgumentType.team()));
|
}, builder -> builder.toConstant(net.minecraft.commands.arguments.TeamArgument.team()));
|
||||||
this.getParserRegistry().registerParserSupplier(TypeToken.get(Team.class), params -> new TeamArgument.TeamParser<>());
|
this.getParserRegistry().registerParserSupplier(TypeToken.get(PlayerTeam.class), params -> new TeamArgument.TeamParser<>());
|
||||||
|
|
||||||
/* Wrapped/Constant Brigadier types, native value type */
|
/* Wrapped/Constant Brigadier types, native value type */
|
||||||
this.registerConstantNativeParserSupplier(Formatting.class, ColorArgumentType.color());
|
this.registerConstantNativeParserSupplier(ChatFormatting.class, ColorArgument.color());
|
||||||
this.registerConstantNativeParserSupplier(CompoundTag.class, NbtCompoundTagArgumentType.nbtCompound());
|
this.registerConstantNativeParserSupplier(CompoundTag.class, CompoundTagArgument.compoundTag());
|
||||||
this.registerConstantNativeParserSupplier(Tag.class, NbtTagArgumentType.nbtTag());
|
this.registerConstantNativeParserSupplier(Tag.class, NbtTagArgument.nbtTag());
|
||||||
this.registerConstantNativeParserSupplier(NbtPathArgumentType.NbtPath.class, NbtPathArgumentType.nbtPath());
|
this.registerConstantNativeParserSupplier(NbtPathArgument.NbtPath.class, NbtPathArgument.nbtPath());
|
||||||
this.registerConstantNativeParserSupplier(ScoreboardCriterion.class, ObjectiveCriteriaArgumentType.objectiveCriteria());
|
this.registerConstantNativeParserSupplier(ObjectiveCriteria.class, ObjectiveCriteriaArgument.criteria());
|
||||||
this.registerConstantNativeParserSupplier(OperationArgumentType.Operation.class, OperationArgumentType.operation());
|
this.registerConstantNativeParserSupplier(OperationArgument.Operation.class, OperationArgument.operation());
|
||||||
this.registerConstantNativeParserSupplier(ParticleEffect.class, ParticleArgumentType.particle());
|
this.registerConstantNativeParserSupplier(ParticleOptions.class, ParticleArgument.particle());
|
||||||
this.registerConstantNativeParserSupplier(AngleArgumentType.Angle.class, AngleArgumentType.angle());
|
this.registerConstantNativeParserSupplier(AngleArgument.SingleAngle.class, AngleArgument.angle());
|
||||||
this.registerConstantNativeParserSupplier(new TypeToken<EnumSet<Direction.Axis>>() {
|
this.registerConstantNativeParserSupplier(new TypeToken<EnumSet<Direction.Axis>>() {
|
||||||
}, SwizzleArgumentType.swizzle());
|
}, SwizzleArgument.swizzle());
|
||||||
this.registerConstantNativeParserSupplier(Identifier.class, IdentifierArgumentType.identifier());
|
this.registerConstantNativeParserSupplier(ResourceLocation.class, ResourceLocationArgument.id());
|
||||||
this.registerConstantNativeParserSupplier(
|
this.registerConstantNativeParserSupplier(
|
||||||
EntityAnchorArgumentType.EntityAnchor.class,
|
EntityAnchorArgument.Anchor.class,
|
||||||
EntityAnchorArgumentType.entityAnchor()
|
EntityAnchorArgument.anchor()
|
||||||
);
|
);
|
||||||
this.registerConstantNativeParserSupplier(NumberRange.IntRange.class, NumberRangeArgumentType.numberRange());
|
this.registerConstantNativeParserSupplier(MinMaxBounds.Ints.class, RangeArgument.intRange());
|
||||||
this.registerConstantNativeParserSupplier(NumberRange.FloatRange.class, NumberRangeArgumentType.method_30918());
|
this.registerConstantNativeParserSupplier(MinMaxBounds.Floats.class, RangeArgument.floatRange());
|
||||||
this.registerConstantNativeParserSupplier(ItemStackArgument.class, ItemStackArgumentType.itemStack());
|
this.registerConstantNativeParserSupplier(ItemInput.class, ItemArgument.item());
|
||||||
|
|
||||||
/* Wrapped/Constant Brigadier types, mapped value type */
|
/* Wrapped/Constant Brigadier types, mapped value type */
|
||||||
this.registerConstantNativeParserSupplier(
|
this.registerConstantNativeParserSupplier(
|
||||||
BlockPredicateArgumentType.BlockPredicate.class,
|
BlockPredicateArgument.Result.class,
|
||||||
BlockPredicateArgumentType.blockPredicate()
|
BlockPredicateArgument.blockPredicate()
|
||||||
);
|
);
|
||||||
this.registerConstantNativeParserSupplier(MessageArgumentType.MessageFormat.class, MessageArgumentType.message());
|
this.registerConstantNativeParserSupplier(MessageArgument.Message.class, MessageArgument.message());
|
||||||
this.getParserRegistry().registerParserSupplier(
|
this.getParserRegistry().registerParserSupplier(
|
||||||
TypeToken.get(MinecraftTime.class),
|
TypeToken.get(MinecraftTime.class),
|
||||||
params -> FabricArgumentParsers.time()
|
params -> FabricArgumentParsers.time()
|
||||||
|
|
@ -212,30 +211,30 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
},
|
},
|
||||||
builder -> builder.to(argument -> {
|
builder -> builder.to(argument -> {
|
||||||
/* several registries have specialized argument types, so let's use those where possible */
|
/* several registries have specialized argument types, so let's use those where possible */
|
||||||
final RegistryKey<? extends Registry<?>> registry = argument.getRegistry();
|
final ResourceKey<? extends Registry<?>> registry = argument.getRegistry();
|
||||||
if (registry.equals(Registry.ENTITY_TYPE_KEY)) {
|
if (registry.equals(Registry.ENTITY_TYPE_REGISTRY)) {
|
||||||
return EntitySummonArgumentType.entitySummon();
|
return EntitySummonArgument.id();
|
||||||
} else if (registry.equals(Registry.ENCHANTMENT_KEY)) {
|
} else if (registry.equals(Registry.ENCHANTMENT_REGISTRY)) {
|
||||||
return ItemEnchantmentArgumentType.itemEnchantment();
|
return ItemEnchantmentArgument.enchantment();
|
||||||
} else if (registry.equals(Registry.MOB_EFFECT_KEY)) { // yarn wai
|
} else if (registry.equals(Registry.MOB_EFFECT_REGISTRY)) {
|
||||||
return MobEffectArgumentType.mobEffect();
|
return MobEffectArgument.effect();
|
||||||
} else if (registry.equals(Registry.DIMENSION)) {
|
} else if (registry.equals(Registry.DIMENSION_REGISTRY)) {
|
||||||
return DimensionArgumentType.dimension();
|
return DimensionArgument.dimension();
|
||||||
}
|
}
|
||||||
return IdentifierArgumentType.identifier();
|
return ResourceLocationArgument.id();
|
||||||
}
|
}
|
||||||
).suggestedBy((argument, useCloud) -> {
|
).suggestedBy((argument, useCloud) -> {
|
||||||
/* A few other registries have client-side suggestion providers but no argument type */
|
/* A few other registries have client-side suggestion providers but no argument type */
|
||||||
/* Type parameters are messed up here for some reason */
|
/* Type parameters are messed up here for some reason */
|
||||||
final RegistryKey<? extends Registry<?>> registry = argument.getRegistry();
|
final ResourceKey<? extends Registry<?>> registry = argument.getRegistry();
|
||||||
if (registry.equals(Registry.SOUND_EVENT_KEY)) {
|
if (registry.equals(Registry.SOUND_EVENT_REGISTRY)) {
|
||||||
return (SuggestionProvider<S>) SuggestionProviders.AVAILABLE_SOUNDS;
|
return (SuggestionProvider<S>) SuggestionProviders.AVAILABLE_SOUNDS;
|
||||||
} else if (registry.equals(Registry.BIOME_KEY)) {
|
} else if (registry.equals(Registry.BIOME_REGISTRY)) {
|
||||||
return (SuggestionProvider<S>) SuggestionProviders.ALL_BIOMES;
|
return (SuggestionProvider<S>) SuggestionProviders.AVAILABLE_BIOMES;
|
||||||
} else if (registry.equals(Registry.ENTITY_TYPE_KEY)
|
} else if (registry.equals(Registry.ENTITY_TYPE_REGISTRY)
|
||||||
|| registry.equals(Registry.ENCHANTMENT_KEY)
|
|| registry.equals(Registry.ENCHANTMENT_REGISTRY)
|
||||||
|| registry.equals(Registry.MOB_EFFECT_KEY)
|
|| registry.equals(Registry.MOB_EFFECT_REGISTRY)
|
||||||
|| registry.equals(Registry.DIMENSION)) {
|
|| registry.equals(Registry.DIMENSION_REGISTRY)) {
|
||||||
return null; /* for types with their own argument type, use Brigadier */
|
return null; /* for types with their own argument type, use Brigadier */
|
||||||
}
|
}
|
||||||
return useCloud; /* use cloud suggestions for anything else */
|
return useCloud; /* use cloud suggestions for anything else */
|
||||||
|
|
@ -247,13 +246,13 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
final Set<Class<?>> seenClasses = new HashSet<>();
|
final Set<Class<?>> seenClasses = new HashSet<>();
|
||||||
/* Some registries have types that are too generic... we'll skip those for now.
|
/* Some registries have types that are too generic... we'll skip those for now.
|
||||||
* Eventually, these could be resolved by using ParserParameters in some way? */
|
* Eventually, these could be resolved by using ParserParameters in some way? */
|
||||||
seenClasses.add(Identifier.class);
|
seenClasses.add(ResourceLocation.class);
|
||||||
seenClasses.add(Codec.class);
|
seenClasses.add(Codec.class);
|
||||||
for (final Field field : Registry.class.getDeclaredFields()) {
|
for (final Field field : Registry.class.getDeclaredFields()) {
|
||||||
if ((field.getModifiers() & MOD_PUBLIC_STATIC_FINAL) != MOD_PUBLIC_STATIC_FINAL) {
|
if ((field.getModifiers() & MOD_PUBLIC_STATIC_FINAL) != MOD_PUBLIC_STATIC_FINAL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!field.getType().equals(RegistryKey.class)) {
|
if (!field.getType().equals(ResourceKey.class)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -271,9 +270,9 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final RegistryKey<?> key;
|
final ResourceKey<?> key;
|
||||||
try {
|
try {
|
||||||
key = (RegistryKey<?>) field.get(null);
|
key = (ResourceKey<?>) field.get(null);
|
||||||
} catch (final IllegalAccessException ex) {
|
} catch (final IllegalAccessException ex) {
|
||||||
LOGGER.warn("Failed to access value of registry key in field {} of type {}", field.getName(), generic, ex);
|
LOGGER.warn("Failed to access value of registry key in field {} of type {}", field.getName(), generic, ex);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -327,7 +326,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the mapper from a game {@link CommandSource} to the manager's {@code C} type.
|
* Gets the mapper from a game {@link SharedSuggestionProvider} to the manager's {@code C} type.
|
||||||
*
|
*
|
||||||
* @return Command source mapper
|
* @return Command source mapper
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
@ -337,7 +336,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the mapper from the manager's {@code C} type to a game {@link CommandSource}.
|
* Gets the mapper from the manager's {@code C} type to a game {@link SharedSuggestionProvider}.
|
||||||
*
|
*
|
||||||
* @return Command source mapper
|
* @return Command source mapper
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
@ -366,7 +365,7 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
||||||
public @NonNull PredicatePermission<C> permissionLevel(final int permissionLevel) {
|
public @NonNull PredicatePermission<C> permissionLevel(final int permissionLevel) {
|
||||||
return sender -> this.getBackwardsCommandSourceMapper()
|
return sender -> this.getBackwardsCommandSourceMapper()
|
||||||
.apply(sender)
|
.apply(sender)
|
||||||
.hasPermissionLevel(permissionLevel);
|
.hasPermission(permissionLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ import com.mojang.brigadier.tree.RootCommandNode;
|
||||||
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
|
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
|
||||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.command.CommandManager.RegistrationEnvironment;
|
import net.minecraft.commands.Commands.CommandSelection;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
* @param <C> command sender type
|
* @param <C> command sender type
|
||||||
* @param <S> native sender type
|
* @param <S> native sender type
|
||||||
*/
|
*/
|
||||||
abstract class FabricCommandRegistrationHandler<C, S extends CommandSource> implements CommandRegistrationHandler {
|
abstract class FabricCommandRegistrationHandler<C, S extends SharedSuggestionProvider> implements CommandRegistrationHandler {
|
||||||
private @MonotonicNonNull FabricCommandManager<C, S> commandManager;
|
private @MonotonicNonNull FabricCommandManager<C, S> commandManager;
|
||||||
|
|
||||||
void initialize(final FabricCommandManager<C, S> manager) {
|
void initialize(final FabricCommandManager<C, S> manager) {
|
||||||
|
|
@ -122,7 +122,7 @@ abstract class FabricCommandRegistrationHandler<C, S extends CommandSource> impl
|
||||||
true,
|
true,
|
||||||
new FabricExecutor<>(
|
new FabricExecutor<>(
|
||||||
this.getCommandManager(),
|
this.getCommandManager(),
|
||||||
source -> source.getPlayer().getName().asString(),
|
source -> source.getPlayer().getGameProfile().getName(),
|
||||||
FabricClientCommandSource::sendError
|
FabricClientCommandSource::sendError
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -136,11 +136,11 @@ abstract class FabricCommandRegistrationHandler<C, S extends CommandSource> impl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Server<C> extends FabricCommandRegistrationHandler<C, ServerCommandSource> {
|
static class Server<C> extends FabricCommandRegistrationHandler<C, CommandSourceStack> {
|
||||||
private final Set<Command<C>> registeredCommands = ConcurrentHashMap.newKeySet();
|
private final Set<Command<C>> registeredCommands = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void initialize(final FabricCommandManager<C, ServerCommandSource> manager) {
|
void initialize(final FabricCommandManager<C, CommandSourceStack> manager) {
|
||||||
super.initialize(manager);
|
super.initialize(manager);
|
||||||
CommandRegistrationCallback.EVENT.register(this::registerAllCommands);
|
CommandRegistrationCallback.EVENT.register(this::registerAllCommands);
|
||||||
}
|
}
|
||||||
|
|
@ -151,27 +151,27 @@ abstract class FabricCommandRegistrationHandler<C, S extends CommandSource> impl
|
||||||
return this.registeredCommands.add((Command<C>) command);
|
return this.registeredCommands.add((Command<C>) command);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerAllCommands(final CommandDispatcher<ServerCommandSource> dispatcher, final boolean isDedicated) {
|
private void registerAllCommands(final CommandDispatcher<CommandSourceStack> dispatcher, final boolean isDedicated) {
|
||||||
this.getCommandManager().registrationCalled();
|
this.getCommandManager().registrationCalled();
|
||||||
for (final Command<C> command : this.registeredCommands) {
|
for (final Command<C> command : this.registeredCommands) {
|
||||||
/* Only register commands in the declared environment */
|
/* Only register commands in the declared environment */
|
||||||
final RegistrationEnvironment env = command.getCommandMeta().getOrDefault(
|
final CommandSelection env = command.getCommandMeta().getOrDefault(
|
||||||
FabricServerCommandManager.META_REGISTRATION_ENVIRONMENT,
|
FabricServerCommandManager.META_REGISTRATION_ENVIRONMENT,
|
||||||
RegistrationEnvironment.ALL
|
CommandSelection.ALL
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((env == RegistrationEnvironment.INTEGRATED && isDedicated)
|
if ((env == CommandSelection.INTEGRATED && isDedicated)
|
||||||
|| (env == RegistrationEnvironment.DEDICATED && !isDedicated)) {
|
|| (env == CommandSelection.DEDICATED && !isDedicated)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.registerCommand(dispatcher.getRoot(), command);
|
this.registerCommand(dispatcher.getRoot(), command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerCommand(final RootCommandNode<ServerCommandSource> dispatcher, final Command<C> command) {
|
private void registerCommand(final RootCommandNode<CommandSourceStack> dispatcher, final Command<C> command) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final StaticArgument<C> first = ((StaticArgument<C>) command.getArguments().get(0));
|
final StaticArgument<C> first = ((StaticArgument<C>) command.getArguments().get(0));
|
||||||
final CommandNode<ServerCommandSource> baseNode = this.getCommandManager().brigadierManager().createLiteralCommandNode(
|
final CommandNode<CommandSourceStack> baseNode = this.getCommandManager().brigadierManager().createLiteralCommandNode(
|
||||||
first.getName(),
|
first.getName(),
|
||||||
command,
|
command,
|
||||||
(src, perm) -> this.getCommandManager().hasPermission(
|
(src, perm) -> this.getCommandManager().hasPermission(
|
||||||
|
|
@ -179,7 +179,7 @@ abstract class FabricCommandRegistrationHandler<C, S extends CommandSource> impl
|
||||||
perm
|
perm
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
new FabricExecutor<>(this.getCommandManager(), ServerCommandSource::getName, ServerCommandSource::sendError));
|
new FabricExecutor<>(this.getCommandManager(), CommandSourceStack::getTextName, CommandSourceStack::sendFailure));
|
||||||
|
|
||||||
dispatcher.addChild(baseNode);
|
dispatcher.addChild(baseNode);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@ import cloud.commandframework.exceptions.NoSuchCommandException;
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.text.ClickEvent;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import net.minecraft.text.HoverEvent;
|
import net.minecraft.network.chat.ClickEvent;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.network.chat.ComponentUtils;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.HoverEvent;
|
||||||
import net.minecraft.text.Texts;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
@ -50,11 +50,11 @@ import java.util.concurrent.CompletionException;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
final class FabricExecutor<C, S extends SharedSuggestionProvider> implements Command<S> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
private static final Text NEWLINE = new LiteralText("\n");
|
private static final Component NEWLINE = new TextComponent("\n");
|
||||||
private static final String MESSAGE_INTERNAL_ERROR = "An internal error occurred while attempting to perform this command.";
|
private static final String MESSAGE_INTERNAL_ERROR = "An internal error occurred while attempting to perform this command.";
|
||||||
private static final String MESSAGE_NO_PERMS =
|
private static final String MESSAGE_NO_PERMS =
|
||||||
"I'm sorry, but you do not have permission to perform this command. "
|
"I'm sorry, but you do not have permission to perform this command. "
|
||||||
|
|
@ -63,12 +63,12 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
|
|
||||||
private final FabricCommandManager<C, S> manager;
|
private final FabricCommandManager<C, S> manager;
|
||||||
private final Function<S, String> getName;
|
private final Function<S, String> getName;
|
||||||
private final BiConsumer<S, Text> sendError;
|
private final BiConsumer<S, Component> sendError;
|
||||||
|
|
||||||
FabricExecutor(
|
FabricExecutor(
|
||||||
final @NonNull FabricCommandManager<C, S> manager,
|
final @NonNull FabricCommandManager<C, S> manager,
|
||||||
final @NonNull Function<S, String> getName,
|
final @NonNull Function<S, String> getName,
|
||||||
final @NonNull BiConsumer<S, Text> sendError
|
final @NonNull BiConsumer<S, Component> sendError
|
||||||
) {
|
) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.getName = getName;
|
this.getName = getName;
|
||||||
|
|
@ -100,9 +100,9 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
(InvalidSyntaxException) throwable,
|
(InvalidSyntaxException) throwable,
|
||||||
(c, e) -> this.sendError.accept(
|
(c, e) -> this.sendError.accept(
|
||||||
source,
|
source,
|
||||||
new LiteralText("Invalid Command Syntax. Correct command syntax is: ")
|
new TextComponent("Invalid Command Syntax. Correct command syntax is: ")
|
||||||
.append(new LiteralText(String.format("/%s", e.getCorrectSyntax()))
|
.append(new TextComponent(String.format("/%s", e.getCorrectSyntax()))
|
||||||
.styled(style -> style.withColor(Formatting.GRAY)))
|
.withStyle(style -> style.withColor(ChatFormatting.GRAY)))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||||
|
|
@ -110,21 +110,21 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
sender,
|
sender,
|
||||||
InvalidCommandSenderException.class,
|
InvalidCommandSenderException.class,
|
||||||
(InvalidCommandSenderException) throwable,
|
(InvalidCommandSenderException) throwable,
|
||||||
(c, e) -> this.sendError.accept(source, new LiteralText(throwable.getMessage()))
|
(c, e) -> this.sendError.accept(source, new TextComponent(throwable.getMessage()))
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof NoPermissionException) {
|
} else if (throwable instanceof NoPermissionException) {
|
||||||
this.manager.handleException(
|
this.manager.handleException(
|
||||||
sender,
|
sender,
|
||||||
NoPermissionException.class,
|
NoPermissionException.class,
|
||||||
(NoPermissionException) throwable,
|
(NoPermissionException) throwable,
|
||||||
(c, e) -> this.sendError.accept(source, new LiteralText(MESSAGE_NO_PERMS))
|
(c, e) -> this.sendError.accept(source, new TextComponent(MESSAGE_NO_PERMS))
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof NoSuchCommandException) {
|
} else if (throwable instanceof NoSuchCommandException) {
|
||||||
this.manager.handleException(
|
this.manager.handleException(
|
||||||
sender,
|
sender,
|
||||||
NoSuchCommandException.class,
|
NoSuchCommandException.class,
|
||||||
(NoSuchCommandException) throwable,
|
(NoSuchCommandException) throwable,
|
||||||
(c, e) -> this.sendError.accept(source, new LiteralText(MESSAGE_UNKNOWN_COMMAND))
|
(c, e) -> this.sendError.accept(source, new TextComponent(MESSAGE_UNKNOWN_COMMAND))
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof ArgumentParseException) {
|
} else if (throwable instanceof ArgumentParseException) {
|
||||||
this.manager.handleException(
|
this.manager.handleException(
|
||||||
|
|
@ -133,14 +133,14 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
(ArgumentParseException) throwable,
|
(ArgumentParseException) throwable,
|
||||||
(c, e) -> {
|
(c, e) -> {
|
||||||
if (throwable.getCause() instanceof CommandSyntaxException) {
|
if (throwable.getCause() instanceof CommandSyntaxException) {
|
||||||
this.sendError.accept(source, new LiteralText("Invalid Command Argument: ")
|
this.sendError.accept(source, new TextComponent("Invalid Command Argument: ")
|
||||||
.append(new LiteralText("")
|
.append(new TextComponent("")
|
||||||
.append(Texts.toText(((CommandSyntaxException) throwable.getCause()).getRawMessage()))
|
.append(ComponentUtils.fromMessage(((CommandSyntaxException) throwable.getCause()).getRawMessage()))
|
||||||
.formatted(Formatting.GRAY)));
|
.withStyle(ChatFormatting.GRAY)));
|
||||||
} else {
|
} else {
|
||||||
this.sendError.accept(source, new LiteralText("Invalid Command Argument: ")
|
this.sendError.accept(source, new TextComponent("Invalid Command Argument: ")
|
||||||
.append(new LiteralText(throwable.getCause().getMessage())
|
.append(new TextComponent(throwable.getCause().getMessage())
|
||||||
.formatted(Formatting.GRAY)));
|
.withStyle(ChatFormatting.GRAY)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -151,7 +151,7 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
(CommandExecutionException) throwable,
|
(CommandExecutionException) throwable,
|
||||||
(c, e) -> {
|
(c, e) -> {
|
||||||
this.sendError.accept(source, this.decorateHoverStacktrace(
|
this.sendError.accept(source, this.decorateHoverStacktrace(
|
||||||
new LiteralText(MESSAGE_INTERNAL_ERROR),
|
new TextComponent(MESSAGE_INTERNAL_ERROR),
|
||||||
throwable.getCause(),
|
throwable.getCause(),
|
||||||
sender
|
sender
|
||||||
));
|
));
|
||||||
|
|
@ -164,7 +164,7 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.sendError.accept(source, this.decorateHoverStacktrace(
|
this.sendError.accept(source, this.decorateHoverStacktrace(
|
||||||
new LiteralText(MESSAGE_INTERNAL_ERROR),
|
new TextComponent(MESSAGE_INTERNAL_ERROR),
|
||||||
throwable,
|
throwable,
|
||||||
sender
|
sender
|
||||||
));
|
));
|
||||||
|
|
@ -172,7 +172,7 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableText decorateHoverStacktrace(final MutableText input, final Throwable cause, final C sender) {
|
private MutableComponent decorateHoverStacktrace(final MutableComponent input, final Throwable cause, final C sender) {
|
||||||
if (!this.manager.hasPermission(sender, "cloud.hover-stacktrace")) {
|
if (!this.manager.hasPermission(sender, "cloud.hover-stacktrace")) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
@ -180,13 +180,13 @@ final class FabricExecutor<C, S extends CommandSource> implements Command<S> {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
cause.printStackTrace(new PrintWriter(writer));
|
cause.printStackTrace(new PrintWriter(writer));
|
||||||
final String stackTrace = writer.toString().replace("\t", " ");
|
final String stackTrace = writer.toString().replace("\t", " ");
|
||||||
return input.styled(style -> style
|
return input.withStyle(style -> style
|
||||||
.withHoverEvent(new HoverEvent(
|
.withHoverEvent(new HoverEvent(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
HoverEvent.Action.SHOW_TEXT,
|
||||||
new LiteralText(stackTrace)
|
new TextComponent(stackTrace)
|
||||||
.append(NEWLINE)
|
.append(NEWLINE)
|
||||||
.append(new LiteralText(" Click to copy")
|
.append(new TextComponent(" Click to copy")
|
||||||
.styled(s2 -> s2.withColor(Formatting.GRAY).withItalic(true)))
|
.withStyle(s2 -> s2.withColor(ChatFormatting.GRAY).withItalic(true)))
|
||||||
))
|
))
|
||||||
.withClickEvent(new ClickEvent(
|
.withClickEvent(new ClickEvent(
|
||||||
ClickEvent.Action.COPY_TO_CLIPBOARD,
|
ClickEvent.Action.COPY_TO_CLIPBOARD,
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,12 @@ import cloud.commandframework.meta.CommandMeta;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.commands.CommandSource;
|
||||||
import net.minecraft.server.command.CommandOutput;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.util.math.Vec2f;
|
import net.minecraft.world.phys.Vec2;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -60,17 +60,17 @@ import java.util.function.Function;
|
||||||
* @param <C> the command sender type
|
* @param <C> the command sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class FabricServerCommandManager<C> extends FabricCommandManager<C, ServerCommandSource> {
|
public final class FabricServerCommandManager<C> extends FabricCommandManager<C, CommandSourceStack> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A meta attribute specifying which environments a command should be registered in.
|
* A meta attribute specifying which environments a command should be registered in.
|
||||||
*
|
*
|
||||||
* <p>The default value is {@link CommandManager.RegistrationEnvironment#ALL}.</p>
|
* <p>The default value is {@link Commands.CommandSelection#ALL}.</p>
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final CommandMeta.Key<CommandManager.RegistrationEnvironment> META_REGISTRATION_ENVIRONMENT = CommandMeta.Key.of(
|
public static final CommandMeta.Key<Commands.CommandSelection> META_REGISTRATION_ENVIRONMENT = CommandMeta.Key.of(
|
||||||
CommandManager.RegistrationEnvironment.class,
|
Commands.CommandSelection.class,
|
||||||
"cloud:registration-environment"
|
"cloud:registration-environment"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -82,9 +82,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 @NonNull FabricServerCommandManager<@NonNull ServerCommandSource> createNative(
|
public static @NonNull FabricServerCommandManager<@NonNull CommandSourceStack> createNative(
|
||||||
final @NonNull Function<@NonNull CommandTree<@NonNull ServerCommandSource>,
|
final @NonNull Function<@NonNull CommandTree<@NonNull CommandSourceStack>,
|
||||||
@NonNull CommandExecutionCoordinator<@NonNull ServerCommandSource>> execCoordinator
|
@NonNull CommandExecutionCoordinator<@NonNull CommandSourceStack>> execCoordinator
|
||||||
) {
|
) {
|
||||||
return new FabricServerCommandManager<>(execCoordinator, Function.identity(), Function.identity());
|
return new FabricServerCommandManager<>(execCoordinator, Function.identity(), Function.identity());
|
||||||
}
|
}
|
||||||
|
|
@ -100,29 +100,29 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
|
||||||
* use a synchronous execution coordinator. In most cases you will want to pick between
|
* use a synchronous execution coordinator. In most cases you will want to pick between
|
||||||
* {@link CommandExecutionCoordinator#simpleCoordinator()} and
|
* {@link CommandExecutionCoordinator#simpleCoordinator()} and
|
||||||
* {@link AsynchronousCommandExecutionCoordinator}
|
* {@link AsynchronousCommandExecutionCoordinator}
|
||||||
* @param commandSourceMapper Function that maps {@link ServerCommandSource} to the command sender type
|
* @param commandSourceMapper Function that maps {@link CommandSourceStack} to the command sender type
|
||||||
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link ServerCommandSource}
|
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link CommandSourceStack}
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public FabricServerCommandManager(
|
public FabricServerCommandManager(
|
||||||
final @NonNull Function<@NonNull CommandTree<@NonNull C>,
|
final @NonNull Function<@NonNull CommandTree<@NonNull C>,
|
||||||
@NonNull CommandExecutionCoordinator<@NonNull C>> commandExecutionCoordinator,
|
@NonNull CommandExecutionCoordinator<@NonNull C>> commandExecutionCoordinator,
|
||||||
final @NonNull Function<@NonNull ServerCommandSource, @NonNull C> commandSourceMapper,
|
final @NonNull Function<@NonNull CommandSourceStack, @NonNull C> commandSourceMapper,
|
||||||
final @NonNull Function<@NonNull C, @NonNull ServerCommandSource> backwardsCommandSourceMapper
|
final @NonNull Function<@NonNull C, @NonNull CommandSourceStack> backwardsCommandSourceMapper
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
commandExecutionCoordinator,
|
commandExecutionCoordinator,
|
||||||
commandSourceMapper,
|
commandSourceMapper,
|
||||||
backwardsCommandSourceMapper,
|
backwardsCommandSourceMapper,
|
||||||
new FabricCommandRegistrationHandler.Server<>(),
|
new FabricCommandRegistrationHandler.Server<>(),
|
||||||
() -> new ServerCommandSource(
|
() -> new CommandSourceStack(
|
||||||
CommandOutput.DUMMY,
|
CommandSource.NULL,
|
||||||
Vec3d.ZERO,
|
Vec3.ZERO,
|
||||||
Vec2f.ZERO,
|
Vec2.ZERO,
|
||||||
null,
|
null,
|
||||||
4,
|
4,
|
||||||
"",
|
"",
|
||||||
LiteralText.EMPTY,
|
TextComponent.EMPTY,
|
||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|
@ -199,8 +199,8 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) {
|
public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) {
|
||||||
final ServerCommandSource source = this.getBackwardsCommandSourceMapper().apply(sender);
|
final CommandSourceStack source = this.getBackwardsCommandSourceMapper().apply(sender);
|
||||||
return Permissions.check(source, permission, source.getMinecraftServer().getOpPermissionLevel());
|
return Permissions.check(source, permission, source.getServer().getOperatorUserPermissionLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.AngleArgumentType;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -40,7 +39,7 @@ import java.util.function.BiFunction;
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType.Angle> {
|
public final class AngleArgument<C> extends CommandArgument<C, net.minecraft.commands.arguments.AngleArgument.SingleAngle> {
|
||||||
|
|
||||||
AngleArgument(
|
AngleArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
|
|
@ -52,9 +51,9 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(AngleArgumentType.angle()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.AngleArgument.angle()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
AngleArgumentType.Angle.class,
|
net.minecraft.commands.arguments.AngleArgument.SingleAngle.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -119,10 +118,10 @@ public final class AngleArgument<C> extends CommandArgument<C, AngleArgumentType
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, AngleArgumentType.Angle, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, net.minecraft.commands.arguments.AngleArgument.SingleAngle, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(AngleArgumentType.Angle.class, name);
|
super(net.minecraft.commands.arguments.AngleArgument.SingleAngle.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import net.minecraft.command.argument.SwizzleArgumentType;
|
import net.minecraft.commands.arguments.coordinates.SwizzleArgument;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for a set of {@link net.minecraft.util.math.Direction.Axis axes}, described in Vanilla as a "swizzle".
|
* An argument for a set of {@link net.minecraft.core.Direction.Axis axes}, described in Vanilla as a "swizzle".
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
@ -59,7 +59,7 @@ public final class AxisArgument<C> extends CommandArgument<C, EnumSet<Direction.
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(SwizzleArgumentType.swizzle()),
|
new WrappedBrigadierParser<>(SwizzleArgument.swizzle()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
TYPE,
|
TYPE,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.NbtCompoundTagArgumentType;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
@ -53,7 +52,7 @@ public final class CompoundTagArgument<C> extends CommandArgument<C, CompoundTag
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(NbtCompoundTagArgumentType.nbtCompound()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.CompoundTagArgument.compoundTag()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
CompoundTag.class,
|
CompoundTag.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -35,12 +34,12 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument parsing an {@link net.minecraft.command.argument.EntityAnchorArgumentType.EntityAnchor}.
|
* An argument parsing an {@link net.minecraft.commands.arguments.EntityAnchorArgument.Anchor}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnchorArgumentType.EntityAnchor> {
|
public final class EntityAnchorArgument<C> extends CommandArgument<C, net.minecraft.commands.arguments.EntityAnchorArgument.Anchor> {
|
||||||
|
|
||||||
EntityAnchorArgument(
|
EntityAnchorArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
|
|
@ -52,9 +51,9 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(EntityAnchorArgumentType.entityAnchor()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.EntityAnchorArgument.anchor()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
EntityAnchorArgumentType.EntityAnchor.class,
|
net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -107,7 +106,7 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull EntityAnchorArgument<C> optional(
|
public static <C> @NonNull EntityAnchorArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final EntityAnchorArgumentType.@NonNull EntityAnchor defaultValue
|
final net.minecraft.commands.arguments.EntityAnchorArgument.@NonNull Anchor defaultValue
|
||||||
) {
|
) {
|
||||||
return EntityAnchorArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return EntityAnchorArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
@ -119,10 +118,10 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, EntityAnchorArgumentType.EntityAnchor, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, net.minecraft.commands.arguments.EntityAnchorArgument.Anchor, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(EntityAnchorArgumentType.EntityAnchor.class, name);
|
super(net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,7 +149,7 @@ public final class EntityAnchorArgument<C> extends CommandArgument<C, EntityAnch
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final EntityAnchorArgumentType.@NonNull EntityAnchor defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final net.minecraft.commands.arguments.EntityAnchorArgument.@NonNull Anchor defaultValue) {
|
||||||
return this.asOptionalWithDefault(defaultValue.name());
|
return this.asOptionalWithDefault(defaultValue.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,25 +36,24 @@ import cloud.commandframework.fabric.data.MultiplePlayerSelector;
|
||||||
import cloud.commandframework.fabric.data.SingleEntitySelector;
|
import cloud.commandframework.fabric.data.SingleEntitySelector;
|
||||||
import cloud.commandframework.fabric.data.SinglePlayerSelector;
|
import cloud.commandframework.fabric.data.SinglePlayerSelector;
|
||||||
import cloud.commandframework.fabric.internal.EntitySelectorAccess;
|
import cloud.commandframework.fabric.internal.EntitySelectorAccess;
|
||||||
import cloud.commandframework.fabric.mixin.MessageArgumentTypeMessageFormatAccess;
|
import cloud.commandframework.fabric.mixin.MessageArgumentMessageAccess;
|
||||||
import cloud.commandframework.fabric.mixin.MessageArgumentTypeMessageSelectorAccess;
|
import cloud.commandframework.fabric.mixin.MessageArgumentPartAccess;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.command.EntitySelector;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import net.minecraft.command.argument.BlockPosArgumentType;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.command.argument.ColumnPosArgumentType;
|
import net.minecraft.commands.arguments.MessageArgument;
|
||||||
import net.minecraft.command.argument.EntityArgumentType;
|
import net.minecraft.commands.arguments.TimeArgument;
|
||||||
import net.minecraft.command.argument.MessageArgumentType;
|
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
import net.minecraft.command.argument.PosArgument;
|
import net.minecraft.commands.arguments.coordinates.ColumnPosArgument;
|
||||||
import net.minecraft.command.argument.TimeArgumentType;
|
import net.minecraft.commands.arguments.coordinates.Vec2Argument;
|
||||||
import net.minecraft.command.argument.Vec2ArgumentType;
|
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
|
||||||
import net.minecraft.command.argument.Vec3ArgumentType;
|
import net.minecraft.commands.arguments.selector.EntitySelector;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -80,7 +79,7 @@ public final class FabricArgumentParsers {
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, MinecraftTime> time() {
|
public static <C> @NonNull ArgumentParser<C, MinecraftTime> time() {
|
||||||
return new WrappedBrigadierParser<C, Integer>(TimeArgumentType.time())
|
return new WrappedBrigadierParser<C, Integer>(TimeArgument.time())
|
||||||
.map((ctx, val) -> ArgumentParseResult.success(MinecraftTime.of(val)));
|
.map((ctx, val) -> ArgumentParseResult.success(MinecraftTime.of(val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +90,7 @@ public final class FabricArgumentParsers {
|
||||||
* @return a parser instance
|
* @return a parser instance
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, Coordinates.BlockCoordinates> blockPos() {
|
public static <C> @NonNull ArgumentParser<C, Coordinates.BlockCoordinates> blockPos() {
|
||||||
return new WrappedBrigadierParser<C, PosArgument>(BlockPosArgumentType.blockPos())
|
return new WrappedBrigadierParser<C, net.minecraft.commands.arguments.coordinates.Coordinates>(BlockPosArgument.blockPos())
|
||||||
.map(FabricArgumentParsers::mapToCoordinates);
|
.map(FabricArgumentParsers::mapToCoordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +101,7 @@ public final class FabricArgumentParsers {
|
||||||
* @return a parser instance
|
* @return a parser instance
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, Coordinates.ColumnCoordinates> columnPos() {
|
public static <C> @NonNull ArgumentParser<C, Coordinates.ColumnCoordinates> columnPos() {
|
||||||
return new WrappedBrigadierParser<C, PosArgument>(ColumnPosArgumentType.columnPos())
|
return new WrappedBrigadierParser<C, net.minecraft.commands.arguments.coordinates.Coordinates>(ColumnPosArgument.columnPos())
|
||||||
.map(FabricArgumentParsers::mapToCoordinates);
|
.map(FabricArgumentParsers::mapToCoordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,7 +114,7 @@ public final class FabricArgumentParsers {
|
||||||
* @return a parser instance
|
* @return a parser instance
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, Coordinates.CoordinatesXZ> vec2(final boolean centerIntegers) {
|
public static <C> @NonNull ArgumentParser<C, Coordinates.CoordinatesXZ> vec2(final boolean centerIntegers) {
|
||||||
return new WrappedBrigadierParser<C, PosArgument>(new Vec2ArgumentType(centerIntegers))
|
return new WrappedBrigadierParser<C, net.minecraft.commands.arguments.coordinates.Coordinates>(new Vec2Argument(centerIntegers))
|
||||||
.map(FabricArgumentParsers::mapToCoordinates);
|
.map(FabricArgumentParsers::mapToCoordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,14 +126,14 @@ public final class FabricArgumentParsers {
|
||||||
* @return a parser instance
|
* @return a parser instance
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, Coordinates> vec3(final boolean centerIntegers) {
|
public static <C> @NonNull ArgumentParser<C, Coordinates> vec3(final boolean centerIntegers) {
|
||||||
return new WrappedBrigadierParser<C, PosArgument>(Vec3ArgumentType.vec3(centerIntegers))
|
return new WrappedBrigadierParser<C, net.minecraft.commands.arguments.coordinates.Coordinates>(Vec3Argument.vec3(centerIntegers))
|
||||||
.map(FabricArgumentParsers::mapToCoordinates);
|
.map(FabricArgumentParsers::mapToCoordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static <C, O extends Coordinates> @NonNull ArgumentParseResult<@NonNull O> mapToCoordinates(
|
private static <C, O extends Coordinates> @NonNull ArgumentParseResult<@NonNull O> mapToCoordinates(
|
||||||
final @NonNull CommandContext<C> ctx,
|
final @NonNull CommandContext<C> ctx,
|
||||||
final @NonNull PosArgument posArgument
|
final net.minecraft.commands.arguments.coordinates.@NonNull Coordinates posArgument
|
||||||
) {
|
) {
|
||||||
return requireServerCommandSource(
|
return requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
@ -153,14 +152,14 @@ public final class FabricArgumentParsers {
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() {
|
public static <C> @NonNull ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() {
|
||||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.player())
|
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.player())
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new SinglePlayerSelectorImpl(
|
() -> ArgumentParseResult.success(new SinglePlayerSelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
entitySelector.getPlayer(serverCommandSource)
|
entitySelector.findSinglePlayer(serverCommandSource)
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
@ -174,14 +173,14 @@ public final class FabricArgumentParsers {
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() {
|
public static <C> @NonNull ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() {
|
||||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.players())
|
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.players())
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new MultiplePlayerSelectorImpl(
|
() -> ArgumentParseResult.success(new MultiplePlayerSelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
entitySelector.getPlayers(serverCommandSource)
|
entitySelector.findPlayers(serverCommandSource)
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
@ -195,14 +194,14 @@ public final class FabricArgumentParsers {
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, SingleEntitySelector> singleEntitySelector() {
|
public static <C> @NonNull ArgumentParser<C, SingleEntitySelector> singleEntitySelector() {
|
||||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entity())
|
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.entity())
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new SingleEntitySelectorImpl(
|
() -> ArgumentParseResult.success(new SingleEntitySelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
entitySelector.getEntity(serverCommandSource)
|
entitySelector.findSingleEntity(serverCommandSource)
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
@ -216,14 +215,14 @@ public final class FabricArgumentParsers {
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() {
|
public static <C> @NonNull ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() {
|
||||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entities())
|
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.entities())
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new MultipleEntitySelectorImpl(
|
() -> ArgumentParseResult.success(new MultipleEntitySelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
Collections.unmodifiableCollection(entitySelector.getEntities(serverCommandSource))
|
Collections.unmodifiableCollection(entitySelector.findEntities(serverCommandSource))
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
@ -237,7 +236,7 @@ public final class FabricArgumentParsers {
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ArgumentParser<C, Message> message() {
|
public static <C> @NonNull ArgumentParser<C, Message> message() {
|
||||||
return new WrappedBrigadierParser<C, MessageArgumentType.MessageFormat>(MessageArgumentType.message())
|
return new WrappedBrigadierParser<C, MessageArgument.Message>(MessageArgument.message())
|
||||||
.map((ctx, format) -> requireServerCommandSource(
|
.map((ctx, format) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
|
|
@ -273,44 +272,44 @@ public final class FabricArgumentParsers {
|
||||||
|
|
||||||
private static <C, O> @NonNull ArgumentParseResult<O> requireServerCommandSource(
|
private static <C, O> @NonNull ArgumentParseResult<O> requireServerCommandSource(
|
||||||
final @NonNull CommandContext<C> context,
|
final @NonNull CommandContext<C> context,
|
||||||
final @NonNull Function<ServerCommandSource, ArgumentParseResult<O>> resultFunction
|
final @NonNull Function<CommandSourceStack, ArgumentParseResult<O>> resultFunction
|
||||||
) {
|
) {
|
||||||
final CommandSource nativeSource = context.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
final SharedSuggestionProvider nativeSource = context.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
||||||
if (!(nativeSource instanceof ServerCommandSource)) {
|
if (!(nativeSource instanceof CommandSourceStack)) {
|
||||||
return ArgumentParseResult.failure(serverOnly());
|
return ArgumentParseResult.failure(serverOnly());
|
||||||
}
|
}
|
||||||
return resultFunction.apply((ServerCommandSource) nativeSource);
|
return resultFunction.apply((CommandSourceStack) nativeSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class MessageImpl implements Message {
|
static final class MessageImpl implements Message {
|
||||||
|
|
||||||
private final Collection<Entity> mentionedEntities;
|
private final Collection<Entity> mentionedEntities;
|
||||||
private final Text contents;
|
private final Component contents;
|
||||||
|
|
||||||
static MessageImpl from(
|
static MessageImpl from(
|
||||||
final @NonNull ServerCommandSource source,
|
final @NonNull CommandSourceStack source,
|
||||||
final MessageArgumentType.@NonNull MessageFormat message,
|
final MessageArgument.@NonNull Message message,
|
||||||
final boolean useSelectors
|
final boolean useSelectors
|
||||||
) throws CommandSyntaxException {
|
) throws CommandSyntaxException {
|
||||||
final Text contents = message.format(source, useSelectors);
|
final Component contents = message.toComponent(source, useSelectors);
|
||||||
final MessageArgumentType.MessageSelector[] selectors =
|
final MessageArgument.Part[] selectors =
|
||||||
((MessageArgumentTypeMessageFormatAccess) message).accessor$selectors();
|
((MessageArgumentMessageAccess) message).accessor$parts();
|
||||||
final Collection<Entity> entities;
|
final Collection<Entity> entities;
|
||||||
if (!useSelectors || selectors.length == 0) {
|
if (!useSelectors || selectors.length == 0) {
|
||||||
entities = Collections.emptySet();
|
entities = Collections.emptySet();
|
||||||
} else {
|
} else {
|
||||||
entities = new HashSet<>();
|
entities = new HashSet<>();
|
||||||
for (final MessageArgumentType.MessageSelector selector : selectors) {
|
for (final MessageArgument.Part selector : selectors) {
|
||||||
entities.addAll(((MessageArgumentTypeMessageSelectorAccess) selector)
|
entities.addAll(((MessageArgumentPartAccess) selector)
|
||||||
.accessor$selector()
|
.accessor$selector()
|
||||||
.getEntities(source));
|
.findEntities(source));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MessageImpl(entities, contents);
|
return new MessageImpl(entities, contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageImpl(final Collection<Entity> mentionedEntities, final Text contents) {
|
MessageImpl(final Collection<Entity> mentionedEntities, final Component contents) {
|
||||||
this.mentionedEntities = mentionedEntities;
|
this.mentionedEntities = mentionedEntities;
|
||||||
this.contents = contents;
|
this.contents = contents;
|
||||||
}
|
}
|
||||||
|
|
@ -321,7 +320,7 @@ public final class FabricArgumentParsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Text getContents() {
|
public @NonNull Component getContents() {
|
||||||
return this.contents;
|
return this.contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,17 +331,17 @@ public final class FabricArgumentParsers {
|
||||||
Coordinates.BlockCoordinates,
|
Coordinates.BlockCoordinates,
|
||||||
Coordinates.ColumnCoordinates {
|
Coordinates.ColumnCoordinates {
|
||||||
|
|
||||||
private final ServerCommandSource source;
|
private final CommandSourceStack source;
|
||||||
private final PosArgument posArgument;
|
private final net.minecraft.commands.arguments.coordinates.Coordinates posArgument;
|
||||||
|
|
||||||
CoordinatesImpl(final @NonNull ServerCommandSource source, final @NonNull PosArgument posArgument) {
|
CoordinatesImpl(final @NonNull CommandSourceStack source, final net.minecraft.commands.arguments.coordinates.@NonNull Coordinates posArgument) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.posArgument = posArgument;
|
this.posArgument = posArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Vec3d position() {
|
public @NonNull Vec3 position() {
|
||||||
return this.posArgument.toAbsolutePos(this.source);
|
return this.posArgument.getPosition(this.source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -366,7 +365,7 @@ public final class FabricArgumentParsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull PosArgument wrappedCoordinates() {
|
public net.minecraft.commands.arguments.coordinates.@NonNull Coordinates wrappedCoordinates() {
|
||||||
return this.posArgument;
|
return this.posArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -442,12 +441,12 @@ public final class FabricArgumentParsers {
|
||||||
|
|
||||||
private final String inputString;
|
private final String inputString;
|
||||||
private final EntitySelector entitySelector;
|
private final EntitySelector entitySelector;
|
||||||
private final ServerPlayerEntity selectedPlayer;
|
private final ServerPlayer selectedPlayer;
|
||||||
|
|
||||||
SinglePlayerSelectorImpl(
|
SinglePlayerSelectorImpl(
|
||||||
final @NonNull String inputString,
|
final @NonNull String inputString,
|
||||||
final @NonNull EntitySelector entitySelector,
|
final @NonNull EntitySelector entitySelector,
|
||||||
final @NonNull ServerPlayerEntity selectedPlayer
|
final @NonNull ServerPlayer selectedPlayer
|
||||||
) {
|
) {
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
this.entitySelector = entitySelector;
|
this.entitySelector = entitySelector;
|
||||||
|
|
@ -465,7 +464,7 @@ public final class FabricArgumentParsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ServerPlayerEntity getSingle() {
|
public @NonNull ServerPlayer getSingle() {
|
||||||
return this.selectedPlayer;
|
return this.selectedPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -475,12 +474,12 @@ public final class FabricArgumentParsers {
|
||||||
|
|
||||||
private final String inputString;
|
private final String inputString;
|
||||||
private final EntitySelector entitySelector;
|
private final EntitySelector entitySelector;
|
||||||
private final Collection<ServerPlayerEntity> selectedPlayers;
|
private final Collection<ServerPlayer> selectedPlayers;
|
||||||
|
|
||||||
MultiplePlayerSelectorImpl(
|
MultiplePlayerSelectorImpl(
|
||||||
final @NonNull String inputString,
|
final @NonNull String inputString,
|
||||||
final @NonNull EntitySelector entitySelector,
|
final @NonNull EntitySelector entitySelector,
|
||||||
final @NonNull Collection<ServerPlayerEntity> selectedPlayers
|
final @NonNull Collection<ServerPlayer> selectedPlayers
|
||||||
) {
|
) {
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
this.entitySelector = entitySelector;
|
this.entitySelector = entitySelector;
|
||||||
|
|
@ -498,7 +497,7 @@ public final class FabricArgumentParsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Collection<ServerPlayerEntity> get() {
|
public @NonNull Collection<ServerPlayer> get() {
|
||||||
return this.selectedPlayers;
|
return this.selectedPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.NumberRangeArgumentType;
|
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||||
import net.minecraft.predicate.NumberRange;
|
import net.minecraft.commands.arguments.RangeArgument;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -36,13 +36,13 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument parsing an unbounded {@link net.minecraft.predicate.NumberRange.FloatRange float range}, in the form
|
* An argument parsing an unbounded {@link net.minecraft.advancements.critereon.MinMaxBounds.Floats float range}, in the form
|
||||||
* {@code [min]..[max]}, where both lower and upper bounds are optional.
|
* {@code [min]..[max]}, where both lower and upper bounds are optional.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.FloatRange> {
|
public final class FloatRangeArgument<C> extends CommandArgument<C, MinMaxBounds.Floats> {
|
||||||
|
|
||||||
FloatRangeArgument(
|
FloatRangeArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
|
|
@ -54,9 +54,9 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(NumberRangeArgumentType.method_30918()),
|
new WrappedBrigadierParser<>(RangeArgument.floatRange()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
NumberRange.FloatRange.class,
|
MinMaxBounds.Floats.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -109,7 +109,7 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull FloatRangeArgument<C> optional(
|
public static <C> @NonNull FloatRangeArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final NumberRange.@NonNull FloatRange defaultValue
|
final MinMaxBounds.@NonNull Floats defaultValue
|
||||||
) {
|
) {
|
||||||
return FloatRangeArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return FloatRangeArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
@ -121,10 +121,10 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, NumberRange.FloatRange, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, MinMaxBounds.Floats, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(NumberRange.FloatRange.class, name);
|
super(MinMaxBounds.Floats.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -152,7 +152,7 @@ public final class FloatRangeArgument<C> extends CommandArgument<C, NumberRange.
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final NumberRange.@NonNull FloatRange defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final MinMaxBounds.@NonNull Floats defaultValue) {
|
||||||
final StringBuilder value = new StringBuilder(6);
|
final StringBuilder value = new StringBuilder(6);
|
||||||
if (defaultValue.getMin() != null) {
|
if (defaultValue.getMin() != null) {
|
||||||
value.append(defaultValue.getMin());
|
value.append(defaultValue.getMin());
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.NumberRangeArgumentType;
|
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||||
import net.minecraft.predicate.NumberRange;
|
import net.minecraft.commands.arguments.RangeArgument;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -36,13 +36,13 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument parsing an unbounded {@link net.minecraft.predicate.NumberRange.IntRange integer range}, in the form
|
* An argument parsing an unbounded {@link net.minecraft.advancements.critereon.MinMaxBounds.Ints integer range}, in the form
|
||||||
* {@code [min]..[max]}, where both lower and upper bounds are optional.
|
* {@code [min]..[max]}, where both lower and upper bounds are optional.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.IntRange> {
|
public final class IntRangeArgument<C> extends CommandArgument<C, MinMaxBounds.Ints> {
|
||||||
|
|
||||||
IntRangeArgument(
|
IntRangeArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
|
|
@ -54,9 +54,9 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(NumberRangeArgumentType.numberRange()),
|
new WrappedBrigadierParser<>(RangeArgument.intRange()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
NumberRange.IntRange.class,
|
MinMaxBounds.Ints.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -109,7 +109,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.@NonNull IntRange defaultValue
|
final MinMaxBounds.@NonNull Ints defaultValue
|
||||||
) {
|
) {
|
||||||
return IntRangeArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return IntRangeArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
@ -121,10 +121,10 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, NumberRange.IntRange, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, MinMaxBounds.Ints, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(NumberRange.IntRange.class, name);
|
super(MinMaxBounds.Ints.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -152,7 +152,7 @@ public final class IntRangeArgument<C> extends CommandArgument<C, NumberRange.In
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final NumberRange.@NonNull IntRange defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final MinMaxBounds.@NonNull Ints defaultValue) {
|
||||||
final StringBuilder value = new StringBuilder(6);
|
final StringBuilder value = new StringBuilder(6);
|
||||||
if (defaultValue.getMin() != null) {
|
if (defaultValue.getMin() != null) {
|
||||||
value.append(defaultValue.getMin());
|
value.append(defaultValue.getMin());
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,10 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.ItemStackArgument;
|
import net.minecraft.commands.arguments.item.ItemArgument;
|
||||||
import net.minecraft.command.argument.ItemStackArgumentType;
|
import net.minecraft.commands.arguments.item.ItemInput;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -38,14 +38,14 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument parsing an item identifier and optional extra NBT data into an {@link ItemStackArgument}.
|
* An argument parsing an item identifier and optional extra NBT data into an {@link ItemInput}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgument> {
|
public final class ItemInputArgument<C> extends CommandArgument<C, ItemInput> {
|
||||||
|
|
||||||
ItemDataArgument(
|
ItemInputArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull String defaultValue,
|
final @NonNull String defaultValue,
|
||||||
|
|
@ -55,9 +55,9 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(ItemStackArgumentType.itemStack()),
|
new WrappedBrigadierParser<>(ItemArgument.item()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
ItemStackArgument.class,
|
ItemInput.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -76,31 +76,31 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new required {@link ItemDataArgument}.
|
* Create a new required {@link ItemInputArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ItemDataArgument<C> of(final @NonNull String name) {
|
public static <C> @NonNull ItemInputArgument<C> of(final @NonNull String name) {
|
||||||
return ItemDataArgument.<C>builder(name).asRequired().build();
|
return ItemInputArgument.<C>builder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ItemDataArgument}.
|
* Create a new optional {@link ItemInputArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ItemDataArgument<C> optional(final @NonNull String name) {
|
public static <C> @NonNull ItemInputArgument<C> optional(final @NonNull String name) {
|
||||||
return ItemDataArgument.<C>builder(name).asOptional().build();
|
return ItemInputArgument.<C>builder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ItemDataArgument} with the specified default value.
|
* Create a new optional {@link ItemInputArgument} with the specified default value.
|
||||||
*
|
*
|
||||||
* @param name Argument name
|
* @param name Argument name
|
||||||
* @param defaultValue Default value
|
* @param defaultValue Default value
|
||||||
|
|
@ -108,31 +108,31 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ItemDataArgument<C> optional(final @NonNull String name, final @NonNull ItemStack defaultValue) {
|
public static <C> @NonNull ItemInputArgument<C> optional(final @NonNull String name, final @NonNull ItemStack defaultValue) {
|
||||||
return ItemDataArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return ItemInputArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link ItemDataArgument}.
|
* Builder for {@link ItemInputArgument}.
|
||||||
*
|
*
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, ItemStackArgument, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, ItemInput, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(ItemStackArgument.class, name);
|
super(ItemInput.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new {@link ItemDataArgument}.
|
* Build a new {@link ItemInputArgument}.
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ItemDataArgument<C> build() {
|
public @NonNull ItemInputArgument<C> build() {
|
||||||
return new ItemDataArgument<>(
|
return new ItemInputArgument<>(
|
||||||
this.isRequired(),
|
this.isRequired(),
|
||||||
this.getName(),
|
this.getName(),
|
||||||
this.getDefaultValue(),
|
this.getDefaultValue(),
|
||||||
|
|
@ -152,9 +152,9 @@ public final class ItemDataArgument<C> extends CommandArgument<C, ItemStackArgum
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ItemStack defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ItemStack defaultValue) {
|
||||||
final String serializedDefault;
|
final String serializedDefault;
|
||||||
if (defaultValue.hasTag()) {
|
if (defaultValue.hasTag()) {
|
||||||
serializedDefault = Registry.ITEM.getId(defaultValue.getItem()) + defaultValue.getTag().toString();
|
serializedDefault = Registry.ITEM.getKey(defaultValue.getItem()) + defaultValue.getTag().toString();
|
||||||
} else {
|
} else {
|
||||||
serializedDefault = Registry.ITEM.getId(defaultValue.getItem()).toString();
|
serializedDefault = Registry.ITEM.getKey(defaultValue.getItem()).toString();
|
||||||
}
|
}
|
||||||
return this.asOptionalWithDefault(serializedDefault);
|
return this.asOptionalWithDefault(serializedDefault);
|
||||||
}
|
}
|
||||||
|
|
@ -27,9 +27,8 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.MobEffectArgumentType;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.entity.effect.StatusEffect;
|
import net.minecraft.world.effect.MobEffect;
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -37,14 +36,14 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument parsing a status effect from the {@link net.minecraft.util.registry.Registry#STATUS_EFFECT status effect registry}.
|
* An argument parsing a status effect from the {@link net.minecraft.core.Registry#MOB_EFFECT status effect registry}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffect> {
|
public final class MobEffectArgument<C> extends CommandArgument<C, MobEffect> {
|
||||||
|
|
||||||
StatusEffectArgument(
|
MobEffectArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull String defaultValue,
|
final @NonNull String defaultValue,
|
||||||
|
|
@ -54,9 +53,9 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(MobEffectArgumentType.mobEffect()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.MobEffectArgument.effect()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
StatusEffect.class,
|
MobEffect.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -71,35 +70,35 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
|
public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
|
||||||
return new StatusEffectArgument.Builder<>(name);
|
return new MobEffectArgument.Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new required {@link StatusEffectArgument}.
|
* Create a new required {@link MobEffectArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull StatusEffectArgument<C> of(final @NonNull String name) {
|
public static <C> @NonNull MobEffectArgument<C> of(final @NonNull String name) {
|
||||||
return StatusEffectArgument.<C>builder(name).asRequired().build();
|
return MobEffectArgument.<C>builder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link StatusEffectArgument}.
|
* Create a new optional {@link MobEffectArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull StatusEffectArgument<C> optional(final @NonNull String name) {
|
public static <C> @NonNull MobEffectArgument<C> optional(final @NonNull String name) {
|
||||||
return StatusEffectArgument.<C>builder(name).asOptional().build();
|
return MobEffectArgument.<C>builder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link StatusEffectArgument} with the specified default value.
|
* Create a new optional {@link MobEffectArgument} with the specified default value.
|
||||||
*
|
*
|
||||||
* @param name Argument name
|
* @param name Argument name
|
||||||
* @param defaultValue Default value
|
* @param defaultValue Default value
|
||||||
|
|
@ -107,35 +106,35 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull StatusEffectArgument<C> optional(
|
public static <C> @NonNull MobEffectArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull StatusEffect defaultValue
|
final @NonNull MobEffect defaultValue
|
||||||
) {
|
) {
|
||||||
return StatusEffectArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return MobEffectArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link StatusEffectArgument}.
|
* Builder for {@link MobEffectArgument}.
|
||||||
*
|
*
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, StatusEffect, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, MobEffect, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(StatusEffect.class, name);
|
super(MobEffect.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new {@link StatusEffectArgument}.
|
* Build a new {@link MobEffectArgument}.
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NonNull StatusEffectArgument<C> build() {
|
public @NonNull MobEffectArgument<C> build() {
|
||||||
return new StatusEffectArgument<>(
|
return new MobEffectArgument<>(
|
||||||
this.isRequired(),
|
this.isRequired(),
|
||||||
this.getName(),
|
this.getName(),
|
||||||
this.getDefaultValue(),
|
this.getDefaultValue(),
|
||||||
|
|
@ -152,8 +151,8 @@ public final class StatusEffectArgument<C> extends CommandArgument<C, StatusEffe
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull StatusEffect defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull MobEffect defaultValue) {
|
||||||
return this.asOptionalWithDefault(Registry.STATUS_EFFECT.getId(defaultValue).toString());
|
return this.asOptionalWithDefault(Registry.MOB_EFFECT.getKey(defaultValue).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -27,8 +27,7 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.ColorArgumentType;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.util.Formatting;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -36,14 +35,14 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for named colors in the {@link Formatting} enum.
|
* An argument for named colors in the {@link ChatFormatting} enum.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
|
public final class NamedColorArgument<C> extends CommandArgument<C, ChatFormatting> {
|
||||||
|
|
||||||
ColorArgument(
|
NamedColorArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull String defaultValue,
|
final @NonNull String defaultValue,
|
||||||
|
|
@ -53,16 +52,16 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(ColorArgumentType.color()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.ColorArgument.color()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
Formatting.class,
|
ChatFormatting.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link Builder}.
|
* Create a new {@link NamedColorArgument.Builder}.
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the component
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
|
|
@ -74,67 +73,67 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new required {@link ColorArgument}.
|
* Create a new required {@link NamedColorArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created component
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ColorArgument<C> of(final @NonNull String name) {
|
public static <C> @NonNull NamedColorArgument<C> of(final @NonNull String name) {
|
||||||
return ColorArgument.<C>builder(name).asRequired().build();
|
return NamedColorArgument.<C>builder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ColorArgument}.
|
* Create a new optional {@link NamedColorArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created component
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ColorArgument<C> optional(final @NonNull String name) {
|
public static <C> @NonNull NamedColorArgument<C> optional(final @NonNull String name) {
|
||||||
return ColorArgument.<C>builder(name).asOptional().build();
|
return NamedColorArgument.<C>builder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ColorArgument} with the specified default value.
|
* Create a new optional {@link NamedColorArgument} with the specified default value.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param defaultColor Default colour, must be {@link Formatting#isColor() a color}
|
* @param defaultColor Default colour, must be {@link ChatFormatting#isColor() a color}
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created component
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ColorArgument<C> optional(
|
public static <C> @NonNull NamedColorArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull Formatting defaultColor
|
final @NonNull ChatFormatting defaultColor
|
||||||
) {
|
) {
|
||||||
return ColorArgument.<C>builder(name).asOptionalWithDefault(defaultColor).build();
|
return NamedColorArgument.<C>builder(name).asOptionalWithDefault(defaultColor).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link ColorArgument}.
|
* Builder for {@link NamedColorArgument}.
|
||||||
*
|
*
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends CommandArgument.TypedBuilder<C, Formatting, Builder<C>> {
|
public static final class Builder<C> extends CommandArgument.TypedBuilder<C, ChatFormatting, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(Formatting.class, name);
|
super(ChatFormatting.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new {@link ColorArgument}.
|
* Build a new {@link NamedColorArgument}.
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ColorArgument<C> build() {
|
public @NonNull NamedColorArgument<C> build() {
|
||||||
return new ColorArgument<>(
|
return new NamedColorArgument<>(
|
||||||
this.isRequired(),
|
this.isRequired(),
|
||||||
this.getName(),
|
this.getName(),
|
||||||
this.getDefaultValue(),
|
this.getDefaultValue(),
|
||||||
|
|
@ -146,12 +145,12 @@ public final class ColorArgument<C> extends CommandArgument<C, Formatting> {
|
||||||
/**
|
/**
|
||||||
* Sets the command argument to be optional, with the specified default value.
|
* Sets the command argument to be optional, with the specified default value.
|
||||||
*
|
*
|
||||||
* @param defaultColor default value, must be {@link Formatting#isColor() a color}
|
* @param defaultColor default value, must be {@link ChatFormatting#isColor() a color}
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Formatting defaultColor) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ChatFormatting defaultColor) {
|
||||||
if (!defaultColor.isColor()) {
|
if (!defaultColor.isColor()) {
|
||||||
throw new IllegalArgumentException("Only color types are allowed but " + defaultColor + " was provided");
|
throw new IllegalArgumentException("Only color types are allowed but " + defaultColor + " was provided");
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,6 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.NbtPathArgumentType;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -35,13 +34,13 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for {@link net.minecraft.command.argument.NbtPathArgumentType.NbtPath NBT paths} to locations within
|
* An argument for {@link net.minecraft.commands.arguments.NbtPathArgument.NbtPath NBT paths} to locations within
|
||||||
* {@link net.minecraft.nbt.Tag Tags}.
|
* {@link net.minecraft.nbt.Tag Tags}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgumentType.NbtPath> {
|
public final class NbtPathArgument<C> extends CommandArgument<C, net.minecraft.commands.arguments.NbtPathArgument.NbtPath> {
|
||||||
|
|
||||||
NbtPathArgument(
|
NbtPathArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
|
|
@ -53,9 +52,9 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(NbtPathArgumentType.nbtPath()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.NbtPathArgument.nbtPath()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
NbtPathArgumentType.NbtPath.class,
|
net.minecraft.commands.arguments.NbtPathArgument.NbtPath.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -108,7 +107,7 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull NbtPathArgument<C> optional(
|
public static <C> @NonNull NbtPathArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final NbtPathArgumentType.@NonNull NbtPath defaultTag
|
final net.minecraft.commands.arguments.NbtPathArgument.@NonNull NbtPath defaultTag
|
||||||
) {
|
) {
|
||||||
return NbtPathArgument.<C>builder(name).asOptionalWithDefault(defaultTag).build();
|
return NbtPathArgument.<C>builder(name).asOptionalWithDefault(defaultTag).build();
|
||||||
}
|
}
|
||||||
|
|
@ -120,10 +119,10 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, NbtPathArgumentType.NbtPath, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, net.minecraft.commands.arguments.NbtPathArgument.NbtPath, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(NbtPathArgumentType.NbtPath.class, name);
|
super(net.minecraft.commands.arguments.NbtPathArgument.NbtPath.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -151,7 +150,7 @@ public final class NbtPathArgument<C> extends CommandArgument<C, NbtPathArgument
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final NbtPathArgumentType.@NonNull NbtPath defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final net.minecraft.commands.arguments.NbtPathArgument.@NonNull NbtPath defaultValue) {
|
||||||
return this.asOptionalWithDefault(defaultValue.toString());
|
return this.asOptionalWithDefault(defaultValue.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.NbtTagArgumentType;
|
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
@ -53,7 +52,7 @@ public final class NbtTagArgument<C> extends CommandArgument<C, Tag> {
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(NbtTagArgumentType.nbtTag()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.NbtTagArgument.nbtTag()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
Tag.class,
|
Tag.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.ObjectiveCriteriaArgumentType;
|
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||||
import net.minecraft.scoreboard.ScoreboardCriterion;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -36,14 +35,14 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for a {@linkplain ScoreboardCriterion criterion} in a scoreboard.
|
* An argument for a {@linkplain ObjectiveCriteria criterion} in a scoreboard.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, ScoreboardCriterion> {
|
public final class ObjectiveCriteriaArgument<C> extends CommandArgument<C, ObjectiveCriteria> {
|
||||||
|
|
||||||
ScoreboardCriterionArgument(
|
ObjectiveCriteriaArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull String defaultValue,
|
final @NonNull String defaultValue,
|
||||||
|
|
@ -53,9 +52,9 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(ObjectiveCriteriaArgumentType.objectiveCriteria()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.ObjectiveCriteriaArgument.criteria()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
ScoreboardCriterion.class,
|
ObjectiveCriteria.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -74,31 +73,31 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new required {@link ScoreboardCriterionArgument}.
|
* Create a new required {@link ObjectiveCriteriaArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ScoreboardCriterionArgument<C> of(final @NonNull String name) {
|
public static <C> @NonNull ObjectiveCriteriaArgument<C> of(final @NonNull String name) {
|
||||||
return ScoreboardCriterionArgument.<C>builder(name).asRequired().build();
|
return ObjectiveCriteriaArgument.<C>builder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ScoreboardCriterionArgument}.
|
* Create a new optional {@link ObjectiveCriteriaArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ScoreboardCriterionArgument<C> optional(final @NonNull String name) {
|
public static <C> @NonNull ObjectiveCriteriaArgument<C> optional(final @NonNull String name) {
|
||||||
return ScoreboardCriterionArgument.<C>builder(name).asOptional().build();
|
return ObjectiveCriteriaArgument.<C>builder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ScoreboardCriterionArgument} with the specified default value.
|
* Create a new optional {@link ObjectiveCriteriaArgument} with the specified default value.
|
||||||
*
|
*
|
||||||
* @param name Argument name
|
* @param name Argument name
|
||||||
* @param defaultCriterion Default criterion
|
* @param defaultCriterion Default criterion
|
||||||
|
|
@ -106,35 +105,35 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ScoreboardCriterionArgument<C> optional(
|
public static <C> @NonNull ObjectiveCriteriaArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull ScoreboardCriterion defaultCriterion
|
final @NonNull ObjectiveCriteria defaultCriterion
|
||||||
) {
|
) {
|
||||||
return ScoreboardCriterionArgument.<C>builder(name).asOptionalWithDefault(defaultCriterion).build();
|
return ObjectiveCriteriaArgument.<C>builder(name).asOptionalWithDefault(defaultCriterion).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link ScoreboardCriterionArgument}.
|
* Builder for {@link ObjectiveCriteriaArgument}.
|
||||||
*
|
*
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, ScoreboardCriterion, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, ObjectiveCriteria, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(ScoreboardCriterion.class, name);
|
super(ObjectiveCriteria.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new {@link ScoreboardCriterionArgument}.
|
* Build a new {@link ObjectiveCriteriaArgument}.
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ScoreboardCriterionArgument<C> build() {
|
public @NonNull ObjectiveCriteriaArgument<C> build() {
|
||||||
return new ScoreboardCriterionArgument<>(
|
return new ObjectiveCriteriaArgument<>(
|
||||||
this.isRequired(),
|
this.isRequired(),
|
||||||
this.getName(),
|
this.getName(),
|
||||||
this.getDefaultValue(),
|
this.getDefaultValue(),
|
||||||
|
|
@ -151,7 +150,7 @@ public final class ScoreboardCriterionArgument<C> extends CommandArgument<C, Sco
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ScoreboardCriterion defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ObjectiveCriteria defaultValue) {
|
||||||
return this.asOptionalWithDefault(defaultValue.getName());
|
return this.asOptionalWithDefault(defaultValue.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,8 +27,7 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.ParticleArgumentType;
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
import net.minecraft.particle.ParticleEffect;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -36,14 +35,14 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for any {@link net.minecraft.particle.ParticleEffect}.
|
* An argument for any {@link net.minecraft.core.particles.ParticleOptions}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class ParticleEffectArgument<C> extends CommandArgument<C, ParticleEffect> {
|
public final class ParticleArgument<C> extends CommandArgument<C, ParticleOptions> {
|
||||||
|
|
||||||
ParticleEffectArgument(
|
ParticleArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull String defaultValue,
|
final @NonNull String defaultValue,
|
||||||
|
|
@ -53,9 +52,9 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(ParticleArgumentType.particle()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.ParticleArgument.particle()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
ParticleEffect.class,
|
ParticleOptions.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -74,31 +73,31 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new required {@link ParticleEffectArgument}.
|
* Create a new required {@link ParticleArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ParticleEffectArgument<C> of(final @NonNull String name) {
|
public static <C> @NonNull ParticleArgument<C> of(final @NonNull String name) {
|
||||||
return ParticleEffectArgument.<C>builder(name).asRequired().build();
|
return ParticleArgument.<C>builder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ParticleEffectArgument}.
|
* Create a new optional {@link ParticleArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ParticleEffectArgument<C> optional(final @NonNull String name) {
|
public static <C> @NonNull ParticleArgument<C> optional(final @NonNull String name) {
|
||||||
return ParticleEffectArgument.<C>builder(name).asOptional().build();
|
return ParticleArgument.<C>builder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link ParticleEffectArgument} with the specified default value.
|
* Create a new optional {@link ParticleArgument} with the specified default value.
|
||||||
*
|
*
|
||||||
* @param name Argument name
|
* @param name Argument name
|
||||||
* @param defaultValue Default particle effect value
|
* @param defaultValue Default particle effect value
|
||||||
|
|
@ -106,24 +105,24 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull ParticleEffectArgument<C> optional(
|
public static <C> @NonNull ParticleArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull ParticleEffect defaultValue
|
final @NonNull ParticleOptions defaultValue
|
||||||
) {
|
) {
|
||||||
return ParticleEffectArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return ParticleArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link ParticleEffectArgument}.
|
* Builder for {@link ParticleArgument}.
|
||||||
*
|
*
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, ParticleEffect, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, ParticleOptions, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(ParticleEffect.class, name);
|
super(ParticleOptions.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -133,8 +132,8 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ParticleEffectArgument<C> build() {
|
public @NonNull ParticleArgument<C> build() {
|
||||||
return new ParticleEffectArgument<>(
|
return new ParticleArgument<>(
|
||||||
this.isRequired(),
|
this.isRequired(),
|
||||||
this.getName(),
|
this.getName(),
|
||||||
this.getDefaultValue(),
|
this.getDefaultValue(),
|
||||||
|
|
@ -151,8 +150,8 @@ public final class ParticleEffectArgument<C> extends CommandArgument<C, Particle
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ParticleEffect defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ParticleOptions defaultValue) {
|
||||||
return this.asOptionalWithDefault(defaultValue.asString());
|
return this.asOptionalWithDefault(defaultValue.writeToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -36,10 +36,10 @@ import cloud.commandframework.fabric.FabricCommandContextKeys;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.util.registry.RegistryKey;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
RegistryEntryArgument(
|
RegistryEntryArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull RegistryKey<? extends Registry<V>> registry,
|
final @NonNull ResourceKey<? extends Registry<V>> registry,
|
||||||
final @NonNull String defaultValue,
|
final @NonNull String defaultValue,
|
||||||
final @NonNull TypeToken<V> valueType,
|
final @NonNull TypeToken<V> valueType,
|
||||||
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider,
|
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider,
|
||||||
|
|
@ -98,9 +98,9 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder(
|
public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull Class<V> type,
|
final @NonNull Class<V> type,
|
||||||
final @NonNull RegistryKey<? extends Registry<V>> registry
|
final @NonNull ResourceKey<? extends Registry<V>> registry
|
||||||
) {
|
) {
|
||||||
return new RegistryEntryArgument.Builder<>(registry, type, name);
|
return new Builder<>(registry, type, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -117,9 +117,9 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder(
|
public static <C, V> RegistryEntryArgument.@NonNull Builder<C, V> newBuilder(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull TypeToken<V> type,
|
final @NonNull TypeToken<V> type,
|
||||||
final @NonNull RegistryKey<? extends Registry<V>> registry
|
final @NonNull ResourceKey<? extends Registry<V>> registry
|
||||||
) {
|
) {
|
||||||
return new RegistryEntryArgument.Builder<>(registry, type, name);
|
return new Builder<>(registry, type, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -136,7 +136,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
public static <C, V> @NonNull RegistryEntryArgument<C, V> of(
|
public static <C, V> @NonNull RegistryEntryArgument<C, V> of(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull Class<V> type,
|
final @NonNull Class<V> type,
|
||||||
final @NonNull RegistryKey<? extends Registry<V>> registry
|
final @NonNull ResourceKey<? extends Registry<V>> registry
|
||||||
) {
|
) {
|
||||||
return RegistryEntryArgument.<C, V>newBuilder(name, type, registry).asRequired().build();
|
return RegistryEntryArgument.<C, V>newBuilder(name, type, registry).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +155,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
public static <C, V> @NonNull RegistryEntryArgument<C, V> optional(
|
public static <C, V> @NonNull RegistryEntryArgument<C, V> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull Class<V> type,
|
final @NonNull Class<V> type,
|
||||||
final @NonNull RegistryKey<? extends Registry<V>> registry
|
final @NonNull ResourceKey<? extends Registry<V>> registry
|
||||||
) {
|
) {
|
||||||
return RegistryEntryArgument.<C, V>newBuilder(name, type, registry).asOptional().build();
|
return RegistryEntryArgument.<C, V>newBuilder(name, type, registry).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
@ -175,8 +175,8 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
public static <C, V> @NonNull RegistryEntryArgument<C, V> optional(
|
public static <C, V> @NonNull RegistryEntryArgument<C, V> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull Class<V> type,
|
final @NonNull Class<V> type,
|
||||||
final @NonNull RegistryKey<? extends Registry<V>> registry,
|
final @NonNull ResourceKey<? extends Registry<V>> registry,
|
||||||
final @NonNull RegistryKey<V> defaultValue
|
final @NonNull ResourceKey<V> defaultValue
|
||||||
) {
|
) {
|
||||||
return RegistryEntryArgument.<C, V>newBuilder(name, type, registry)
|
return RegistryEntryArgument.<C, V>newBuilder(name, type, registry)
|
||||||
.asOptionalWithDefault(defaultValue)
|
.asOptionalWithDefault(defaultValue)
|
||||||
|
|
@ -192,7 +192,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
*/
|
*/
|
||||||
public static final class Parser<C, V> implements ArgumentParser<C, V> {
|
public static final class Parser<C, V> implements ArgumentParser<C, V> {
|
||||||
|
|
||||||
private final RegistryKey<? extends Registry<V>> registryIdent;
|
private final ResourceKey<? extends Registry<V>> registryIdent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link Parser}.
|
* Create a new {@link Parser}.
|
||||||
|
|
@ -200,7 +200,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
* @param registryIdent the registry identifier
|
* @param registryIdent the registry identifier
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public Parser(final RegistryKey<? extends Registry<V>> registryIdent) {
|
public Parser(final ResourceKey<? extends Registry<V>> registryIdent) {
|
||||||
this.registryIdent = requireNonNull(registryIdent, "registryIdent");
|
this.registryIdent = requireNonNull(registryIdent, "registryIdent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,9 +214,9 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
return ArgumentParseResult.failure(new NoInputProvidedException(RegistryEntryArgument.class, commandContext));
|
return ArgumentParseResult.failure(new NoInputProvidedException(RegistryEntryArgument.class, commandContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Identifier key;
|
final ResourceLocation key;
|
||||||
try {
|
try {
|
||||||
key = Identifier.fromCommandInput(new StringReader(possibleIdentifier));
|
key = ResourceLocation.read(new StringReader(possibleIdentifier));
|
||||||
} catch (final CommandSyntaxException ex) {
|
} catch (final CommandSyntaxException ex) {
|
||||||
return ArgumentParseResult.failure(ex);
|
return ArgumentParseResult.failure(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -237,12 +237,12 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Registry<V> getRegistry(final CommandContext<C> ctx) {
|
Registry<V> getRegistry(final CommandContext<C> ctx) {
|
||||||
final CommandSource reverseMapped = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
final SharedSuggestionProvider reverseMapped = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
||||||
// First try dynamic registries (for things loaded from data-packs)
|
// First try dynamic registries (for things loaded from data-packs)
|
||||||
Registry<V> registry = reverseMapped.getRegistryManager().getOptional(this.registryIdent).orElse(null);
|
Registry<V> registry = reverseMapped.registryAccess().registry(this.registryIdent).orElse(null);
|
||||||
if (registry == null) {
|
if (registry == null) {
|
||||||
// And then static registries
|
// And then static registries
|
||||||
registry = (Registry<V>) Registry.REGISTRIES.get(this.registryIdent.getValue());
|
registry = (Registry<V>) Registry.REGISTRY.get(this.registryIdent.location());
|
||||||
}
|
}
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
@ -252,9 +252,9 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull String input
|
final @NonNull String input
|
||||||
) {
|
) {
|
||||||
final Set<Identifier> ids = this.getRegistry(commandContext).getIds();
|
final Set<ResourceLocation> ids = this.getRegistry(commandContext).keySet();
|
||||||
final List<String> results = new ArrayList<>(ids.size());
|
final List<String> results = new ArrayList<>(ids.size());
|
||||||
for (final Identifier entry : ids) {
|
for (final ResourceLocation entry : ids) {
|
||||||
if (entry.getNamespace().equals(NAMESPACE_MINECRAFT)) {
|
if (entry.getNamespace().equals(NAMESPACE_MINECRAFT)) {
|
||||||
results.add(entry.getPath());
|
results.add(entry.getPath());
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +275,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
* @return the registry
|
* @return the registry
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public RegistryKey<? extends Registry<?>> getRegistry() {
|
public ResourceKey<? extends Registry<?>> getRegistry() {
|
||||||
return this.registryIdent;
|
return this.registryIdent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -290,10 +290,10 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C, V> extends CommandArgument.TypedBuilder<C, V, Builder<C, V>> {
|
public static final class Builder<C, V> extends CommandArgument.TypedBuilder<C, V, Builder<C, V>> {
|
||||||
|
|
||||||
private final RegistryKey<? extends Registry<V>> registryIdent;
|
private final ResourceKey<? extends Registry<V>> registryIdent;
|
||||||
|
|
||||||
Builder(
|
Builder(
|
||||||
final RegistryKey<? extends Registry<V>> key,
|
final ResourceKey<? extends Registry<V>> key,
|
||||||
final @NonNull Class<V> valueType,
|
final @NonNull Class<V> valueType,
|
||||||
final @NonNull String name
|
final @NonNull String name
|
||||||
) {
|
) {
|
||||||
|
|
@ -302,7 +302,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder(
|
Builder(
|
||||||
final RegistryKey<? extends Registry<V>> key,
|
final ResourceKey<? extends Registry<V>> key,
|
||||||
final @NonNull TypeToken<V> valueType,
|
final @NonNull TypeToken<V> valueType,
|
||||||
final @NonNull String name
|
final @NonNull String name
|
||||||
) {
|
) {
|
||||||
|
|
@ -331,8 +331,8 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C, V> asOptionalWithDefault(final @NonNull RegistryKey<V> defaultValue) {
|
public @NonNull Builder<C, V> asOptionalWithDefault(final @NonNull ResourceKey<V> defaultValue) {
|
||||||
return this.asOptionalWithDefault(defaultValue.getValue().toString());
|
return this.asOptionalWithDefault(defaultValue.location().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -348,8 +348,8 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
|
||||||
|
|
||||||
UnknownEntryException(
|
UnknownEntryException(
|
||||||
final CommandContext<?> context,
|
final CommandContext<?> context,
|
||||||
final Identifier key,
|
final ResourceLocation key,
|
||||||
final RegistryKey<? extends Registry<?>> registry
|
final ResourceKey<? extends Registry<?>> registry
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
RegistryEntryArgument.class,
|
RegistryEntryArgument.class,
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.IdentifierArgumentType;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -36,14 +35,14 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument parsing an {@link Identifier}, or "resource location".
|
* An argument parsing a {@link ResourceLocation}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class IdentifierArgument<C> extends CommandArgument<C, Identifier> {
|
public final class ResourceLocationArgument<C> extends CommandArgument<C, ResourceLocation> {
|
||||||
|
|
||||||
IdentifierArgument(
|
ResourceLocationArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull String defaultValue,
|
final @NonNull String defaultValue,
|
||||||
|
|
@ -53,9 +52,9 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(IdentifierArgumentType.identifier()),
|
new WrappedBrigadierParser<>(net.minecraft.commands.arguments.ResourceLocationArgument.id()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
Identifier.class,
|
ResourceLocation.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -74,31 +73,31 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new required {@link IdentifierArgument}.
|
* Create a new required {@link ResourceLocationArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull IdentifierArgument<C> of(final @NonNull String name) {
|
public static <C> @NonNull ResourceLocationArgument<C> of(final @NonNull String name) {
|
||||||
return IdentifierArgument.<C>builder(name).asRequired().build();
|
return ResourceLocationArgument.<C>builder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link IdentifierArgument}.
|
* Create a new optional {@link ResourceLocationArgument}.
|
||||||
*
|
*
|
||||||
* @param name Component name
|
* @param name Component name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull IdentifierArgument<C> optional(final @NonNull String name) {
|
public static <C> @NonNull ResourceLocationArgument<C> optional(final @NonNull String name) {
|
||||||
return IdentifierArgument.<C>builder(name).asOptional().build();
|
return ResourceLocationArgument.<C>builder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new optional {@link IdentifierArgument} with the specified default value.
|
* Create a new optional {@link ResourceLocationArgument} with the specified default value.
|
||||||
*
|
*
|
||||||
* @param name Argument name
|
* @param name Argument name
|
||||||
* @param defaultValue Default value
|
* @param defaultValue Default value
|
||||||
|
|
@ -106,35 +105,35 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull IdentifierArgument<C> optional(
|
public static <C> @NonNull ResourceLocationArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull Identifier defaultValue
|
final @NonNull ResourceLocation defaultValue
|
||||||
) {
|
) {
|
||||||
return IdentifierArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return ResourceLocationArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link IdentifierArgument}.
|
* Builder for {@link ResourceLocationArgument}.
|
||||||
*
|
*
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, Identifier, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, ResourceLocation, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(Identifier.class, name);
|
super(ResourceLocation.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new {@link IdentifierArgument}.
|
* Build a new {@link ResourceLocationArgument}.
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NonNull IdentifierArgument<C> build() {
|
public @NonNull ResourceLocationArgument<C> build() {
|
||||||
return new IdentifierArgument<>(
|
return new ResourceLocationArgument<>(
|
||||||
this.isRequired(),
|
this.isRequired(),
|
||||||
this.getName(),
|
this.getName(),
|
||||||
this.getDefaultValue(),
|
this.getDefaultValue(),
|
||||||
|
|
@ -151,7 +150,7 @@ public final class IdentifierArgument<C> extends CommandArgument<C, Identifier>
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Identifier defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull ResourceLocation defaultValue) {
|
||||||
return this.asOptionalWithDefault(defaultValue.toString());
|
return this.asOptionalWithDefault(defaultValue.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,8 +27,8 @@ import cloud.commandframework.ArgumentDescription;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import net.minecraft.command.argument.OperationArgumentType;
|
import net.minecraft.commands.arguments.OperationArgument;
|
||||||
import net.minecraft.command.argument.OperationArgumentType.Operation;
|
import net.minecraft.commands.arguments.OperationArgument.Operation;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ import java.util.function.BiFunction;
|
||||||
/**
|
/**
|
||||||
* An argument for selecting any of the logical operations in {@link Operation}.
|
* 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>
|
* <p>These operations can be used to compare scores on a {@link net.minecraft.world.scores.Scoreboard}.</p>
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
@ -55,7 +55,7 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
|
||||||
super(
|
super(
|
||||||
required,
|
required,
|
||||||
name,
|
name,
|
||||||
new WrappedBrigadierParser<>(OperationArgumentType.operation()),
|
new WrappedBrigadierParser<>(OperationArgument.operation()),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
Operation.class,
|
Operation.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.fabric.FabricCommandContextKeys;
|
import cloud.commandframework.fabric.FabricCommandContextKeys;
|
||||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
@ -49,12 +49,12 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
|
||||||
@NonNull final CommandContext<@NonNull C> commandContext,
|
@NonNull final CommandContext<@NonNull C> commandContext,
|
||||||
@NonNull final Queue<@NonNull String> inputQueue
|
@NonNull final Queue<@NonNull String> inputQueue
|
||||||
) {
|
) {
|
||||||
final CommandSource source = commandContext.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
final SharedSuggestionProvider source = commandContext.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
||||||
final ArgumentParseResult<I> intermediate = this.parseIntermediate(commandContext, inputQueue);
|
final ArgumentParseResult<I> intermediate = this.parseIntermediate(commandContext, inputQueue);
|
||||||
|
|
||||||
return intermediate.flatMapParsedValue(value -> {
|
return intermediate.flatMapParsedValue(value -> {
|
||||||
if (source instanceof ServerCommandSource) {
|
if (source instanceof CommandSourceStack) {
|
||||||
return this.resolveServer(commandContext, (ServerCommandSource) source, value);
|
return this.resolveServer(commandContext, (CommandSourceStack) source, value);
|
||||||
} else if (source instanceof FabricClientCommandSource) {
|
} else if (source instanceof FabricClientCommandSource) {
|
||||||
return this.resolveClient(commandContext, (FabricClientCommandSource) source, value);
|
return this.resolveClient(commandContext, (FabricClientCommandSource) source, value);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -94,7 +94,7 @@ abstract class SidedArgumentParser<C, I, R> implements ArgumentParser<C, R> {
|
||||||
*/
|
*/
|
||||||
protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveServer(
|
protected abstract @NonNull ArgumentParseResult<@NonNull R> resolveServer(
|
||||||
@NonNull CommandContext<@NonNull C> context,
|
@NonNull CommandContext<@NonNull C> context,
|
||||||
@NonNull ServerCommandSource source,
|
@NonNull CommandSourceStack source,
|
||||||
@NonNull I value
|
@NonNull I value
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ import cloud.commandframework.exceptions.parsing.ParserException;
|
||||||
import cloud.commandframework.fabric.FabricCaptionKeys;
|
import cloud.commandframework.fabric.FabricCaptionKeys;
|
||||||
import cloud.commandframework.fabric.FabricCommandContextKeys;
|
import cloud.commandframework.fabric.FabricCommandContextKeys;
|
||||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||||
import net.minecraft.scoreboard.Team;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -44,12 +44,12 @@ import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for parsing {@link Team Teams}.
|
* An argument for parsing {@link PlayerTeam Teams}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class TeamArgument<C> extends CommandArgument<C, Team> {
|
public final class TeamArgument<C> extends CommandArgument<C, PlayerTeam> {
|
||||||
|
|
||||||
TeamArgument(
|
TeamArgument(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
|
|
@ -63,7 +63,7 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
|
||||||
name,
|
name,
|
||||||
new TeamParser<>(),
|
new TeamParser<>(),
|
||||||
defaultValue,
|
defaultValue,
|
||||||
Team.class,
|
PlayerTeam.class,
|
||||||
suggestionsProvider,
|
suggestionsProvider,
|
||||||
defaultDescription
|
defaultDescription
|
||||||
);
|
);
|
||||||
|
|
@ -116,25 +116,25 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull TeamArgument<C> optional(
|
public static <C> @NonNull TeamArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final @NonNull Team defaultValue
|
final @NonNull PlayerTeam defaultValue
|
||||||
) {
|
) {
|
||||||
return TeamArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return TeamArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Argument parser for {@link Team Teams}.
|
* Argument parser for {@link PlayerTeam Teams}.
|
||||||
*
|
*
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class TeamParser<C> extends SidedArgumentParser<C, String, Team> {
|
public static final class TeamParser<C> extends SidedArgumentParser<C, String, PlayerTeam> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull List<@NonNull String> suggestions(
|
public @NonNull List<@NonNull String> suggestions(
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull String input
|
final @NonNull String input
|
||||||
) {
|
) {
|
||||||
return new ArrayList<>(commandContext.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE).getTeamNames());
|
return new ArrayList<>(commandContext.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE).getAllTeams());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -150,12 +150,12 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @NonNull ArgumentParseResult<Team> resolveClient(
|
protected @NonNull ArgumentParseResult<PlayerTeam> resolveClient(
|
||||||
final @NonNull CommandContext<C> context,
|
final @NonNull CommandContext<C> context,
|
||||||
final @NonNull FabricClientCommandSource source,
|
final @NonNull FabricClientCommandSource source,
|
||||||
final @NonNull String value
|
final @NonNull String value
|
||||||
) {
|
) {
|
||||||
final Team result = source.getClient().getNetworkHandler().getWorld().getScoreboard().getTeam(value);
|
final PlayerTeam result = source.getClient().getConnection().getLevel().getScoreboard().getPlayerTeam(value);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return ArgumentParseResult.failure(new UnknownTeamException(context, value));
|
return ArgumentParseResult.failure(new UnknownTeamException(context, value));
|
||||||
}
|
}
|
||||||
|
|
@ -163,12 +163,12 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @NonNull ArgumentParseResult<Team> resolveServer(
|
protected @NonNull ArgumentParseResult<PlayerTeam> resolveServer(
|
||||||
final @NonNull CommandContext<C> context,
|
final @NonNull CommandContext<C> context,
|
||||||
final @NonNull ServerCommandSource source,
|
final @NonNull CommandSourceStack source,
|
||||||
final @NonNull String value
|
final @NonNull String value
|
||||||
) {
|
) {
|
||||||
final Team result = source.getWorld().getScoreboard().getTeam(value);
|
final PlayerTeam result = source.getLevel().getScoreboard().getPlayerTeam(value);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return ArgumentParseResult.failure(new UnknownTeamException(context, value));
|
return ArgumentParseResult.failure(new UnknownTeamException(context, value));
|
||||||
}
|
}
|
||||||
|
|
@ -183,10 +183,10 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
|
||||||
* @param <C> sender type
|
* @param <C> sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C> extends TypedBuilder<C, Team, Builder<C>> {
|
public static final class Builder<C> extends TypedBuilder<C, PlayerTeam, Builder<C>> {
|
||||||
|
|
||||||
Builder(final @NonNull String name) {
|
Builder(final @NonNull String name) {
|
||||||
super(Team.class, name);
|
super(PlayerTeam.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -214,7 +214,7 @@ public final class TeamArgument<C> extends CommandArgument<C, Team> {
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Team defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull PlayerTeam defaultValue) {
|
||||||
return this.asOptionalWithDefault(defaultValue.getName());
|
return this.asOptionalWithDefault(defaultValue.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||||
import cloud.commandframework.fabric.data.Coordinates.BlockCoordinates;
|
import cloud.commandframework.fabric.data.Coordinates.BlockCoordinates;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||||
import cloud.commandframework.fabric.data.Coordinates.ColumnCoordinates;
|
import cloud.commandframework.fabric.data.Coordinates.ColumnCoordinates;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for selecting multiple {@link net.minecraft.entity.Entity entities} using an
|
* An argument for selecting multiple {@link net.minecraft.world.entity.Entity entities} using an
|
||||||
* {@link net.minecraft.command.EntitySelector}.
|
* {@link net.minecraft.commands.arguments.selector.EntitySelector}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for selecting multiple {@link net.minecraft.server.network.ServerPlayerEntity players} using an
|
* An argument for selecting multiple {@link net.minecraft.server.level.ServerPlayer players} using an
|
||||||
* {@link net.minecraft.command.EntitySelector}.
|
* {@link net.minecraft.commands.arguments.selector.EntitySelector}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for selecting a single {@link net.minecraft.entity.Entity entity} using an
|
* An argument for selecting a single {@link net.minecraft.world.entity.Entity entity} using an
|
||||||
* {@link net.minecraft.command.EntitySelector}.
|
* {@link net.minecraft.commands.arguments.selector.EntitySelector}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for selecting a single {@link net.minecraft.server.network.ServerPlayerEntity player} using an
|
* An argument for selecting a single {@link net.minecraft.server.level.ServerPlayer player} using an
|
||||||
* {@link net.minecraft.command.EntitySelector}.
|
* {@link net.minecraft.commands.arguments.selector.EntitySelector}.
|
||||||
*
|
*
|
||||||
* @param <C> the sender type
|
* @param <C> the sender type
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||||
import cloud.commandframework.fabric.data.Coordinates;
|
import cloud.commandframework.fabric.data.Coordinates;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ public final class Vec2dArgument<C> extends CommandArgument<C, Coordinates.Coord
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull Vec2dArgument<C> optional(final @NonNull String name, final @NonNull Vec3d defaultValue) {
|
public static <C> @NonNull Vec2dArgument<C> optional(final @NonNull String name, final @NonNull Vec3 defaultValue) {
|
||||||
return Vec2dArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return Vec2dArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ public final class Vec2dArgument<C> extends CommandArgument<C, Coordinates.Coord
|
||||||
public static <C> @NonNull Vec2dArgument<C> optional(
|
public static <C> @NonNull Vec2dArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final boolean centerIntegers,
|
final boolean centerIntegers,
|
||||||
final @NonNull Vec3d defaultValue
|
final @NonNull Vec3 defaultValue
|
||||||
) {
|
) {
|
||||||
return Vec2dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptionalWithDefault(defaultValue).build();
|
return Vec2dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
@ -212,7 +212,7 @@ public final class Vec2dArgument<C> extends CommandArgument<C, Coordinates.Coord
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Vec3d defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Vec3 defaultValue) {
|
||||||
return this.asOptionalWithDefault(String.format(
|
return this.asOptionalWithDefault(String.format(
|
||||||
"%.10f %.10f",
|
"%.10f %.10f",
|
||||||
defaultValue.x,
|
defaultValue.x,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||||
import cloud.commandframework.fabric.data.Coordinates;
|
import cloud.commandframework.fabric.data.Coordinates;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ public final class Vec3dArgument<C> extends CommandArgument<C, Coordinates> {
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public static <C> @NonNull Vec3dArgument<C> optional(final @NonNull String name, final @NonNull Vec3d defaultValue) {
|
public static <C> @NonNull Vec3dArgument<C> optional(final @NonNull String name, final @NonNull Vec3 defaultValue) {
|
||||||
return Vec3dArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
return Vec3dArgument.<C>builder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ public final class Vec3dArgument<C> extends CommandArgument<C, Coordinates> {
|
||||||
public static <C> @NonNull Vec3dArgument<C> optional(
|
public static <C> @NonNull Vec3dArgument<C> optional(
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
final boolean centerIntegers,
|
final boolean centerIntegers,
|
||||||
final @NonNull Vec3d defaultValue
|
final @NonNull Vec3 defaultValue
|
||||||
) {
|
) {
|
||||||
return Vec3dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptionalWithDefault(defaultValue).build();
|
return Vec3dArgument.<C>builder(name).centerIntegers(centerIntegers).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
@ -212,7 +212,7 @@ public final class Vec3dArgument<C> extends CommandArgument<C, Coordinates> {
|
||||||
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
* @see CommandArgument.Builder#asOptionalWithDefault(String)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Vec3d defaultValue) {
|
public @NonNull Builder<C> asOptionalWithDefault(final @NonNull Vec3 defaultValue) {
|
||||||
return this.asOptionalWithDefault(String.format(
|
return this.asOptionalWithDefault(String.format(
|
||||||
"%.10f %.10f %.10f",
|
"%.10f %.10f %.10f",
|
||||||
defaultValue.x,
|
defaultValue.x,
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,15 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.command.argument.BlockPosArgumentType;
|
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
import net.minecraft.command.argument.ColumnPosArgumentType;
|
import net.minecraft.commands.arguments.coordinates.ColumnPosArgument;
|
||||||
import net.minecraft.command.argument.PosArgument;
|
import net.minecraft.commands.arguments.coordinates.Vec2Argument;
|
||||||
import net.minecraft.command.argument.Vec2ArgumentType;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link PosArgument} wrapper for easier use with cloud commands.
|
* A {@link net.minecraft.commands.arguments.coordinates.Coordinates} wrapper for easier use with cloud commands.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -44,7 +43,7 @@ public interface Coordinates {
|
||||||
* @return position
|
* @return position
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@NonNull Vec3d position();
|
@NonNull Vec3 position();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve a block position from the parsed coordinates.
|
* Resolve a block position from the parsed coordinates.
|
||||||
|
|
@ -84,10 +83,10 @@ public interface Coordinates {
|
||||||
* @return the base coordinates
|
* @return the base coordinates
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@NonNull PosArgument wrappedCoordinates();
|
net.minecraft.commands.arguments.coordinates.@NonNull Coordinates wrappedCoordinates();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized version of {@link Coordinates} for representing the result of the vanilla {@link Vec2ArgumentType},
|
* A specialized version of {@link Coordinates} for representing the result of the vanilla {@link Vec2Argument},
|
||||||
* which accepts two doubles for the x and z coordinate, always defaulting to 0 for the y coordinate.
|
* which accepts two doubles for the x and z coordinate, always defaulting to 0 for the y coordinate.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
|
@ -97,7 +96,7 @@ public interface Coordinates {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized version of {@link Coordinates} for representing the result of the vanilla {@link BlockPosArgumentType}.
|
* A specialized version of {@link Coordinates} for representing the result of the vanilla {@link BlockPosArgument}.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -106,7 +105,7 @@ public interface Coordinates {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized version of {@link Coordinates} for representing the result of the vanilla {@link ColumnPosArgumentType}.
|
* A specialized version of {@link Coordinates} for representing the result of the vanilla {@link ColumnPosArgument}.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.world.entity.Entity;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -50,6 +50,6 @@ public interface Message {
|
||||||
* @return the parsed text
|
* @return the parsed text
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@NonNull Text getContents();
|
@NonNull Component getContents();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for multiple entities.
|
* A selector for multiple entities.
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for multiple players.
|
* A selector for multiple players.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public interface MultiplePlayerSelector extends Selector<ServerPlayerEntity> {
|
public interface MultiplePlayerSelector extends Selector<ServerPlayer> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.command.EntitySelector;
|
import net.minecraft.commands.arguments.selector.EntitySelector;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for a single entity.
|
* A selector for a single entity.
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for a single player.
|
* A selector for a single player.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public interface SinglePlayerSelector extends Selector.Single<ServerPlayerEntity> {
|
public interface SinglePlayerSelector extends Selector.Single<ServerPlayer> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,16 +25,16 @@ package cloud.commandframework.fabric.mixin;
|
||||||
|
|
||||||
import cloud.commandframework.fabric.internal.CloudStringReader;
|
import cloud.commandframework.fabric.internal.CloudStringReader;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.commands.Commands;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
@Mixin(CommandManager.class)
|
@Mixin(Commands.class)
|
||||||
public class CommandManagerMixin {
|
public class CommandsMixin {
|
||||||
|
|
||||||
/* Use our StringReader. This is technically optional, but it's nicer to avoid re-wrapping the object every time */
|
/* Use our StringReader. This is technically optional, but it's nicer to avoid re-wrapping the object every time */
|
||||||
@Redirect(method = "execute", at = @At(value = "NEW", target = "com/mojang/brigadier/StringReader", remap = false), require = 0)
|
@Redirect(method = "performCommand", at = @At(value = "NEW", target = "com/mojang/brigadier/StringReader", remap = false), require = 0)
|
||||||
private StringReader cloud$newStringReader(final String arguments) {
|
private StringReader cloud$newStringReader(final String arguments) {
|
||||||
return new CloudStringReader(arguments);
|
return new CloudStringReader(arguments);
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
package cloud.commandframework.fabric.mixin;
|
package cloud.commandframework.fabric.mixin;
|
||||||
|
|
||||||
import cloud.commandframework.fabric.internal.EntitySelectorAccess;
|
import cloud.commandframework.fabric.internal.EntitySelectorAccess;
|
||||||
import net.minecraft.command.EntitySelector;
|
import net.minecraft.commands.arguments.selector.EntitySelector;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.spongepowered.asm.mixin.Implements;
|
import org.spongepowered.asm.mixin.Implements;
|
||||||
import org.spongepowered.asm.mixin.Interface;
|
import org.spongepowered.asm.mixin.Interface;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ package cloud.commandframework.fabric.mixin;
|
||||||
|
|
||||||
import cloud.commandframework.fabric.internal.EntitySelectorAccess;
|
import cloud.commandframework.fabric.internal.EntitySelectorAccess;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import net.minecraft.command.EntitySelector;
|
import net.minecraft.commands.arguments.selector.EntitySelector;
|
||||||
import net.minecraft.command.EntitySelectorReader;
|
import net.minecraft.commands.arguments.selector.EntitySelectorParser;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
@ -35,20 +35,20 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(EntitySelectorReader.class)
|
@Mixin(EntitySelectorParser.class)
|
||||||
abstract class EntitySelectorReaderMixin {
|
abstract class EntitySelectorParserMixin {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
private int startCursor;
|
private int startPosition;
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
@Final
|
@Final
|
||||||
private StringReader reader;
|
private StringReader reader;
|
||||||
|
|
||||||
@Inject(method = "read", at = @At("RETURN"))
|
@Inject(method = "parse", at = @At("RETURN"))
|
||||||
public void setInputString(final @NonNull CallbackInfoReturnable<EntitySelector> cir) {
|
public void setInputString(final @NonNull CallbackInfoReturnable<EntitySelector> cir) {
|
||||||
final EntitySelector selector = cir.getReturnValue();
|
final EntitySelector selector = cir.getReturnValue();
|
||||||
final String inputString = this.reader.getString().substring(this.startCursor, this.reader.getCursor());
|
final String inputString = this.reader.getString().substring(this.startPosition, this.reader.getCursor());
|
||||||
((EntitySelectorAccess) selector).inputString(inputString);
|
((EntitySelectorAccess) selector).inputString(inputString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,13 +23,11 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.mixin;
|
package cloud.commandframework.fabric.mixin;
|
||||||
|
|
||||||
import net.minecraft.command.argument.MessageArgumentType;
|
import net.minecraft.commands.arguments.MessageArgument;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
@Mixin(MessageArgumentType.MessageFormat.class)
|
@Mixin(MessageArgument.Message.class)
|
||||||
public interface MessageArgumentTypeMessageFormatAccess {
|
public interface MessageArgumentMessageAccess {
|
||||||
|
@Accessor("parts") MessageArgument.Part[] accessor$parts();
|
||||||
@Accessor("selectors") MessageArgumentType.MessageSelector[] accessor$selectors();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -23,12 +23,12 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.mixin;
|
package cloud.commandframework.fabric.mixin;
|
||||||
|
|
||||||
import net.minecraft.command.EntitySelector;
|
import net.minecraft.commands.arguments.MessageArgument;
|
||||||
import net.minecraft.command.argument.MessageArgumentType;
|
import net.minecraft.commands.arguments.selector.EntitySelector;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
@Mixin(MessageArgumentType.MessageSelector.class)
|
@Mixin(MessageArgument.Part.class)
|
||||||
public interface MessageArgumentTypeMessageSelectorAccess {
|
public interface MessageArgumentPartAccess {
|
||||||
@Accessor("selector") EntitySelector accessor$selector();
|
@Accessor("selector") EntitySelector accessor$selector();
|
||||||
}
|
}
|
||||||
|
|
@ -4,11 +4,11 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"CloudStringReaderMixin",
|
"CloudStringReaderMixin",
|
||||||
"CommandManagerMixin",
|
"CommandsMixin",
|
||||||
"EntitySelectorMixin",
|
"EntitySelectorMixin",
|
||||||
"EntitySelectorReaderMixin",
|
"EntitySelectorParserMixin",
|
||||||
"MessageArgumentTypeMessageFormatAccess",
|
"MessageArgumentMessageAccess",
|
||||||
"MessageArgumentTypeMessageSelectorAccess"
|
"MessageArgumentPartAccess"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
|
||||||
|
|
@ -35,16 +35,16 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screen.SaveLevelScreen;
|
import net.minecraft.client.gui.screens.GenericDirtMessageScreen;
|
||||||
import net.minecraft.client.gui.screen.TitleScreen;
|
import net.minecraft.client.gui.screens.TitleScreen;
|
||||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||||
import net.minecraft.client.realms.gui.screen.RealmsBridgeScreen;
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.commands.synchronization.ArgumentTypes;
|
||||||
import net.minecraft.command.argument.ArgumentTypes;
|
import net.minecraft.network.chat.ClickEvent;
|
||||||
import net.minecraft.text.ClickEvent;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.realms.RealmsBridge;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
|
@ -69,23 +69,23 @@ public final class FabricClientExample implements ClientModInitializer {
|
||||||
"cloud-dump-" + Instant.now().toString().replace(':', '-') + ".json"
|
"cloud-dump-" + Instant.now().toString().replace(':', '-') + ".json"
|
||||||
);
|
);
|
||||||
ctx.getSender().sendFeedback(
|
ctx.getSender().sendFeedback(
|
||||||
new LiteralText("Dumping command output to ")
|
new TextComponent("Dumping command output to ")
|
||||||
.append(new LiteralText(target.toString())
|
.append(new TextComponent(target.toString())
|
||||||
.styled(s -> s.withClickEvent(new ClickEvent(
|
.withStyle(s -> s.withClickEvent(new ClickEvent(
|
||||||
ClickEvent.Action.OPEN_FILE,
|
ClickEvent.Action.OPEN_FILE,
|
||||||
target.toAbsolutePath().toString()
|
target.toAbsolutePath().toString()
|
||||||
))))
|
))))
|
||||||
);
|
);
|
||||||
|
|
||||||
try (BufferedWriter writer = Files.newBufferedWriter(target); JsonWriter json = new JsonWriter(writer)) {
|
try (BufferedWriter writer = Files.newBufferedWriter(target); JsonWriter json = new JsonWriter(writer)) {
|
||||||
final CommandDispatcher<CommandSource> dispatcher = MinecraftClient.getInstance()
|
final CommandDispatcher<SharedSuggestionProvider> dispatcher = Minecraft.getInstance()
|
||||||
.getNetworkHandler()
|
.getConnection()
|
||||||
.getCommandDispatcher();
|
.getCommands();
|
||||||
final JsonObject object = ArgumentTypes.toJson(dispatcher, dispatcher.getRoot());
|
final JsonObject object = ArgumentTypes.serializeNodeToJson(dispatcher, dispatcher.getRoot());
|
||||||
json.setIndent(" ");
|
json.setIndent(" ");
|
||||||
Streams.write(object, json);
|
Streams.write(object, json);
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
ctx.getSender().sendError(new LiteralText(
|
ctx.getSender().sendError(new TextComponent(
|
||||||
"Unable to write file, see console for details: " + ex.getMessage()
|
"Unable to write file, see console for details: " + ex.getMessage()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -94,38 +94,38 @@ public final class FabricClientExample implements ClientModInitializer {
|
||||||
commandManager.command(base.literal("say")
|
commandManager.command(base.literal("say")
|
||||||
.argument(StringArgument.greedy("message"))
|
.argument(StringArgument.greedy("message"))
|
||||||
.handler(ctx -> ctx.getSender().sendFeedback(
|
.handler(ctx -> ctx.getSender().sendFeedback(
|
||||||
new LiteralText("Cloud client commands says: " + ctx.get("message"))
|
new TextComponent("Cloud client commands says: " + ctx.get("message"))
|
||||||
)));
|
)));
|
||||||
|
|
||||||
commandManager.command(base.literal("quit")
|
commandManager.command(base.literal("quit")
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
final MinecraftClient client = MinecraftClient.getInstance();
|
final Minecraft client = Minecraft.getInstance();
|
||||||
disconnectClient(client);
|
disconnectClient(client);
|
||||||
client.scheduleStop();
|
client.stop();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
commandManager.command(base.literal("disconnect")
|
commandManager.command(base.literal("disconnect")
|
||||||
.handler(ctx -> disconnectClient(MinecraftClient.getInstance())));
|
.handler(ctx -> disconnectClient(Minecraft.getInstance())));
|
||||||
|
|
||||||
commandManager.command(base.literal("requires_cheats")
|
commandManager.command(base.literal("requires_cheats")
|
||||||
.permission(FabricClientCommandManager.cheatsAllowed(false))
|
.permission(FabricClientCommandManager.cheatsAllowed(false))
|
||||||
.handler(ctx -> ctx.getSender().sendFeedback(new LiteralText("Cheats are enabled!"))));
|
.handler(ctx -> ctx.getSender().sendFeedback(new TextComponent("Cheats are enabled!"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void disconnectClient(final @NonNull MinecraftClient client) {
|
private static void disconnectClient(final @NonNull Minecraft client) {
|
||||||
boolean singlePlayer = client.isInSingleplayer();
|
boolean singlePlayer = client.hasSingleplayerServer();
|
||||||
client.world.disconnect();
|
client.level.disconnect();
|
||||||
if (singlePlayer) {
|
if (singlePlayer) {
|
||||||
client.disconnect(new SaveLevelScreen(new TranslatableText("menu.savingLevel")));
|
client.clearLevel(new GenericDirtMessageScreen(new TranslatableComponent("menu.savingLevel")));
|
||||||
} else {
|
} else {
|
||||||
client.disconnect();
|
client.clearLevel();
|
||||||
}
|
}
|
||||||
if (singlePlayer) {
|
if (singlePlayer) {
|
||||||
client.openScreen(new TitleScreen());
|
client.setScreen(new TitleScreen());
|
||||||
} else if (client.isConnectedToRealms()) {
|
} else if (client.isConnectedToRealms()) {
|
||||||
new RealmsBridgeScreen().switchToRealms(new TitleScreen());
|
new RealmsBridge().switchToRealms(new TitleScreen());
|
||||||
} else {
|
} else {
|
||||||
client.openScreen(new MultiplayerScreen(new TitleScreen()));
|
client.setScreen(new JoinMultiplayerScreen(new TitleScreen()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ import cloud.commandframework.arguments.standard.IntegerArgument;
|
||||||
import cloud.commandframework.arguments.standard.StringArgument;
|
import cloud.commandframework.arguments.standard.StringArgument;
|
||||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||||
import cloud.commandframework.fabric.argument.ColorArgument;
|
import cloud.commandframework.fabric.argument.ItemInputArgument;
|
||||||
import cloud.commandframework.fabric.argument.ItemDataArgument;
|
import cloud.commandframework.fabric.argument.NamedColorArgument;
|
||||||
import cloud.commandframework.fabric.argument.server.ColumnPosArgument;
|
import cloud.commandframework.fabric.argument.server.ColumnPosArgument;
|
||||||
import cloud.commandframework.fabric.argument.server.MultipleEntitySelectorArgument;
|
import cloud.commandframework.fabric.argument.server.MultipleEntitySelectorArgument;
|
||||||
import cloud.commandframework.fabric.argument.server.MultiplePlayerSelectorArgument;
|
import cloud.commandframework.fabric.argument.server.MultiplePlayerSelectorArgument;
|
||||||
|
|
@ -47,20 +47,20 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||||
import net.fabricmc.loader.api.metadata.Person;
|
import net.fabricmc.loader.api.metadata.Person;
|
||||||
import net.minecraft.command.argument.ItemStackArgument;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.network.MessageType;
|
import net.minecraft.Util;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.commands.arguments.item.ItemInput;
|
||||||
import net.minecraft.text.ClickEvent;
|
import net.minecraft.network.chat.ChatType;
|
||||||
import net.minecraft.text.HoverEvent;
|
import net.minecraft.network.chat.ClickEvent;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.network.chat.ComponentUtils;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.network.chat.HoverEvent;
|
||||||
import net.minecraft.text.TextColor;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.text.Texts;
|
import net.minecraft.network.chat.TextColor;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.math.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
@ -72,13 +72,13 @@ public final class FabricExample implements ModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
// Create a commands manager. We'll use native command source types for this.
|
// Create a commands manager. We'll use native command source types for this.
|
||||||
final FabricServerCommandManager<ServerCommandSource> manager =
|
final FabricServerCommandManager<CommandSourceStack> manager =
|
||||||
FabricServerCommandManager.createNative(CommandExecutionCoordinator.simpleCoordinator());
|
FabricServerCommandManager.createNative(CommandExecutionCoordinator.simpleCoordinator());
|
||||||
|
|
||||||
final Command.Builder<ServerCommandSource> base = manager.commandBuilder("cloudtest");
|
final Command.Builder<CommandSourceStack> base = manager.commandBuilder("cloudtest");
|
||||||
|
|
||||||
final CommandArgument<ServerCommandSource, String> name = StringArgument.of("name");
|
final CommandArgument<CommandSourceStack, String> name = StringArgument.of("name");
|
||||||
final CommandArgument<ServerCommandSource, Integer> hugs = IntegerArgument.<ServerCommandSource>newBuilder("hugs")
|
final CommandArgument<CommandSourceStack, Integer> hugs = IntegerArgument.<CommandSourceStack>newBuilder("hugs")
|
||||||
.asOptionalWithDefault("1")
|
.asOptionalWithDefault("1")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -87,38 +87,38 @@ public final class FabricExample implements ModInitializer {
|
||||||
.argument(name)
|
.argument(name)
|
||||||
.argument(hugs)
|
.argument(hugs)
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
ctx.getSender().sendFeedback(new LiteralText("Hello, ")
|
ctx.getSender().sendSuccess(new TextComponent("Hello, ")
|
||||||
.append(ctx.get(name))
|
.append(ctx.get(name))
|
||||||
.append(", hope you're doing well!")
|
.append(", hope you're doing well!")
|
||||||
.styled(style -> style.withColor(TextColor.fromRgb(0xAA22BB))), false);
|
.withStyle(style -> style.withColor(TextColor.fromRgb(0xAA22BB))), false);
|
||||||
|
|
||||||
ctx.getSender().sendFeedback(new LiteralText("Cloud would like to give you ")
|
ctx.getSender().sendSuccess(new TextComponent("Cloud would like to give you ")
|
||||||
.append(new LiteralText(String.valueOf(ctx.get(hugs)))
|
.append(new TextComponent(String.valueOf(ctx.get(hugs)))
|
||||||
.styled(style -> style.withColor(TextColor.fromRgb(0xFAB3DA))))
|
.withStyle(style -> style.withColor(TextColor.fromRgb(0xFAB3DA))))
|
||||||
.append(" hug(s) <3")
|
.append(" hug(s) <3")
|
||||||
.styled(style -> style.withBold(true)), false);
|
.withStyle(style -> style.withBold(true)), false);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
final CommandArgument<ServerCommandSource, MultiplePlayerSelector> playerSelector =
|
final CommandArgument<CommandSourceStack, MultiplePlayerSelector> playerSelector =
|
||||||
MultiplePlayerSelectorArgument.of("players");
|
MultiplePlayerSelectorArgument.of("players");
|
||||||
final CommandArgument<ServerCommandSource, Formatting> textColor = ColorArgument.of("color");
|
final CommandArgument<CommandSourceStack, ChatFormatting> textColor = NamedColorArgument.of("color");
|
||||||
|
|
||||||
manager.command(base.literal("wave")
|
manager.command(base.literal("wave")
|
||||||
.argument(playerSelector)
|
.argument(playerSelector)
|
||||||
.argument(textColor)
|
.argument(textColor)
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
final MultiplePlayerSelector selector = ctx.get(playerSelector);
|
final MultiplePlayerSelector selector = ctx.get(playerSelector);
|
||||||
final Collection<ServerPlayerEntity> selected = selector.get();
|
final Collection<ServerPlayer> selected = selector.get();
|
||||||
selected.forEach(selectedPlayer ->
|
selected.forEach(selectedPlayer ->
|
||||||
selectedPlayer.sendMessage(
|
selectedPlayer.sendMessage(
|
||||||
new LiteralText("Wave from ")
|
new TextComponent("Wave from ")
|
||||||
.styled(style -> style.withColor(ctx.get(textColor)))
|
.withStyle(style -> style.withColor(ctx.get(textColor)))
|
||||||
.append(ctx.getSender().getDisplayName()),
|
.append(ctx.getSender().getDisplayName()),
|
||||||
MessageType.SYSTEM,
|
ChatType.SYSTEM,
|
||||||
Util.NIL_UUID
|
Util.NIL_UUID
|
||||||
));
|
));
|
||||||
ctx.getSender().sendFeedback(
|
ctx.getSender().sendSuccess(
|
||||||
new LiteralText(String.format("Waved at %d players (%s)", selected.size(),
|
new TextComponent(String.format("Waved at %d players (%s)", selected.size(),
|
||||||
selector.inputString()
|
selector.inputString()
|
||||||
)),
|
)),
|
||||||
false
|
false
|
||||||
|
|
@ -128,15 +128,15 @@ public final class FabricExample implements ModInitializer {
|
||||||
manager.command(base.literal("give")
|
manager.command(base.literal("give")
|
||||||
.permission("cloud.give")
|
.permission("cloud.give")
|
||||||
.argument(MultiplePlayerSelectorArgument.of("targets"))
|
.argument(MultiplePlayerSelectorArgument.of("targets"))
|
||||||
.argument(ItemDataArgument.of("item"))
|
.argument(ItemInputArgument.of("item"))
|
||||||
.argument(IntegerArgument.<ServerCommandSource>newBuilder("amount")
|
.argument(IntegerArgument.<CommandSourceStack>newBuilder("amount")
|
||||||
.withMin(1)
|
.withMin(1)
|
||||||
.asOptionalWithDefault("1"))
|
.asOptionalWithDefault("1"))
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
final ItemStackArgument item = ctx.get("item");
|
final ItemInput item = ctx.get("item");
|
||||||
final MultiplePlayerSelector targets = ctx.get("targets");
|
final MultiplePlayerSelector targets = ctx.get("targets");
|
||||||
final int amount = ctx.get("amount");
|
final int amount = ctx.get("amount");
|
||||||
GiveCommandAccess.give(
|
GiveCommandAccess.giveItem(
|
||||||
ctx.getSender(),
|
ctx.getSender(),
|
||||||
item,
|
item,
|
||||||
targets.get(),
|
targets.get(),
|
||||||
|
|
@ -144,43 +144,45 @@ public final class FabricExample implements ModInitializer {
|
||||||
);
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
final Command.Builder<ServerCommandSource> mods = base.literal("mods").permission("cloud.mods");
|
final Command.Builder<CommandSourceStack> mods = base.literal("mods").permission("cloud.mods");
|
||||||
|
|
||||||
manager.command(mods.handler(ctx -> {
|
manager.command(mods.handler(ctx -> {
|
||||||
final List<ModMetadata> modList = FabricLoader.getInstance().getAllMods().stream()
|
final List<ModMetadata> modList = FabricLoader.getInstance().getAllMods().stream()
|
||||||
.map(ModContainer::getMetadata)
|
.map(ModContainer::getMetadata)
|
||||||
.sorted(Comparator.comparing(ModMetadata::getId))
|
.sorted(Comparator.comparing(ModMetadata::getId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
final LiteralText text = new LiteralText("");
|
final TextComponent text = new TextComponent("");
|
||||||
text.append(new LiteralText("Loaded Mods")
|
text.append(new TextComponent("Loaded Mods")
|
||||||
.styled(style -> style.withColor(Formatting.BLUE).withFormatting(Formatting.BOLD)));
|
.withStyle(style -> style.withColor(ChatFormatting.BLUE).applyFormat(ChatFormatting.BOLD)));
|
||||||
text.append(new LiteralText(String.format(" (%s)\n", modList.size()))
|
text.append(new TextComponent(String.format(" (%s)\n", modList.size()))
|
||||||
.styled(style -> style.withColor(Formatting.GRAY).withFormatting(Formatting.ITALIC)));
|
.withStyle(style -> style.withColor(ChatFormatting.GRAY).applyFormat(ChatFormatting.ITALIC)));
|
||||||
for (final ModMetadata mod : modList) {
|
for (final ModMetadata mod : modList) {
|
||||||
text.append(
|
text.append(
|
||||||
new LiteralText("")
|
new TextComponent("")
|
||||||
.styled(style -> style.withColor(Formatting.WHITE)
|
.withStyle(style -> style.withColor(ChatFormatting.WHITE)
|
||||||
.withClickEvent(new ClickEvent(
|
.withClickEvent(new ClickEvent(
|
||||||
ClickEvent.Action.SUGGEST_COMMAND,
|
ClickEvent.Action.SUGGEST_COMMAND,
|
||||||
String.format("/cloudtest mods %s", mod.getId())
|
String.format("/cloudtest mods %s", mod.getId())
|
||||||
))
|
))
|
||||||
.withHoverEvent(new HoverEvent(
|
.withHoverEvent(new HoverEvent(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
HoverEvent.Action.SHOW_TEXT,
|
||||||
new LiteralText("Click for more info")
|
new TextComponent("Click for more info")
|
||||||
)))
|
)))
|
||||||
.append(new LiteralText(mod.getName()).styled(style -> style.withColor(Formatting.GREEN)))
|
.append(new TextComponent(mod.getName()).withStyle(style -> style.withColor(ChatFormatting.GREEN)))
|
||||||
.append(new LiteralText(String.format(" (%s) ", mod.getId()))
|
.append(new TextComponent(String.format(" (%s) ", mod.getId()))
|
||||||
.styled(style -> style.withColor(Formatting.GRAY).withFormatting(Formatting.ITALIC)))
|
.withStyle(style -> style
|
||||||
.append(new LiteralText(String.format("v%s", mod.getVersion())))
|
.withColor(ChatFormatting.GRAY)
|
||||||
|
.applyFormat(ChatFormatting.ITALIC)))
|
||||||
|
.append(new TextComponent(String.format("v%s", mod.getVersion())))
|
||||||
);
|
);
|
||||||
if (modList.indexOf(mod) != modList.size() - 1) {
|
if (modList.indexOf(mod) != modList.size() - 1) {
|
||||||
text.append(new LiteralText(", ").styled(style -> style.withColor(Formatting.GRAY)));
|
text.append(new TextComponent(", ").withStyle(style -> style.withColor(ChatFormatting.GRAY)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.getSender().sendFeedback(text, false);
|
ctx.getSender().sendSuccess(text, false);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
final CommandArgument<ServerCommandSource, ModMetadata> modMetadata = manager.argumentBuilder(ModMetadata.class, "mod")
|
final CommandArgument<CommandSourceStack, ModMetadata> modMetadata = manager.argumentBuilder(ModMetadata.class, "mod")
|
||||||
.withSuggestionsProvider((ctx, input) -> FabricLoader.getInstance().getAllMods().stream()
|
.withSuggestionsProvider((ctx, input) -> FabricLoader.getInstance().getAllMods().stream()
|
||||||
.map(ModContainer::getMetadata)
|
.map(ModContainer::getMetadata)
|
||||||
.map(ModMetadata::getId)
|
.map(ModMetadata::getId)
|
||||||
|
|
@ -203,25 +205,25 @@ public final class FabricExample implements ModInitializer {
|
||||||
manager.command(mods.argument(modMetadata)
|
manager.command(mods.argument(modMetadata)
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
final ModMetadata meta = ctx.get(modMetadata);
|
final ModMetadata meta = ctx.get(modMetadata);
|
||||||
final MutableText text = new LiteralText("")
|
final MutableComponent text = new TextComponent("")
|
||||||
.append(new LiteralText(meta.getName())
|
.append(new TextComponent(meta.getName())
|
||||||
.styled(style -> style.withColor(Formatting.BLUE).withFormatting(Formatting.BOLD)))
|
.withStyle(style -> style.withColor(ChatFormatting.BLUE).applyFormat(ChatFormatting.BOLD)))
|
||||||
.append(new LiteralText("\n modid: " + meta.getId()))
|
.append(new TextComponent("\n modid: " + meta.getId()))
|
||||||
.append(new LiteralText("\n version: " + meta.getVersion()))
|
.append(new TextComponent("\n version: " + meta.getVersion()))
|
||||||
.append(new LiteralText("\n type: " + meta.getType()));
|
.append(new TextComponent("\n type: " + meta.getType()));
|
||||||
|
|
||||||
if (!meta.getDescription().isEmpty()) {
|
if (!meta.getDescription().isEmpty()) {
|
||||||
text.append(new LiteralText("\n description: " + meta.getDescription()));
|
text.append(new TextComponent("\n description: " + meta.getDescription()));
|
||||||
}
|
}
|
||||||
if (!meta.getAuthors().isEmpty()) {
|
if (!meta.getAuthors().isEmpty()) {
|
||||||
text.append(new LiteralText("\n authors: " + meta.getAuthors().stream()
|
text.append(new TextComponent("\n authors: " + meta.getAuthors().stream()
|
||||||
.map(Person::getName)
|
.map(Person::getName)
|
||||||
.collect(Collectors.joining(", "))));
|
.collect(Collectors.joining(", "))));
|
||||||
}
|
}
|
||||||
if (!meta.getLicense().isEmpty()) {
|
if (!meta.getLicense().isEmpty()) {
|
||||||
text.append(new LiteralText("\n license: " + String.join(", ", meta.getLicense())));
|
text.append(new TextComponent("\n license: " + String.join(", ", meta.getLicense())));
|
||||||
}
|
}
|
||||||
ctx.getSender().sendFeedback(
|
ctx.getSender().sendSuccess(
|
||||||
text,
|
text,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
@ -233,25 +235,25 @@ public final class FabricExample implements ModInitializer {
|
||||||
.argument(Vec3dArgument.of("location"))
|
.argument(Vec3dArgument.of("location"))
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
final MultipleEntitySelector selector = ctx.get("targets");
|
final MultipleEntitySelector selector = ctx.get("targets");
|
||||||
final Vec3d location = ctx.<Coordinates>get("location").position();
|
final Vec3 location = ctx.<Coordinates>get("location").position();
|
||||||
selector.get().forEach(target ->
|
selector.get().forEach(target ->
|
||||||
target.requestTeleport(location.getX(), location.getY(), location.getZ()));
|
target.teleportToWithTicket(location.x(), location.y(), location.z()));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
manager.command(base.literal("gotochunk")
|
manager.command(base.literal("gotochunk")
|
||||||
.permission("cloud.gotochunk")
|
.permission("cloud.gotochunk")
|
||||||
.argument(ColumnPosArgument.of("chunk_position"))
|
.argument(ColumnPosArgument.of("chunk_position"))
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
final ServerPlayerEntity player;
|
final ServerPlayer player;
|
||||||
try {
|
try {
|
||||||
player = ctx.getSender().getPlayer();
|
player = ctx.getSender().getPlayerOrException();
|
||||||
} catch (final CommandSyntaxException e) {
|
} catch (final CommandSyntaxException e) {
|
||||||
ctx.getSender().sendFeedback(Texts.toText(e.getRawMessage()), false);
|
ctx.getSender().sendSuccess(ComponentUtils.fromMessage(e.getRawMessage()), false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Vec3d vec = ctx.<ColumnCoordinates>get("chunk_position").position();
|
final Vec3 vec = ctx.<ColumnCoordinates>get("chunk_position").position();
|
||||||
final ChunkPos pos = new ChunkPos((int) vec.getX(), (int) vec.getZ());
|
final ChunkPos pos = new ChunkPos((int) vec.x(), (int) vec.z());
|
||||||
player.requestTeleport(pos.getStartX(), 128, pos.getStartZ());
|
player.teleportToWithTicket(pos.getMinBlockX(), 128, pos.getMinBlockZ());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@
|
||||||
package cloud.commandframework.fabric.testmod.mixin;
|
package cloud.commandframework.fabric.testmod.mixin;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
import net.minecraft.command.argument.ItemStackArgument;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.command.GiveCommand;
|
import net.minecraft.commands.arguments.item.ItemInput;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.commands.GiveCommand;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
|
@ -36,11 +36,11 @@ import java.util.Collection;
|
||||||
@Mixin(GiveCommand.class)
|
@Mixin(GiveCommand.class)
|
||||||
public interface GiveCommandAccess {
|
public interface GiveCommandAccess {
|
||||||
|
|
||||||
@Invoker("execute")
|
@Invoker("giveItem")
|
||||||
static int give(
|
static int giveItem(
|
||||||
final ServerCommandSource source,
|
final CommandSourceStack source,
|
||||||
final ItemStackArgument item,
|
final ItemInput item,
|
||||||
final Collection<ServerPlayerEntity> targets,
|
final Collection<ServerPlayer> targets,
|
||||||
final int count
|
final int count
|
||||||
) {
|
) {
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue