Minecraft execute tellraw's clickEvent from original entity, not player
I'm using a command like this:
/execute @e[type=ArmorStand] ~ ~ ~ tellraw @a[score_goto=-1]
{
"selector": "@e[type=ArmorStand,r=1]",
"clickEvent": {
"action": "run_command",
"value": "/tp @p ~ ~ ~"
},
"color":"blue"
}
To try and make each armor stand in the world say their name (in blue), and, if the player clicks the armor stand's name in-chat they will be teleported to that armor stand.
Currently, it looks like this:
And, when I click either of the two names, I'd like to be teleported to that armor stand, hence the
"clickEvent":{"action":"run_command","value":"/tp @p ~ ~ ~"}
part within the command.
However, because run_command apparently only inserts the command into the player's chat, I just get teleported to wherever I currently am when I click any name.
So, I tried:
"clickEvent": {
"action": "run_command",
"value": [
"/tp @p @e[type=ArmorStand,name=",
{"selector": "@e[type=ArmorStand,r=1"},
"]"
]
}
Thinking that maybe the JSON in value would be parsed, producing my desired value of
"value": "/tp @p @e[type=ArmorStand,name=Name_Of_This_Armor_Stand]"
but no luck.
Everything I've tried just doesn't seem to work, can someone please help me find a way to make a tellraw clickEvent teleport the player to the entity which executed the tellraw command?
TL;DR
Please help me find a way to make a tellraw clickEvent teleport the player to the entity which executed the tellraw command?
Best Answer
Do this for all of your armor stands. I believe this is the only way for it to work. It is going to be more command blocks, but I think its the only working one.
/execute @e[type=ArmorStand,name=(insertname)] ~ ~ ~ tellraw @a[score_goto=-1]
{
"selector": "@e[type=ArmorStand,r=1]",
"clickEvent": {
"action": "run_command",
"value": "/tp @p @e[type=ArmorStand,name=(insertname)]"
},
"color":"blue"
}
Pictures about "Minecraft execute tellraw's clickEvent from original entity, not player"



Minecraft Tellraw Command [1.19] Tutorial
More answers regarding minecraft execute tellraw's clickEvent from original entity, not player
Answer 2
You can do this on non-op players using scoreboards and the trigger command.
First, setup an objective with the triggercriteria:
scoreboard objectives add OBJName trigger
Now enable players to use the trigger command (more below):
scoreboard players enable PLAYER OBJName
Now that it is enabled, instead of doing the tp command directly use this command:
/trigger OBJName set 1
This will set the non-op's score of OBJName to 1. Now you can use an execute command to teleport the player:
execute @a[score_OBJNaNe_min=1] ~ ~ ~ tp @p @e[type=Armorstand,name=x]
This tests for players with a score of 1 in OBJName, then teleports them to the @e entity. To TP to an Armorstand, it needs the customname nbt tag set and that value to replace X in the above command
Next, you most likely want to setup protection. When you use the tellraw, you should enable the player then disable when you don't want them to be able to use it.
When you say the tellraw, also execute this:
scoreboard players enable PLAYER OBJName
Then, when they click the tellraw do your stuff then use this
scoreboard players disable PLAYER OBJName
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Andrea Piacquadio, Monstera, Oliver Sjöström, Andrea Piacquadio

