Skip to content

Location

The block position argument is used for retrieving the position of a block. It works the same way as the first argument of the /setblock <position> <block> Vanilla command. In order to retrieve the BlockPosition variable from the BlockPositionResolver, we have to resolve it using the command source.

Commands.argument("pos", ArgumentTypes.blockPosition())
.executes(context -> {
final BlockPositionResolver resolver = context.getArgument("pos", BlockPositionResolver.class);
final BlockPosition pos = resolver.resolve(context.getSource());
context.getSource().getSender().sendPlainMessage("Put in " + pos.x() + " " + pos.y() + " " + pos.z());
return Command.SINGLE_SUCCESS;
})

The fine position argument works similarly to the block position argument, with the only difference being that it can accept decimal (precise) location input. The optional overload (ArgumentTypes.finePosition(boolean centerIntegers)), which defaults to false if not set, will center whole input, meaning 5 becomes 5.5 (5.0 would stay as 5.0 though), as that is the “middle” of a block. This only applies to X/Z, the Y coordinate is untouched by this operation.

This argument returns a FinePositionResolver. You can resolve that by running FinePositionResolver#resolve(CommandSourceStack) to get the resulting FinePosition.

Commands.argument("pos", ArgumentTypes.finePosition(true))
.executes(context -> {
final FinePositionResolver resolver = context.getArgument("pos", FinePositionResolver.class);
final FinePosition pos = resolver.resolve(context.getSource());
context.getSource().getSender().sendRichMessage("Position: <red><x></red> <green><y></green> <blue><z></blue>",
Placeholder.unparsed("x", String.valueOf(pos.x())),
Placeholder.unparsed("y", String.valueOf(pos.y())),
Placeholder.unparsed("z", String.valueOf(pos.z()))
);
return Command.SINGLE_SUCCESS;
})

This argument allows the user to select one of the currently loaded world. You can retrieve the result of that as a generic Bukkit World object.

Commands.argument("world", ArgumentTypes.world())
.executes(context -> {
final World world = context.getArgument("world", World.class);
final Player player = context.getSource().getPlayerOrThrow();
if (player.teleport(world.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.COMMAND)) {
context.getSource().getSender().sendRichMessage("Successfully teleported <player> to <aqua><world></aqua>",
Placeholder.component("player", player.displayName()),
Placeholder.unparsed("world", world.key().asString())
);
return Command.SINGLE_SUCCESS;
} else {
context.getSource().getSender().sendRichMessage("<red>Failed to teleport the player");
return Command.SINGLE_SUCCESS;
}
})