FlashyReese / CommandAliases

Alternate short commands for complex commands
MIT License
25 stars 6 forks source link

[Question/Request] clickable text link #24

Closed Dizover closed 2 years ago

Dizover commented 2 years ago

Is it possible to create a command that gives a clickable text with a link? if it is not possible to do so now, could this be added?

FlashyReese commented 2 years ago

You can do this will the vanilla tellraw command. I have one example in the wiki with it https://github.com/FlashyReese/CommandAliases/wiki/Command-Alias-(0.3.0---0.4.2)#helpop-command=

{
    "commandMode": "COMMAND_ALIAS",
    "command": "helpop {arg::minecraft:greedy_string#message}",
    "execution": [
        {
            "command": "execute if entity @a[team=Staff] run tellraw @a[team=Staff] [\"\",{\"text\":\"[\",\"color\":\"gold\"},{\"text\":\"HelpOP\",\"color\":\"dark_red\"},{\"text\":\"] \",\"color\":\"gold\"},{\"text\":\"{this::SELF}\",\"color\":\"red\"},{\"text\":\": \",\"color\":\"white\"},{\"text\":\"{message}\",\"color\":\"red\"}]",
            "type": "SERVER",
            "ignoreOptionalRemoval": true
        },
        {
            "command": "execute unless entity @a[team=Staff] run tellraw {this::SELF} [\"\",{\"text\":\"[\",\"color\":\"gold\"},{\"text\":\"HelpOP\",\"color\":\"dark_red\"},{\"text\":\"] \",\"color\":\"gold\"},{\"text\":\"There are currently no staff online!\",\"color\":\"red\"}]",
            "type": "SERVER",
            "sleep": "1000"
        },
        {
            "command": "execute unless entity @a[team=Staff] run tellraw {this::SELF} [\"\",{\"text\":\"[\",\"color\":\"gold\"},{\"text\":\"HelpOP\",\"color\":\"dark_red\"},{\"text\":\"] \",\"color\":\"gold\"},{\"text\":\"You can get help in our discord:\",\"color\":\"red\"},{\"text\":\"\\n\"},{\"text\":\"URL GOES HERE\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"URL GOES HERE\"}}]",
            "type": "SERVER"
        }
    ]
}

tellraw @p [{"text":"TEXT","clickEvent":{"action":"open_url","value":"http://example.com/"}}]

Be sure to escape all the quotes

FlashyReese commented 2 years ago

It would look something like this

{
    "commandMode": "COMMAND_CUSTOM",
    "customCommand": {
        "parent": "showlink",
        "actions": [
            {
                "command": "tellraw $executor_name() [{\"text\":\"Click here for link\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http:\/\/example.com\/\"}}]",
                "commandType": "SERVER"
            }
        ]
    }
}

Here is an escape tool https://www.freeformatter.com/json-escape.html

Dizover commented 2 years ago

OMG thank you very much, I watched the wiki, but unfortunately did not notice this, thank you, your mod should then be super popular with such features. If I fully understand it I will make a video tutorial on your mod.