Solved asyncplayerchatevent not working

Discussion in 'Spigot Plugin Development' started by Hardc0re, Jul 29, 2018.

  1. I don't know why this doesn't work. It's supposed to make the players name light purple when chatting.

    public void onPlayerChat(AsyncPlayerChatEvent event) {
    Player player = (Player) event.getPlayer();
    event.setFormat(ChatColor.LIGHT_PURPLE + player.getDisplayName() + ": " + event.getMessage());

    There is no error or anything in the console when talking and the listener is enabled (as other events in the class work).
    Any help? :3
    • Winner Winner x 2
  2. Cancel the message.
    then add this
    Code (Java):
    for (Player players : Bukkit.getOnlinePlayers())

    and in it add this
    Code (Java):
     players.sendMessage(chatcolor + the player name + chatcolor (to change the :) + ": " + chatcolor(to change message color) + event.getMessage())
    I didn't want to spoonfeed the full thing but this should definitely help.
  3. Don't cancel an AsyncPlayerChatEvent..
  4. "The whole purpose of cancelling the events is to stop the defaults, allow modifications and resending. Therefore, if you want to modify the contents of a message you'll need to cancel the event first."
    ^Not my own words but the person who said it said it very well imo.
  5. There are methods for the event to do this specifically. Cancelling the AsyncPlayerChatEvent may cause interference with other chat-based plugins. OP's method of doing it is correct (except in place of the player's name and the message, they should use the "%s" placeholder).
    • Informative Informative x 1