Solved Getting Player's Chat Input

Discussion in 'Spigot Plugin Development' started by Wilsoon, Mar 24, 2020.

Thread Status:
Not open for further replies.
  1. This time, I would want to get the player's full chat input. Something like Citizens where it captures player input and checks whether it is equal to a certain string, before executing something in the code.
    Is there any easy way to do this or do I need to manually do the PlayerChatEvent?
  2. I personally add a player to a hashmap or an arraylist and then inside PlayerChatEvent check if that hashmap/arraylist contains that player;

    Code (Java):
    private void whatever(Player player) {

    public void onChat(PlayerChatEvent e) {
        if (yourHashMap.contains(e.getPlayer) {
          //do stuff
  3. Conversation API? Though, I didn't quite understand what you want to accomplish.
  4. Would AsyncPlayerChatEvent work?

    I meant public chat, when the player types something in public chat, I cancel that event and gets what he said to match my own command arguments etc.
  5. Yeah, but it's better to use AsyncPlayerChatEvent and sync collection somehow(to prevent CME).
  6. I actually don't get the difference between PlayerChatEvent and AsyncPlayerChatEvent, neither do I know how it would affect a server. Mind explaining?
  7. AsyncPlayerChatEvent is async, so it works not in the main thread(that's why chat sometimes works even after crash).
    PlayerChatEvent is deprecated, and I'm not sure if it still works.
  8. If you intend to cancel the event, just use the Conversation API instead.
  9. I'm quite sure Conversations may be for /whisper but correct me if I'm wrong. I'm cancelling the event to use that String in my code. So that the public message that contains the keyword for my command isn't sent out to the public but I can still use that to provide some sort of output.

    Something like:
    Player types /hi
    [Prompts for a player to say Hi to]
    Player types a normal public chat message: "Player2"
    [Plugin stops message from sending, and checks for player2]
    | Finds player 2: [Plugin says: "Player says hi to Player2!"]
    | Doesn't find: (PlayerNotFound logic here)

    #9 Wilsoon, Mar 24, 2020
    Last edited: Mar 24, 2020
  10. Just read the doc that I linked
  11. I mean how else would you expect that to happen,just use AsyncPlayerChat,get the message and just do your checks,it's not really that hard
    Code (Text):
    public void checkTag(AsyncPlayerChatEvent e){
    String msg = e.getMessage();

    Also would be pretty helpful telling us how the message you want typed looks like
  12. I think Dani gave me sufficient info to continue. Thanks anyway Stellrow & rober
Thread Status:
Not open for further replies.