aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--patches/api/0468-Brigadier-based-command-API.patch59
-rw-r--r--patches/server/0972-Brigadier-based-command-API.patch22
-rw-r--r--test-plugin/src/main/java/io/papermc/testplugin/brigtests/Registration.java12
3 files changed, 82 insertions, 11 deletions
diff --git a/patches/api/0468-Brigadier-based-command-API.patch b/patches/api/0468-Brigadier-based-command-API.patch
index bd6921f6cc..7598f0c8b0 100644
--- a/patches/api/0468-Brigadier-based-command-API.patch
+++ b/patches/api/0468-Brigadier-based-command-API.patch
@@ -964,10 +964,10 @@ index 0000000000000000000000000000000000000000..2db12952461c92a64505d6646f6f49f8
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/ArgumentTypes.java b/src/main/java/io/papermc/paper/command/brigadier/argument/ArgumentTypes.java
new file mode 100644
-index 0000000000000000000000000000000000000000..1d5c599d1b9c8bf07720e651bdbe9dadb1335b45
+index 0000000000000000000000000000000000000000..f102176791e57d23a148ba79bfc949f4ef470c70
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/ArgumentTypes.java
-@@ -0,0 +1,349 @@
+@@ -0,0 +1,370 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.mojang.brigadier.arguments.ArgumentType;
@@ -975,6 +975,7 @@ index 0000000000000000000000000000000000000000..1d5c599d1b9c8bf07720e651bdbe9dad
+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.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.selector.EntitySelectorArgumentResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
@@ -1056,7 +1057,7 @@ index 0000000000000000000000000000000000000000..1d5c599d1b9c8bf07720e651bdbe9dad
+ * A selector argument that provides a list
+ * of player profiles.
+ *
-+ * @return player profile arguments
++ * @return player profile argument
+ */
+ public static @NotNull ArgumentType<PlayerProfileListResolver> playerProfiles() {
+ return provider().playerProfiles();
@@ -1065,13 +1066,33 @@ index 0000000000000000000000000000000000000000..1d5c599d1b9c8bf07720e651bdbe9dad
+ /**
+ * A block position argument.
+ *
-+ * @return argument
++ * @return block position argument
+ */
+ public static @NotNull ArgumentType<BlockPositionResolver> 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
+ * the specific block variant and then the block entity NBT if applicable.
+ *
@@ -1519,10 +1540,10 @@ index 0000000000000000000000000000000000000000..159b691e7a1a7066f3e706e80d75ca8f
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java
new file mode 100644
-index 0000000000000000000000000000000000000000..fbbbf324c002dddd868ba2fb56ddda92149ced3c
+index 0000000000000000000000000000000000000000..e8c1c0f781bfc852af4a0f01452566ae994dc285
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java
-@@ -0,0 +1,104 @@
+@@ -0,0 +1,107 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.mojang.brigadier.arguments.ArgumentType;
@@ -1530,6 +1551,7 @@ index 0000000000000000000000000000000000000000..fbbbf324c002dddd868ba2fb56ddda92
+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.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.selector.EntitySelectorArgumentResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
@@ -1580,6 +1602,8 @@ index 0000000000000000000000000000000000000000..fbbbf324c002dddd868ba2fb56ddda92
+
+ ArgumentType<BlockPositionResolver> blockPosition();
+
++ ArgumentType<FinePositionResolver> finePosition(boolean centerIntegers);
++
+ ArgumentType<BlockState> blockState();
+
+ ArgumentType<ItemStack> itemStack();
@@ -1770,6 +1794,29 @@ index 0000000000000000000000000000000000000000..908f40dbf3e52bdfc8577a8916884e9f
+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..e2fc26016b8d68fd0d69c8ca962f61fe65471b24
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/FinePositionResolver.java
+@@ -0,0 +1,17 @@
++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)
++ */
++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
new file mode 100644
index 0000000000000000000000000000000000000000..89024e67fd81a9cd8a9d1ef5bb78d1c8bcb4fcc5
diff --git a/patches/server/0972-Brigadier-based-command-API.patch b/patches/server/0972-Brigadier-based-command-API.patch
index f139f76f3a..d98a2a98c3 100644
--- a/patches/server/0972-Brigadier-based-command-API.patch
+++ b/patches/server/0972-Brigadier-based-command-API.patch
@@ -1071,10 +1071,10 @@ index 0000000000000000000000000000000000000000..72966584089d3fee9778f572727c9b7f
+}
diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProviderImpl.java b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProviderImpl.java
new file mode 100644
-index 0000000000000000000000000000000000000000..1b389cd0e77c24874b2a825608b612e3fc4f3dd6
+index 0000000000000000000000000000000000000000..38fb7d13abfcb55fe4a132b9b27e0c91f8c3d891
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProviderImpl.java
-@@ -0,0 +1,354 @@
+@@ -0,0 +1,366 @@
+package io.papermc.paper.command.brigadier.argument;
+
+import com.destroystokyo.paper.profile.CraftPlayerProfile;
@@ -1094,15 +1094,16 @@ index 0000000000000000000000000000000000000000..1b389cd0e77c24874b2a825608b612e3
+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.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.selector.EntitySelectorArgumentResolver;
+import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
+import io.papermc.paper.entity.LookAnchor;
-+import io.papermc.paper.math.Position;
+import io.papermc.paper.registry.PaperRegistries;
+import io.papermc.paper.registry.RegistryAccess;
+import io.papermc.paper.registry.RegistryKey;
+import io.papermc.paper.registry.TypedKey;
++import io.papermc.paper.util.MCUtil;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
@@ -1137,6 +1138,7 @@ index 0000000000000000000000000000000000000000..1b389cd0e77c24874b2a825608b612e3
+import net.minecraft.commands.arguments.UuidArgument;
+import net.minecraft.commands.arguments.blocks.BlockStateArgument;
+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.ItemPredicateArgument;
+import net.minecraft.core.BlockPos;
@@ -1146,6 +1148,7 @@ index 0000000000000000000000000000000000000000..1b389cd0e77c24874b2a825608b612e3
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.level.Level;
++import net.minecraft.world.phys.Vec3;
+import org.bukkit.GameMode;
+import org.bukkit.HeightMap;
+import org.bukkit.Keyed;
@@ -1217,7 +1220,16 @@ index 0000000000000000000000000000000000000000..1b389cd0e77c24874b2a825608b612e3
+ return this.wrap(BlockPosArgument.blockPos(), (result) -> 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..1b389cd0e77c24874b2a825608b612e3
+ return this.wrap(DimensionArgument.dimension(), dimensionLocation -> {
+ // based on DimensionArgument#getDimension
+ 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) {
+ throw DimensionArgument.ERROR_INVALID_VALUE.create(dimensionLocation);
+ } else {
diff --git a/test-plugin/src/main/java/io/papermc/testplugin/brigtests/Registration.java b/test-plugin/src/main/java/io/papermc/testplugin/brigtests/Registration.java
index 67b0ed983d..f67feda8fa 100644
--- a/test-plugin/src/main/java/io/papermc/testplugin/brigtests/Registration.java
+++ b/test-plugin/src/main/java/io/papermc/testplugin/brigtests/Registration.java
@@ -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.RegistryArgumentExtractor;
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.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
@@ -59,6 +61,16 @@ public final class Registration {
})
).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
commands.register(Commands.literal("tag")
.executes(ctx -> {