Best way to await a chat message from a player?

Title might be confusing. Here’s an example.

[Plugin] Please choose players to kill! When finished, type “done”.
Notch
CaptainSparklez
Me4502
done

The plugin sends a message to the player, and waits for the user to type something and press enter.

I suppose one way to check for this is to listen to the MessageChannelEvent.Chat event. This gets fired when chat messages are being sent and contains the raw message, in which you then can check if it contains certain keywords or something similar.

Not sure if there is a different (or perhaps better) way to go over this.

1 Like

Thanks.

Say I type /killthesepeople, which prompts what I describe in my thread.

The code inside the corresponding class that implemented CommandExecutor would be run, as this is how Sponge performs Minecraft commands.

How would I tell this code, “Hey, await a chat message from a player.”? I’m not sure how to do this since the command class and MessageChannelEvent listener are separate.

Well in theory, when you run the command, your plugin then needs to start tracking what the player says in the message channel event and then cache it. Once they enter a name (or type „done“) you have to trigger the follow up logic from the message event.

However, seeing as are trying to make a /kill command. How about you implement your commands with arguments instead? Do you can do /killthesepeople Notch PersonA PersonB. Then you would just have to check if the names are valid players and then kill them. This can all be done in the command class though.