powered by Jive Software

Probably simple question: How to register a listener for incoming messages

First of all: Hi there,

this migth be a very simple questions but I could not find the answer even after hours of searching. Heres what I want to know:

I want to register a handler/event listener/callback/whatever that gets informed about any incoming message for users that are on the same domains as my server. Of course I read the developers guide and also managed to load a first test plugin that prints some stuff into the log.

But I don’t get how events are handled. I checked some plugins to see how they accomplish a few things, but whenever I open a new one, there is a bunch of totally different named handlers and listeners that don’t even inherit from the same superinterface/class. How in hell am I supposed to know about them? I could not find a document that describes all the handlers that are available.

So for my need I only found the PacketInterceptor. But this seems to be VERY low level since it already handles with all kinds of packets. I’m actually only interessted in Messages. I might just filter these out, but I’m a bit uncertain if this is really the way to go. Additionally I was expecting something like a “MessageListener” that I can register somewhere and only get informed about Messages that were delivered to local users.

I just want to get all messages (for local users only) as soon as they are either delivered to a connected session or stored in the offline storage.

This migth sound like I’m just to lazy to make researches on my own, but I’m really confused about the fact that I could not find something that provides a not so low-level event-system.

Thanks in advance


It might not be the best way to go, but doing this with your own PacketInterceptor should be pretty easy.

I don’t know if there are any signals sent for specific package types, so with your Interceptor you can just test for instanceof Message. You should watch out for the incoming & processed values too, or else you might intercept the packet multiple times.

Then, if you know the packet is a message etc, you just check your remaining constraints until you know it’s exactly what you want, and handle it accordingly. At least thats how we do it with Gojara

Only difference with EventListeners would be that you dont have to check if it’s actually a Message. Of course, if there are many Interceptors checking the same thing it may not be optimal, but it’s really not a problem in practice as far as i’m concerned. That said, if anybody has a better idea, feel free to correct me

Regards, Axel

Hey Chris,

I think the PacketInterceptor is the easiest way to do so.

If you’d like to get up and running quickly, install and inspect the ContentFilter plug-in source code.

Good luck!

  • Jack