Command with person who executes command mentioned in output

Hi, I’m a complete noob at this, except I’m quite interested in learning.

How could you create a command where the executor of command is mentioned in the output of the command.

for example - /sayhi -> “[executor of command] says hi.”

I’d recommend that your learn a bit more general programming, ad then coming back to Sponge after that.

The SpongeDocs have a section on commands, which should be very helpful. If you have any specific issues with the API, feel free to ask.

1 Like

Thanks for replying. I have been over all of that, but there is nothing on integrating variables into outputed commands.
Sorry to be such a hassle.

This section should be what you want. If, for example, you wanted to get the name of the player who sent the command, you would first check if the CommandSource is a Player:

if(src instanceof Player) {

}

then cast the CommandSource as a Player:

Player player = (Player) src;

then use the Player object as normal:

String playerName = player.getName();

In fact, CommandSource has a getName() method itself so you can just use src.getName() directly

2 Likes