Expose more argument types (#12665)
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
This commit is contained in:
+70
@@ -1,10 +1,14 @@
|
||||
package io.papermc.paper.command.brigadier.argument;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import io.papermc.paper.command.brigadier.argument.predicate.BlockInWorldPredicate;
|
||||
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.AngleResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnBlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnFinePositionResolver;
|
||||
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.RotationResolver;
|
||||
@@ -13,12 +17,14 @@ import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSele
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.HeightMap;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -29,6 +35,7 @@ import org.bukkit.block.structure.StructureRotation;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scoreboard.Criteria;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.argument.VanillaArgumentProvider.provider;
|
||||
|
||||
@@ -101,6 +108,26 @@ public final class ArgumentTypes {
|
||||
return provider().blockPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* A column block position argument.
|
||||
*
|
||||
* @return column block position argument
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public static ArgumentType<ColumnBlockPositionResolver> columnBlockPosition() {
|
||||
return provider().columnBlockPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* A block predicate argument.
|
||||
*
|
||||
* @return block predicate argument
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public static ArgumentType<BlockInWorldPredicate> blockInWorldPredicate() {
|
||||
return provider().blockInWorldPredicate();
|
||||
}
|
||||
|
||||
/**
|
||||
* A fine position argument.
|
||||
*
|
||||
@@ -121,6 +148,28 @@ public final class ArgumentTypes {
|
||||
return provider().finePosition(centerIntegers);
|
||||
}
|
||||
|
||||
/**
|
||||
* A column fine position argument.
|
||||
*
|
||||
* @return column fine position argument
|
||||
* @see #columnFinePosition(boolean) to center whole numbers
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public static ArgumentType<ColumnFinePositionResolver> columnFinePosition() {
|
||||
return columnFinePosition(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* A column fine position argument.
|
||||
*
|
||||
* @param centerIntegers if whole numbers should be centered (+0.5)
|
||||
* @return column fine position argument
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public static ArgumentType<ColumnFinePositionResolver> columnFinePosition(final boolean centerIntegers) {
|
||||
return provider().columnFinePosition(centerIntegers);
|
||||
}
|
||||
|
||||
/**
|
||||
* A rotation argument.
|
||||
*
|
||||
@@ -130,6 +179,27 @@ public final class ArgumentTypes {
|
||||
return provider().rotation();
|
||||
}
|
||||
|
||||
/**
|
||||
* An angle argument.
|
||||
*
|
||||
* @return angle argument
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public static ArgumentType<AngleResolver> angle() {
|
||||
return provider().angle();
|
||||
}
|
||||
|
||||
/**
|
||||
* An argument used to resolve a set of axes.
|
||||
*
|
||||
* @return a set of axes.
|
||||
* @see org.bukkit.Axis
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public static ArgumentType<AxisSet> axes() {
|
||||
return provider().axes();
|
||||
}
|
||||
|
||||
/**
|
||||
* A blockstate argument which will provide rich parsing for specifying
|
||||
* the specific block variant and then the block entity NBT if applicable.
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.papermc.paper.command.brigadier.argument;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import org.bukkit.Axis;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A set of {@link Axis} intended for use in {@link CommandContext#getArgument(String, Class)} instead of a raw {@link Set}.
|
||||
*/
|
||||
public interface AxisSet extends Set<Axis> {
|
||||
|
||||
}
|
||||
+16
@@ -1,10 +1,14 @@
|
||||
package io.papermc.paper.command.brigadier.argument;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import io.papermc.paper.command.brigadier.argument.predicate.BlockInWorldPredicate;
|
||||
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.AngleResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnBlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnFinePositionResolver;
|
||||
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.RotationResolver;
|
||||
@@ -15,12 +19,14 @@ import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.HeightMap;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -53,13 +59,23 @@ interface VanillaArgumentProvider {
|
||||
ArgumentType<PlayerProfileListResolver> playerProfiles();
|
||||
|
||||
ArgumentType<BlockPositionResolver> blockPosition();
|
||||
|
||||
ArgumentType<ColumnBlockPositionResolver> columnBlockPosition();
|
||||
|
||||
ArgumentType<FinePositionResolver> finePosition(boolean centerIntegers);
|
||||
|
||||
ArgumentType<ColumnFinePositionResolver> columnFinePosition(boolean centerIntegers);
|
||||
|
||||
ArgumentType<RotationResolver> rotation();
|
||||
|
||||
ArgumentType<AngleResolver> angle();
|
||||
|
||||
ArgumentType<AxisSet> axes();
|
||||
|
||||
ArgumentType<BlockState> blockState();
|
||||
|
||||
ArgumentType<BlockInWorldPredicate> blockInWorldPredicate();
|
||||
|
||||
ArgumentType<ItemStack> itemStack();
|
||||
|
||||
ArgumentType<ItemStackPredicate> itemStackPredicate();
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package io.papermc.paper.command.brigadier.argument.position;
|
||||
|
||||
import io.papermc.paper.math.BlockPosition;
|
||||
import io.papermc.paper.math.Position;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* A block position, which does not have a y value.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@NullMarked
|
||||
public interface ColumnBlockPosition {
|
||||
|
||||
/**
|
||||
* Gets the X-coordinate of the block position.
|
||||
*
|
||||
* @return the block's X-coordinate
|
||||
*/
|
||||
int blockX();
|
||||
|
||||
/**
|
||||
* Gets the Z-coordinate of the block position.
|
||||
*
|
||||
* @return the block's Z-coordinate
|
||||
*/
|
||||
int blockZ();
|
||||
|
||||
/**
|
||||
* Converts this column-based position into a full 3D {@link BlockPosition}
|
||||
* by supplying a Y-coordinate.
|
||||
*
|
||||
* @param y the Y-coordinate to include in the new position
|
||||
* @return a {@link BlockPosition} representing the full 3D position
|
||||
*/
|
||||
default BlockPosition toPosition(final int y) {
|
||||
return Position.block(this.blockX(), y, this.blockZ());
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package io.papermc.paper.command.brigadier.argument.position;
|
||||
|
||||
import io.papermc.paper.math.FinePosition;
|
||||
import io.papermc.paper.math.Position;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* A fine position, which does not hold a y value.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@NullMarked
|
||||
public interface ColumnFinePosition {
|
||||
|
||||
/**
|
||||
* Gets the X-coordinate of this position.
|
||||
*
|
||||
* @return the X-coordinate as a double
|
||||
*/
|
||||
double x();
|
||||
|
||||
/**
|
||||
* Gets the Z-coordinate of this position.
|
||||
*
|
||||
* @return the Z-coordinate as a double
|
||||
*/
|
||||
double z();
|
||||
|
||||
/**
|
||||
* Converts this column-based position into a full 3D {@link FinePosition}
|
||||
* by supplying a Y-coordinate.
|
||||
*
|
||||
* @param y the Y-coordinate to include in the new position
|
||||
* @return a {@link FinePosition} representing the full 3D position
|
||||
*/
|
||||
default FinePosition toPosition(final double y) {
|
||||
return Position.fine(this.x(), y, this.z());
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package io.papermc.paper.command.brigadier.argument.predicate;
|
||||
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* A predicate for a {@link Block}.
|
||||
*
|
||||
* @see ArgumentTypes#blockInWorldPredicate()
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
public interface BlockInWorldPredicate {
|
||||
|
||||
/**
|
||||
* Checks if the passed block matches the block predicate.
|
||||
* <p>
|
||||
* This method will load the chunk the block is at in a synchronous manner.
|
||||
*
|
||||
* @param block the block instance to check
|
||||
* @return the predicate result.
|
||||
*/
|
||||
default Result testBlock(final Block block) {
|
||||
return this.testBlock(block, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed block matches the block predicate.
|
||||
*
|
||||
* @param block the block instance to check
|
||||
* @param loadChunk if the chunk the block is located at should be loaded.
|
||||
* @return the predicate result.
|
||||
*/
|
||||
Result testBlock(Block block, boolean loadChunk);
|
||||
|
||||
/**
|
||||
* The predicate result is yielded by the {@link BlockInWorldPredicate} when applied to a block.
|
||||
*
|
||||
* @see #testBlock(Block)
|
||||
* @see #testBlock(Block, boolean)
|
||||
*/
|
||||
enum Result {
|
||||
/**
|
||||
* The block passed to the predicate matches the predicate.
|
||||
*/
|
||||
TRUE,
|
||||
|
||||
/**
|
||||
* The block passed to the predicate does not match the predicate.
|
||||
*/
|
||||
FALSE,
|
||||
|
||||
/**
|
||||
* The block passed to the predicate was in an unloaded chunk and the {@code loadChunk} flag was false.
|
||||
*/
|
||||
UNLOADED_CHUNK,
|
||||
;
|
||||
|
||||
/**
|
||||
* Converts the result into an approximated boolean representation.
|
||||
* Specifically, the following mappings are applied:
|
||||
* <ul>
|
||||
* <li>{@link #TRUE} -> {@code true}</li>
|
||||
* <li>{@link #FALSE} -> {@code false}</li>
|
||||
* <li>{@link #UNLOADED_CHUNK} -> {@code false}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return the boolean representation.
|
||||
*/
|
||||
public boolean asBoolean() {
|
||||
return this == TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package io.papermc.paper.command.brigadier.argument.resolvers;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* An {@link ArgumentResolver} capable of resolving
|
||||
* an angle value using a {@link CommandSourceStack}.
|
||||
*
|
||||
* @see ArgumentTypes#angle()
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@NullMarked
|
||||
@ApiStatus.NonExtendable
|
||||
public interface AngleResolver {
|
||||
|
||||
/**
|
||||
* Resolves the argument with the given
|
||||
* command source stack.
|
||||
*
|
||||
* @param sourceStack source stack
|
||||
* @return the resolved angle in degrees.
|
||||
*/
|
||||
float resolve(CommandSourceStack sourceStack) throws CommandSyntaxException;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package io.papermc.paper.command.brigadier.argument.resolvers;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.position.ColumnBlockPosition;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* An {@link ArgumentResolver} that's capable of resolving
|
||||
* a column block position argument value using a {@link CommandSourceStack}.
|
||||
*
|
||||
* @see ArgumentTypes#columnBlockPosition()
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
public interface ColumnBlockPositionResolver extends ArgumentResolver<ColumnBlockPosition> {
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package io.papermc.paper.command.brigadier.argument.resolvers;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.position.ColumnFinePosition;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* An {@link ArgumentResolver} that's capable of resolving
|
||||
* a column fine position argument value using a {@link CommandSourceStack}.
|
||||
*
|
||||
* @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#columnFinePosition()
|
||||
* @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#columnFinePosition(boolean)
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
public interface ColumnFinePositionResolver extends ArgumentResolver<ColumnFinePosition> {
|
||||
}
|
||||
@@ -27,16 +27,16 @@ public interface Position {
|
||||
int blockX();
|
||||
|
||||
/**
|
||||
* Gets the block x value for this position
|
||||
* Gets the block y value for this position
|
||||
*
|
||||
* @return the block x value
|
||||
* @return the block y value
|
||||
*/
|
||||
int blockY();
|
||||
|
||||
/**
|
||||
* Gets the block x value for this position
|
||||
* Gets the block z value for this position
|
||||
*
|
||||
* @return the block x value
|
||||
* @return the block z value
|
||||
*/
|
||||
int blockZ();
|
||||
|
||||
|
||||
+84
@@ -2,6 +2,7 @@ package io.papermc.paper.command.brigadier.argument;
|
||||
|
||||
import com.destroystokyo.paper.profile.CraftPlayerProfile;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Range;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
@@ -12,16 +13,22 @@ import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.command.brigadier.PaperCommands;
|
||||
import io.papermc.paper.command.brigadier.argument.predicate.BlockInWorldPredicate;
|
||||
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.range.RangeProvider;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.AngleResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnBlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnFinePositionResolver;
|
||||
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.RotationResolver;
|
||||
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.position.ColumnBlockPositionImpl;
|
||||
import io.papermc.paper.command.brigadier.position.ColumnFinePositionImpl;
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
import io.papermc.paper.math.Rotation;
|
||||
import io.papermc.paper.registry.PaperRegistries;
|
||||
@@ -31,7 +38,9 @@ import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.util.MCUtil;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
@@ -42,6 +51,7 @@ import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.AngleArgument;
|
||||
import net.minecraft.commands.arguments.ColorArgument;
|
||||
import net.minecraft.commands.arguments.ComponentArgument;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
@@ -63,21 +73,28 @@ import net.minecraft.commands.arguments.TemplateMirrorArgument;
|
||||
import net.minecraft.commands.arguments.TemplateRotationArgument;
|
||||
import net.minecraft.commands.arguments.TimeArgument;
|
||||
import net.minecraft.commands.arguments.UuidArgument;
|
||||
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument;
|
||||
import net.minecraft.commands.arguments.blocks.BlockStateArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.ColumnPosArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.RotationArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.SwizzleArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.Vec2Argument;
|
||||
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;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.HeightMap;
|
||||
import org.bukkit.Keyed;
|
||||
@@ -88,11 +105,14 @@ import org.bukkit.block.structure.Mirror;
|
||||
import org.bukkit.block.structure.StructureRotation;
|
||||
import org.bukkit.craftbukkit.CraftHeightMap;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockEntityState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftCriteria;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboardTranslations;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scoreboard.Criteria;
|
||||
@@ -154,6 +174,32 @@ public class VanillaArgumentProviderImpl implements VanillaArgumentProvider {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<ColumnBlockPositionResolver> columnBlockPosition() {
|
||||
return this.wrap(ColumnPosArgument.columnPos(), (result) -> sourceStack -> {
|
||||
final BlockPos pos = result.getBlockPos((CommandSourceStack) sourceStack);
|
||||
|
||||
return new ColumnBlockPositionImpl(pos.getX(), pos.getZ());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<BlockInWorldPredicate> blockInWorldPredicate() {
|
||||
return this.wrap(BlockPredicateArgument.blockPredicate(PaperCommands.INSTANCE.getBuildContext()),
|
||||
result -> (block, loadChunk) -> {
|
||||
final BlockInWorld blockInWorld = new BlockInWorld(
|
||||
((CraftWorld) block.getWorld()).getHandle(),
|
||||
CraftLocation.toBlockPosition(block.getLocation()),
|
||||
loadChunk
|
||||
);
|
||||
// Get state lazy loads the state, will remain null if chunk is unloaded.
|
||||
if (blockInWorld.getState() == null) return BlockInWorldPredicate.Result.UNLOADED_CHUNK;
|
||||
|
||||
return result.test(blockInWorld) ? BlockInWorldPredicate.Result.TRUE : BlockInWorldPredicate.Result.FALSE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<FinePositionResolver> finePosition(final boolean centerIntegers) {
|
||||
return this.wrap(Vec3Argument.vec3(centerIntegers), (result) -> sourceStack -> {
|
||||
@@ -163,6 +209,15 @@ public class VanillaArgumentProviderImpl implements VanillaArgumentProvider {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<ColumnFinePositionResolver> columnFinePosition(final boolean centerIntegers) {
|
||||
return this.wrap(Vec2Argument.vec2(centerIntegers), (result) -> sourceStack -> {
|
||||
final Vec3 vec3 = result.getPosition((CommandSourceStack) sourceStack);
|
||||
|
||||
return new ColumnFinePositionImpl(vec3.x(), vec3.z());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<RotationResolver> rotation() {
|
||||
return this.wrap(RotationArgument.rotation(), (result) -> sourceStack -> {
|
||||
@@ -172,6 +227,35 @@ public class VanillaArgumentProviderImpl implements VanillaArgumentProvider {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<AngleResolver> angle() {
|
||||
return this.wrap(AngleArgument.angle(), (result) -> sourceStack -> result.getAngle((CommandSourceStack) sourceStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<AxisSet> axes() {
|
||||
final class AxisSetImpl extends ForwardingSet<Axis> implements AxisSet {
|
||||
private final EnumSet<Axis> inner;
|
||||
|
||||
public AxisSetImpl(final EnumSet<Axis> inner) {
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Axis> delegate() {
|
||||
return this.inner;
|
||||
}
|
||||
}
|
||||
|
||||
return this.wrap(SwizzleArgument.swizzle(), (result) -> {
|
||||
final EnumSet<Axis> bukkitAxes = EnumSet.noneOf(Axis.class);
|
||||
for (final Direction.Axis nmsAxis : result) {
|
||||
bukkitAxes.add(CraftBlockData.toBukkit(nmsAxis, Axis.class));
|
||||
}
|
||||
return new AxisSetImpl(bukkitAxes);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<BlockState> blockState() {
|
||||
return this.wrap(BlockStateArgument.block(PaperCommands.INSTANCE.getBuildContext()), (result) -> {
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package io.papermc.paper.command.brigadier.position;
|
||||
|
||||
import io.papermc.paper.command.brigadier.argument.position.ColumnBlockPosition;
|
||||
|
||||
public record ColumnBlockPositionImpl(int blockX, int blockZ) implements ColumnBlockPosition {
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package io.papermc.paper.command.brigadier.position;
|
||||
|
||||
import io.papermc.paper.command.brigadier.argument.position.ColumnFinePosition;
|
||||
|
||||
public record ColumnFinePositionImpl(double x, double z) implements ColumnFinePosition {
|
||||
}
|
||||
Reference in New Issue
Block a user