Unload cass?

Discussion in 'Plugin Development' started by Meatiex, Aug 21, 2014.

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

    Meatiex

    Simple question: can I unlaod a class without restarting the server, and how?
    Loading a class:
    Code:
      public void onEnable() {
        Bukkit.getPluginManager().registerEvents(new Spawner(), this);
    }
    Any help is awesome, thanks :D
     
  2. Offline

    Wingzzz

    What is it you're looking to do?
     
  3. Offline

    stormneo7

    Unregister an event. I don't know how thou.
     
  4. Offline

    mythbusterma

    Meatiex

    If you're looking to get rid of the instance, you could unregister the listener you created via these methods:

    https://forums.bukkit.org/threads/unregistering-of-events.60817/

    Once there is no longer a reference to your Spawner object, it will be automatically collected.

    If you're wishing to actually unload the class, i.e. completely unload everything associated with the class (the bytecode and static objects), you would actually have to null reference the class loaded that loaded it, way more trouble than whatever you're doing is worth: http://stackoverflow.com/questions/148681/unloading-classes-in-java
     
  5. Offline

    Meatiex

    I have some code that makes it so you can push players, it lags a lot with a lot of people online, I want to unlaod the class when more than 30 people are online.
    I could make a if statement and a boolean, but that would still have slightly more lag than unloading it.
    I'll try to unload it with the link provided by mythbusterma, thanks :D
     
  6. Offline

    mythbusterma

    Meatiex

    Just unregister the event handler using the first link.
     
  7. Offline

    Meatiex

    This is sorta a dum question, but how would I define listener?
    Code:java
    1. Plugin plugin = plugin;
    2. HandlerList.unregisterAll(listiner); // unregister listener from any events it is registered for
    3. PlayerMoveEvent.getHandlerList().unregister(plugin); // unregister listeners owned by plugin from PlayerMoveEvent
     
  8. Offline

    teej107

    Meatiex
    • Have your class implement Listener
    • Assign your created listener object to a variable
     
  9. Offline

    Meatiex

    I still don't know how do that, sorry for being such a noob...
     
  10. Offline

    teej107

    Meatiex Give it your best shot. This is very basic coding skills. You should know how to create variables and assign values to them.
     
Thread Status:
Not open for further replies.

Share This Page