Solved Problem with crating a custom ChatEvent

Discussion in 'Plugin Development' started by MrVerece, Dec 7, 2013.

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

    MrVerece

    First of all I am not that experienced with bukkit, so please tell me if I understood the behavior of ChatEvents wrong :)
    For my plugin I want to edit the chat-messages that some player receive. My Listener checks for AsyncPlayerChatEvents and saves the message that has been send. If that message needs to be edited, I would cancel the original event and create my own ones so that I am able to kind of set the recipients per message.
    Code:java
    1.  
    2. manager = plugin.getServer().getPluginManager();
    3. manager.registerEvents(this, plugin);
    4.  
    5. AsyncPlayerChatEvent chatEvent = new AsyncPlayerChatEvent( false, event.getPlayer(), ("test"), event.getRecipients() );
    6.  
    7. manager.callEvent(chatEvent);
    8.  

    The Problem that I am having is that I can't get my own ChatEvent getting displayed in chat. The original event is cancelled successfully, but the new one does not appear anywhere. At the same time I don't get any errors, so I am asuming that the event has been created.
    Does anybody know where my mistake is?
    I can post more code if needed!
     
  2. Offline

    ZeusAllMighty11

    You can change the recipients without killing the event
     
  3. Offline

    MrVerece

    How? there isnt any method like setRecipients(). And I need to send multiple messages to different recipients based on one chat event
     
  4. Offline

    RawCode

    Code:
        public Set<Player> getRecipients() {
            return recipients;
        }
    This is "SET" just add or remove anything you like from it.
     
  5. Offline

    MrVerece

    Okay, I think I get what you mean :)
    But how about creating additional ChatEvents? I that even possible?
     
  6. Offline

    RawCode

    there is no additional chat events possible, only internal chat event is response to chat packet recieved from client by server.

    if you want to do something else, you must mod both client and server (like if you want to monitor chat open\chat closed)
     
  7. Offline

    MrVerece

    okay thank you - I got my plugin to work now :)
     
  8. Offline

    Garris0n

    You just can't change the message per-recipient, which I find incredibly annoying.
     
    ZeusAllMighty11 likes this.
  9. Offline

    Conarnar

    Unless you kill the event ;)
     
    Garris0n likes this.
  10. Offline

    kamcio96

    event.getRecipients().clear();
    event.getRecipients().addAll(your list);
     
  11. Offline

    MrVerece

    Mine works aswell
    Code:java
    1. Set<Player> recipients = event.getRecipients();
    2. //....
    3. for(Player p : recipients){
    4. if("p needs to be removed") recipients.remove(p);
    5. }
     
Thread Status:
Not open for further replies.

Share This Page