Minecraft – Spawn a command block with a player’s name

minecraft-commandsminecraft-java-edition

I want to have a command block with a button.
When clicking the button the command block should clear himself and spawn three new command blocks.
But here is the tricky part the new command blocks should have the name of the player who pressed the button.
Basically when the players name is Dinnerbone the new command blocks should have the command:

/tp @p[name=Dinnerbone] ~ ~1 ~-3

When the player who presses the button is named Notch the command of the new command blocks should be:

/tp @p[name=Notch] ~ ~1 ~-3

Is this even possible?

Best Answer

That's not possible right now (1.9.4).

What you can do, is give the player a tag: (Put this command block behind the button)

/scoreboard players tag @p add THEONE

Then (in repeating command block) put the command you want to execute:

/tp @a[tag=THEONE] ~ ~1 ~

Append your commands into Chain-command-blocks. Append a Chain-Command-block put this command:

/scoreboard players tag @a[tag=THEONE] remove THEONE

To reset the machine.

The setup:

enter image description here

Hope it helped (: