Plugin.unregisterEventListener() ineffective?

  • Is it possible that Plugin.unregisterEventListener() does nothing? I tried with the following simple test plug-in which:


    1) in its onEnable(), register itself, unregister itself and than register itself again;


    2) in its PlayerCommandEvent handler, simply echo any command to the chat.


    Expected Result: the command is echoed only once.


    Actual Result: the command is echoed twice, as if the unregisterEventListener() call in onEnable() did nothing and there were TWO listeners.


  • Possible consequences of the above, illustrated by the following scenario:


    *) We have a component, say a menu, which is created when needed and registered as listener (listening for mouse clicks or for key strokes), un-registering the main plug-in listener.
    *) The component does its job and then each of its elements are carefully removed from the player GUI, all children removed from their parents (which, incidentally, sounds quite horrible... ), instance(s) of the component de-referenced and so on.
    *) The main plug-in listener is re-registered.


    1) We end up with 3 listeners being active: the original registration of the main listener, the component listener, the second registration of the main listener, while one at most was intended to be active at a time. Repeat the process a few times and we will have a plethora of listeners all active...


    2) The component, being still referenced by the Event Manager (i.e. by whichever part of the API is responsible for dispatching the events to the listeners), is never garbage collected. In fact n instances of it may occupy memory (and handle events pestering each other) if the process is repeated n times.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!