Solved Editing chat message format

Discussion in 'Plugin Development' started by StellarFX, Aug 20, 2021.

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

    StellarFX

    Hello,

    My problem is a theoretical problem.
    I am trying to modify the chat messages… And I did it.

    Here is how it works:
    It gets the message, using AsyncPlayerChatEvent (EventPriority is HIGHEST), creates another one based on the format that I want to give it, cancels the event and then broadcasts the just-created BaseComponent using getServer()::broadcast.

    Here is my code, minus all the variables I'm using:

    PHP:

    @EventHandler(priority EventPriority.HIGHEST)
    public 
    void chatEvent(AsyncPlayerChatEvent e) {

           
    // DECLARING ALL MY VARIABLES...

           
    BaseComponent[] wholeMessage = new ComponentBuilder(islandLevelFormat).append(userGroupFormat).append(dot).append(userNameFormat).append(guillemet).event((HoverEventnull).append(message).event((HoverEventnull).create();
           
    e.setCancelled(true);

           
    e.getPlayer().getServer().getConsoleSender().sendMessage(wholeMessage);
           
    e.getPlayer().getServer().broadcast(wholeMessage);
    }
    And it works like a charm, even the hover event (which is in fact the most important feature) is working:
    upload_2021-8-20_12-49-2.png

    But here comes my problem.
    Whenever another plugin asks for input in the chat (and it's supposed not to send the message then), my plugin sends it anyway, which ends up looking like this:

    upload_2021-8-20_12-52-20.png

    Is there any way to prevent my plugin from doing that?
    I already tried editing the EventPriority, which results in a different behavior but still not what I want.

    My first lead would be to use packets, but I don't know much about them and I want to know if there is an easier solution before.

    Thanks!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @StellarFX Check if the event is cancelled already?
     
  3. Offline

    StellarFX

    @timtower Oh well, it seems to be working now.
    I wasn't aware of that method… In fact, I wasn't aware that the event would still pass to other plugins.
    Thanks for the quick response time!

    Solved.
     
Thread Status:
Not open for further replies.

Share This Page