Unregister an event

Discussion in 'Plugin Development' started by AinSophAur, Oct 17, 2011.

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

    AinSophAur

    I'm using this to disable my plugin:

    pm.disablePlugin(plugin);

    but it doesn't disable the events so if I re-enable it, it duplicates the number of times it picks up the event. Basically, its giving me double output since the previous event registrations still exists. I want it to reset the event registrations before re-enabling the plugin like when you do a /reload.
     
  2. I wish I knew how.

    I believe there is no way to unregister events. Which would be rediculous, in my opinion.

    There's something about the subject here:
    https://github.com/Bukkit/Bukkit/pull/108

    I'm not sure what that page is all about. Did krsmes make an effort to add unRegisterEvent() but it didn't get accepted or something?

    krsmes says: "I moved on long ago an wrapped the listener layer so i can 'register' and 'unregister' within my plugin".

    I guess he (I'm pretty sure that's a dude) found some workaround.
    Maybe extend the PlayerListener class, and implement some boolean, I don't know.

    Anybody?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  3. Offline

    Sagacious_Zed Bukkit Docs

    The way I removed a listener was by reflection.
     
  4. Offline

    wwsean08

    what do you mean by reflection?
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    LEARN JAVA!
    http://download.oracle.com/javase/tutorial/reflect/

    also note to what I am doing, is actually a very very bad thing, as I am basically breaking into a class and doing horrible things not meant to be done... It is not good practice at all, and depends greatly on the PluginManger's code remaining the same.
     
  6. Offline

    wwsean08

    just because i don't know every internal thing about java doesn't mean i don't know java, but thank you for sending me that, i'm gonna read up on it
     
    Mtihc likes this.
  7. We should convince the Bukkit team to add an unregisterEvent() method.
    I mean wtf
     
  8. If its that easy do it yourself. I mean wtf
     
  9. It is easy on the bukkit "side" of the code and there were already pull requests that implemented that - but you probably know how fast pull requests are merged.
    On the side of a developer, it isn't as easy because you first need to "hack" into the PluginManager's private fields.
    It's still not really that hard if you know how to use reflection, but it's really not good practice, as @Sagacious_Zed said.
     
    Mtihc likes this.
  10. I know. I'm going to look into writing a pull myself
     
  11. Offline

    AinSophAur

    Where do I request for this feature?
     
Thread Status:
Not open for further replies.

Share This Page