mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
Add argument for FinePosition to brig API (#11094)
This commit is contained in:
parent
5257a97fb3
commit
d34db05237
3 changed files with 76 additions and 5 deletions
|
@ -975,6 +975,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
|
+import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
|
||||||
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||||
|
+import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||||
|
@ -1056,7 +1057,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ * A selector argument that provides a list
|
+ * A selector argument that provides a list
|
||||||
+ * of player profiles.
|
+ * of player profiles.
|
||||||
+ *
|
+ *
|
||||||
+ * @return player profile arguments
|
+ * @return player profile argument
|
||||||
+ */
|
+ */
|
||||||
+ public static @NotNull ArgumentType<PlayerProfileListResolver> playerProfiles() {
|
+ public static @NotNull ArgumentType<PlayerProfileListResolver> playerProfiles() {
|
||||||
+ return provider().playerProfiles();
|
+ return provider().playerProfiles();
|
||||||
|
@ -1065,13 +1066,33 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ /**
|
+ /**
|
||||||
+ * A block position argument.
|
+ * A block position argument.
|
||||||
+ *
|
+ *
|
||||||
+ * @return argument
|
+ * @return block position argument
|
||||||
+ */
|
+ */
|
||||||
+ public static @NotNull ArgumentType<BlockPositionResolver> blockPosition() {
|
+ public static @NotNull ArgumentType<BlockPositionResolver> blockPosition() {
|
||||||
+ return provider().blockPosition();
|
+ return provider().blockPosition();
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ /**
|
+ /**
|
||||||
|
+ * A fine position argument.
|
||||||
|
+ *
|
||||||
|
+ * @return fine position argument
|
||||||
|
+ * @see #finePosition(boolean) to center whole numbers
|
||||||
|
+ */
|
||||||
|
+ public static @NotNull ArgumentType<FinePositionResolver> finePosition() {
|
||||||
|
+ return finePosition(false);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * A fine position argument.
|
||||||
|
+ *
|
||||||
|
+ * @param centerIntegers if whole numbers should be centered (+0.5)
|
||||||
|
+ * @return fine position argument
|
||||||
|
+ */
|
||||||
|
+ public static @NotNull ArgumentType<FinePositionResolver> finePosition(final boolean centerIntegers) {
|
||||||
|
+ return provider().finePosition(centerIntegers);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
+ * A blockstate argument which will provide rich parsing for specifying
|
+ * A blockstate argument which will provide rich parsing for specifying
|
||||||
+ * the specific block variant and then the block entity NBT if applicable.
|
+ * the specific block variant and then the block entity NBT if applicable.
|
||||||
+ *
|
+ *
|
||||||
|
@ -1530,6 +1551,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
|
+import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
|
||||||
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||||
|
+import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||||
|
@ -1580,6 +1602,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+
|
+
|
||||||
+ ArgumentType<BlockPositionResolver> blockPosition();
|
+ ArgumentType<BlockPositionResolver> blockPosition();
|
||||||
+
|
+
|
||||||
|
+ ArgumentType<FinePositionResolver> finePosition(boolean centerIntegers);
|
||||||
|
+
|
||||||
+ ArgumentType<BlockState> blockState();
|
+ ArgumentType<BlockState> blockState();
|
||||||
+
|
+
|
||||||
+ ArgumentType<ItemStack> itemStack();
|
+ ArgumentType<ItemStack> itemStack();
|
||||||
|
@ -1770,6 +1794,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+@ApiStatus.NonExtendable
|
+@ApiStatus.NonExtendable
|
||||||
+public interface BlockPositionResolver extends ArgumentResolver<BlockPosition> {
|
+public interface BlockPositionResolver extends ArgumentResolver<BlockPosition> {
|
||||||
+}
|
+}
|
||||||
|
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/FinePositionResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/FinePositionResolver.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/FinePositionResolver.java
|
||||||
|
@@ -0,0 +0,0 @@
|
||||||
|
+package io.papermc.paper.command.brigadier.argument.resolvers;
|
||||||
|
+
|
||||||
|
+import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
+import io.papermc.paper.math.FinePosition;
|
||||||
|
+import org.jetbrains.annotations.ApiStatus;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * An {@link ArgumentResolver} that's capable of resolving
|
||||||
|
+ * a fine position argument value using a {@link CommandSourceStack}.
|
||||||
|
+ *
|
||||||
|
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#finePosition()
|
||||||
|
+ * @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#finePosition(boolean)
|
||||||
|
+ */
|
||||||
|
+@ApiStatus.Experimental
|
||||||
|
+@ApiStatus.NonExtendable
|
||||||
|
+public interface FinePositionResolver extends ArgumentResolver<FinePosition> {
|
||||||
|
+}
|
||||||
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/PlayerProfileListResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/PlayerProfileListResolver.java
|
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/PlayerProfileListResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/PlayerProfileListResolver.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||||
|
|
|
@ -1094,15 +1094,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
+import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
||||||
+import io.papermc.paper.command.brigadier.argument.range.RangeProvider;
|
+import io.papermc.paper.command.brigadier.argument.range.RangeProvider;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||||
|
+import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
||||||
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||||
+import io.papermc.paper.entity.LookAnchor;
|
+import io.papermc.paper.entity.LookAnchor;
|
||||||
+import io.papermc.paper.math.Position;
|
|
||||||
+import io.papermc.paper.registry.PaperRegistries;
|
+import io.papermc.paper.registry.PaperRegistries;
|
||||||
+import io.papermc.paper.registry.RegistryAccess;
|
+import io.papermc.paper.registry.RegistryAccess;
|
||||||
+import io.papermc.paper.registry.RegistryKey;
|
+import io.papermc.paper.registry.RegistryKey;
|
||||||
+import io.papermc.paper.registry.TypedKey;
|
+import io.papermc.paper.registry.TypedKey;
|
||||||
|
+import io.papermc.paper.util.MCUtil;
|
||||||
+import java.util.Collection;
|
+import java.util.Collection;
|
||||||
+import java.util.Collections;
|
+import java.util.Collections;
|
||||||
+import java.util.List;
|
+import java.util.List;
|
||||||
|
@ -1137,6 +1138,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import net.minecraft.commands.arguments.UuidArgument;
|
+import net.minecraft.commands.arguments.UuidArgument;
|
||||||
+import net.minecraft.commands.arguments.blocks.BlockStateArgument;
|
+import net.minecraft.commands.arguments.blocks.BlockStateArgument;
|
||||||
+import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
+import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
|
+import net.minecraft.commands.arguments.coordinates.Vec3Argument;
|
||||||
+import net.minecraft.commands.arguments.item.ItemArgument;
|
+import net.minecraft.commands.arguments.item.ItemArgument;
|
||||||
+import net.minecraft.commands.arguments.item.ItemPredicateArgument;
|
+import net.minecraft.commands.arguments.item.ItemPredicateArgument;
|
||||||
+import net.minecraft.core.BlockPos;
|
+import net.minecraft.core.BlockPos;
|
||||||
|
@ -1146,6 +1148,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import net.minecraft.server.level.ServerLevel;
|
+import net.minecraft.server.level.ServerLevel;
|
||||||
+import net.minecraft.server.level.ServerPlayer;
|
+import net.minecraft.server.level.ServerPlayer;
|
||||||
+import net.minecraft.world.level.Level;
|
+import net.minecraft.world.level.Level;
|
||||||
|
+import net.minecraft.world.phys.Vec3;
|
||||||
+import org.bukkit.GameMode;
|
+import org.bukkit.GameMode;
|
||||||
+import org.bukkit.HeightMap;
|
+import org.bukkit.HeightMap;
|
||||||
+import org.bukkit.Keyed;
|
+import org.bukkit.Keyed;
|
||||||
|
@ -1217,7 +1220,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ return this.wrap(BlockPosArgument.blockPos(), (result) -> sourceStack -> {
|
+ return this.wrap(BlockPosArgument.blockPos(), (result) -> sourceStack -> {
|
||||||
+ final BlockPos pos = result.getBlockPos((CommandSourceStack) sourceStack);
|
+ final BlockPos pos = result.getBlockPos((CommandSourceStack) sourceStack);
|
||||||
+
|
+
|
||||||
+ return Position.block(pos.getX(), pos.getY(), pos.getZ());
|
+ return MCUtil.toPosition(pos);
|
||||||
|
+ });
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public ArgumentType<FinePositionResolver> finePosition(final boolean centerIntegers) {
|
||||||
|
+ return this.wrap(Vec3Argument.vec3(centerIntegers), (result) -> sourceStack -> {
|
||||||
|
+ final Vec3 vec3 = result.getPosition((CommandSourceStack) sourceStack);
|
||||||
|
+
|
||||||
|
+ return MCUtil.toPosition(vec3);
|
||||||
+ });
|
+ });
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
@ -1310,7 +1322,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ return this.wrap(DimensionArgument.dimension(), dimensionLocation -> {
|
+ return this.wrap(DimensionArgument.dimension(), dimensionLocation -> {
|
||||||
+ // based on DimensionArgument#getDimension
|
+ // based on DimensionArgument#getDimension
|
||||||
+ final ResourceKey<Level> resourceKey = ResourceKey.create(Registries.DIMENSION, dimensionLocation);
|
+ final ResourceKey<Level> resourceKey = ResourceKey.create(Registries.DIMENSION, dimensionLocation);
|
||||||
+ @Nullable final ServerLevel serverLevel = MinecraftServer.getServer().getLevel(resourceKey);
|
+ final @Nullable ServerLevel serverLevel = MinecraftServer.getServer().getLevel(resourceKey);
|
||||||
+ if (serverLevel == null) {
|
+ if (serverLevel == null) {
|
||||||
+ throw DimensionArgument.ERROR_INVALID_VALUE.create(dimensionLocation);
|
+ throw DimensionArgument.ERROR_INVALID_VALUE.create(dimensionLocation);
|
||||||
+ } else {
|
+ } else {
|
||||||
|
|
|
@ -7,6 +7,8 @@ import io.papermc.paper.command.brigadier.Commands;
|
||||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||||
import io.papermc.paper.command.brigadier.argument.RegistryArgumentExtractor;
|
import io.papermc.paper.command.brigadier.argument.RegistryArgumentExtractor;
|
||||||
import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
|
import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
|
||||||
|
import io.papermc.paper.math.FinePosition;
|
||||||
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||||
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
||||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||||
|
@ -59,6 +61,16 @@ public final class Registration {
|
||||||
})
|
})
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
|
commands.register(Commands.literal("fine-pos")
|
||||||
|
.then(
|
||||||
|
Commands.argument("pos", ArgumentTypes.finePosition(false))
|
||||||
|
.executes(ctx -> {
|
||||||
|
final FinePositionResolver position = ctx.getArgument("pos", FinePositionResolver.class);
|
||||||
|
ctx.getSource().getSender().sendPlainMessage("Position: " + position.resolve(ctx.getSource()));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
).build()
|
||||||
|
);
|
||||||
// ensure plugin commands override
|
// ensure plugin commands override
|
||||||
commands.register(Commands.literal("tag")
|
commands.register(Commands.literal("tag")
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
|
|
Loading…
Reference in a new issue