Solved Can I cancel AsyncPlayerChatEvent?

Discussion in 'Spigot Plugin Development' started by Lockface77, Nov 22, 2020.

  1. Hello,

    I am creating a plugin and need a little bit of chat management (its not the main aim of my plugin).

    If a Player is sending a message under certain circumstances I would like to cancel the event.

    The thing is that the every chat event is deprecated except "AsyncPlayerChatEvent", and since the event is Async, I don't know if cancelation of this event would work.

    Hope someone can answer this question ;)
  2. Yes cancelling it will stop the message from spreading. The meaning of Async is just that the chat isn't being run on the main thread of the server.
    • Winner Winner x 1
    Joking aside, yes it implements the Cancellable interface so you can do event.setCancelled(true) on it which will prevent the chat message from being sent to anyone.
  4. The problem with "try and see", is that it is async, and async kinda enter the dark side of programming (programming with multiple threads), and if I try, it may work when I try but there could be a case that happen one in a thousand time that make it not work.

    That's why I preferred to ask to be sure that it is meant to work this way or if there was a better event/technique to use
  5. I believe the message doesn't get sent until all the event handlers have gotten a chance to mess with it. So, the only reason why your code wouldn't work is if you wrote unreliable code.
    • Agree Agree x 1