Manipulating a chat message for specific players?

Discussion in 'Plugin Development' started by Anonomoose, Aug 2, 2014.

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

    Anonomoose

    I've been thinking how to go about editing chat messages from other players for only certain players. I get that you can remove recipients from the chat event so that they can't see the message, but I need to be able to manipulate the message itself for certain players, rather just remove them from seeing it entirely. The idea's I thought of were:

    - Removing the player from the recipient list and then sending them a modified version of the message, but that seemed a little.. "cheaty"?
    - Using packets to alter the message, although I'm rather inexperienced with packets to be blunt.

    Any tips in the right direction would be greatly appreciated, thanks!
     
  2. Offline

    Gerov

    Anonomoose If I read this right, you might be able to use an AsyncChatEvent, set the event to canceled and loop through all the players sending each of them the modified message.
     
  3. Offline

    Anonomoose

     
  4. Offline

    Flamedek

    Anonomoose Describe 'cheaty'..
    Seems like a solution to me.
     
  5. Offline

    Anonomoose

    Other plugins not being able to act on the event if it's cancelled's my main concern.
     
  6. Offline

    Gerov

    Anonomoose Well, that is the only way I can think out doing it.
     
  7. Offline

    chaseoes

    It's not possible using the Bukkit API alone, I ran into this problem a couple years ago with my SkitChat plugin. You have to cancel the event and iterate through all online players, which breaks other plugins.

    You can also use ProtocolLib and modify the chat packet, which may be the best option. Using a library like ProtocolLib should be easier than trying to modify packets yourself. You can find example code here.
     
  8. Offline

    Gerov

    chaseoes That is a good idea, I didn't think about that....
     
  9. Offline

    Anonomoose

    Thanks for that, I'll look into it. I tried creating my own PlayerChatEvent with a modified message and the only recipients being certain players who had been removed from the original chat event, so they would see a modified version of the message - but I ran into some confusing stuff that I'm gonna look over later, but thanks for the help!
     
  10. Offline

    _Filip

    Why don't you just do the cancelling the event and looping through players on the highest event priority, that's when most plugins have already acted on that event and you can safely cancel it.
     
    megasaad44 likes this.
Thread Status:
Not open for further replies.

Share This Page