Get message sent after Command

Is there a way to get the message the user sends in the global chat right after he/she runs a command?

For example:

1. User runs command /hello
2. Command responds: What is your name?
3. The user presses ‘t’ and types their name.
4. The plugin responds, "Hello (username)"

I would prefer if this could be done in the command executor and without the use of events.

Does anyone have any ideas?

I guess you could use a MessageChannel if you wanted to not use events.

You’d probably have to write a MutableMessageChannel and add the player as a member from your command executor. When the player types their message to input their username, the transformMessage() method will be called, so do all your player messaging stuff in there. Make sure that you return Optional.empty() so that the message doesn’t actually go into chat. After you’re done doing stuff with the player and whatever username they inputted, remember to remove them from the members set.

I do ask though, why can you not use events?

I just want to have everything under one method, the command executor.

And is there a particular reason for this?

Although, something similar to Bukkit’s Conversations API would be nice.

Yes, the end goal is to create an Inventory GUI, and be able to use the same command. For example:

Player clicks item in GUI, then answers question.

Or

Player runs command /I new nation and then follows up with answer.

The point is so I can reuse the same command.

What would the alternative using events look like?

Hopefully all the old issues get eventually resolved.

1 Like