How can I let player click text to use a command?

I want players to be able to click text to run an OP command even if that player is not an OP. For example something like:

Console: Do you want to enable Fly? [If you do, Please click here]

*Player1 clicks that text*

Console: /fly Player1

Is something like this possible?


Solution 1:

It is a bit of a chore but you can use tellraw command along with a scoreboard.

First create a trigger objective (manually type this in chat):

/scoreboard objectives add TellTrigger trigger

Then you have to enable the trigger for the players who should be able to access your command. You can put this command into a repeating / unconditional / always active command block to allow anyone access:

/scoreboard players enable @a TellTrigger

You could also be more selective with the target selector if you have teams or some other selection method. (ex: @a[team=red])

If using the always repeating command block, I recommend disabling command block output to prevent chat spam using command:

/gamerule commandBlockOutput false

The trigger command can now be used:

/trigger TellTrigger set 1

Use that command as a clickEvent in a tellraw command. Here is a tellraw generator you can use to create it.

Here is a tellraw command you can use:

/tellraw @a ["",{"text":"Do you want to enable flight?  "},{"text":"[Click Here]","color":"aqua","clickEvent":{"action":"run_command","value":"/trigger TellTrigger set 1"}}]

Note: Players with the trigger enabled can just type /trigger TellTrigger set 1 and it will do the same thing as clicking the tellraw. They would have to know the objective name though, so it is unlikely.

Note 2: When a player clicks the tellraw, it disables their access to trigger. If you are not using the repeating command block, you will have to re-enable for them to use it again.


That was just the setup. Now you have to create a chain of command blocks to detect the score, set fly mode for player, and set that players objective score back to 0. If you have only specific players trigger enabled, you can also re-enable their trigger in this chain.

The first block will detect the objective score, it starts everything. It is a repeating / unconditional / always active command block running this command:

/testfor @a[score_TellTrigger_min=1,score_TellTrigger=1]

The next block runs the desired higher authority command. It is a chain / conditional / always active command block with:

/fly @a[score_TellTrigger_min=1,score_TellTrigger=1]

The next block is used to re-enable access to trigger. If you are using the repeat command block to enable access, you can skip this block. It is a chain / conditional / always active command block with:

scoreboard players enable @a[score_TellTrigger_min=1,score_TellTrigger=1] TellTrigger

The final block resets the objective score to 0 so that it will not continue to be detected by the first command block. It is a chain / conditional / always active command block with:

scoreboard players set @a[score_TellTrigger_min=1,score_TellTrigger=1] TellTrigger 0

If there is still confusion, Dragnoz has a youtube video with a similar method: Here

You can also do an internet search with string minecraft tellraw trigger and it brings up several different examples.