[solved]TextActions via runCommands

So how would i phrase a teleportation command through runCommand? would i need to type what the command ‘word’ would be or do i write the entire CommandBuilder inside?

You want to run a command when someone clicks some text?

Texts.of(TextActions.runCommand("/some command here"), "Click Me!")

awesome thank you :slight_smile:

…ok cause what i’m trying to do is teleport when people select the text…to the origonal source…any ideas?

so sort of like a tp to and then after it broad casts the message with their location i’d like for people to click on that and them to be teleported there :slight_smile:

In the command you just need to add the original world the player was in

TextActions.runCommand("/teleport " + player.getWorld().getUniqueId())

Then in the command handler for /teleport you take the UUID and teleport the player to that world

lol i hope it’s that simple :slight_smile:

Since this came up, is it possible to have one text run two commands one after another?

No, any text element can have only one click event. You can however execute a command as a player in code if you need to do that.

BTW a helpful resource on the chat format is http://wiki.vg/Chat you can see the internal representation of our Text object.

oooh quick question…how can one run a command inside of a method? like if i have a method that works when you break a block…how do you cod it to allow say “/setlocation” ? which is a command ?

Sponge.getCommandDispatcher().process(player, "/command");
1 Like

thank you
that helps quite a bit

Sponge also supports the runCallback TextAction which allows an arbitrary function to be run when the text is clicked – this may make what you want to do easier.

1 Like