How to make an AsyncPlayerChatEvent happen

Discussion in 'Plugin Development' started by LeeTheENTP, Oct 11, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    LeeTheENTP

    I'm working on a plugin that highlights a user's name in chat when it is mentioned. Right now it highlights the username for everyone, but I want it to only highlight it for the player it matches.

    In order to accomplish this, I removed the matching player from the recipients list and created a second AsyncPlayerChatEvent with the same sender, but with a colored username and only one recipient - the matching player. However, the second chat event never happens and a boatload of errors spills into the console.

    What can I do to make this work?
     
  2. Offline

    I Al Istannen

    @TheShadbusher You could remove the player from the reciepients list and just send him the message manually via "player.sendMessage(".
    I don't see the need for creating a seconds PlayerChatEvent, but maybe there is a better way im unaware of.
     
  3. Offline

    LeeTheENTP

    This removes all chat formatting and sends a raw message.
     
  4. Offline

    DoggyCode™

    He could do event.getFormat ().getMessage(); to get the formatting.. if that's a problem
     
  5. Offline

    LeeTheENTP

    That statement doesn't compile.
     
  6. Offline

    DoggyCode™

    Huh? You can use that to get the proper format if you'd like to send a raw message.
     
  7. Offline

    LeeTheENTP

    [​IMG]
     
  8. Offline

    DoggyCode™

    Dammit.. I'm on my phone rn. Google AsyncPlayerChatEvent and look in the doc. It will tell you there.
     
  9. Offline

    boomboompower

  10. Offline

    LeeTheENTP

  11. Offline

    I Al Istannen

    @TheShadbusher It did :)
    Look at my Screenshot:
    upload_2015-10-12_21-9-22.png

    Do you see the "Format: " message? This is equal to "event.getFormat()". In the javadoc is written:
    "When this event finishes execution, the first format parameter is the Player.getDisplayName() and the second parameter is getMessage().
    The format parameter refer to the Java formatter here or here or google it. With that information, you should be able to solve it. If not, feel free to ask!
     
Thread Status:
Not open for further replies.

Share This Page