Can you execute a /fill command based on another player's coordinates?

I'm looking for a way to make a fill command that fills where another player is. I know you can do it to your own coordinates using the ~ ~ ~ keys, but can you do it to another player/entity? I'm not willing to download a mod though.


Solution 1:

1.13+

execute's at subcommand allows you to change where the command is running. For example, the following command will fill glass around a random player:

execute at @r run fill ~2 ~2 ~2 ~-2 ~-2 ~-2 glass

Any target selector can be used in place of the @r, or just a player name, to select the player/entity you want.


1.12-

The execute command will change who the command is running as and where it's running from. For example, the following command will fill glass around a random player:

execute @r ~ ~ ~ fill ~2 ~2 ~2 ~-2 ~-2 ~-2 glass