Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument for FinePosition to brig API #11094

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions patches/api/0468-Brigadier-based-command-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,18 @@ 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;
+import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate;
+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;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Machine-Maker marked this conversation as resolved.
Show resolved Hide resolved
+ 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.
+ *
Expand Down Expand Up @@ -1519,17 +1540,18 @@ 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;
+import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate;
+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;
Expand Down Expand Up @@ -1580,6 +1602,8 @@ index 0000000000000000000000000000000000000000..fbbbf324c002dddd868ba2fb56ddda92
+
+ ArgumentType<BlockPositionResolver> blockPosition();
+
+ ArgumentType<FinePositionResolver> finePosition(boolean centerIntegers);
+
+ ArgumentType<BlockState> blockState();
+
+ ArgumentType<ItemStack> itemStack();
Expand Down Expand Up @@ -1770,6 +1794,29 @@ index 0000000000000000000000000000000000000000..908f40dbf3e52bdfc8577a8916884e9f
+@ApiStatus.NonExtendable
+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)
+ */
+@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
new file mode 100644
index 0000000000000000000000000000000000000000..89024e67fd81a9cd8a9d1ef5bb78d1c8bcb4fcc5
Expand Down
22 changes: 17 additions & 5 deletions patches/server/0972-Brigadier-based-command-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
+ });
+ }
+
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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;
Expand Down Expand Up @@ -59,6 +61,16 @@ private static void registerViaLifecycleEvents(final JavaPlugin plugin) {
})
).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 -> {
Expand Down
Loading