How can I get an item with the same name as the nearest player?

Something along the lines of:
/give @p diamond_sword 1 0 {display:{Name:@p}}
but this obviously is not working. How can I do this?
Best Answer
I spent I few hours researching this one! An answer by JooshNF:
This is not possible unless you know all the players who will press it. If so, you would need a setup like this;
http://i.imgur.com/0aYTzT9.png
Command 1: /execute @e[type=WitherSkull] ~ ~ ~ /testfor @p[name=(player's name),r=5]
Command 2: /setblock x y z command_block 0 replace {Command:"/give @p (item) 1 0 {display:{Name"(player's name)"}}}
To summon witherskull: /summon WitherSkull ~ ~ ~ {direction:[0.0,0.0,0.0]} So, this is basically impossible.
Click here for original thread.
If I helped you, please mark this up, and, if you found it useful, please mark as answer.
Pictures about "How can I get an item with the same name as the nearest player?"



How do I get an item with a custom name?
The other target selectors are \u201c@a\u201d for all players, \u201c@r\u201d for a random player, and \u201c@e\u201d will target all entities. Entities include everything that isn't a block, like monsters, snowballs, animals, and arrows.What does @R mean in Minecraft?
The @e target selector is used to target all entities in the game. This includes both players and mobs in the world. Notice that in this last example, we have used [type=enderman] to target only enderman. This value is called a target selector argument and allows us to filter the target.Give Named Items In Minecraft Using Commands | Xbox One, PS4, Windows 10, MCPE
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Erik Mclean, cottonbro, Elijah O'Donnell, Julia Avamotive