Can a plugin auto-remove itself?

Discussion in 'Plugin Development' started by MetalGearDaner, Dec 2, 2014.

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

    MetalGearDaner

    This is my question. For example, the plugin CANT continue beeing used because of X reason, can any piece code auto-remove the plugin once it's disabled? I that X reason make the plugin disable when running the server, after disabling, remove the .jar
     
  2. Offline

    SyTeck

    I'm not so sure about this, but I may think that Java has an implemented method to schedule a file deletion as soon as it is not being used anymore. The problem is that it can't execute code while being deleted, meaning it's "impossible"?
     
  3. Offline

    mine-care

  4. Offline

    SyTeck

    That would require an external plugin though, because it's not possible to execute something that isn't there.

    If a plugin deletes itself, it has to execute code inside the plugin itself, but that code is deleted.
    Unloading isn't a problem because Bukkit, or the file you put in your .bat file to make the server run handles that part.
     
  5. Offline

    xTrollxDudex

    SyTeck
    Theoretically, if you create a new, thread then it will not be destroyed if the starting process run by another process is unloaded, however, I do believe there is something with threading mechanics that keeps it loaded, I might investigate this possibility when I have the time.
     
  6. Offline

    mythbusterma

    xTrollxDudex

    I would think that as long as any one class that is in the jarfile isn't unloaded, the JVM would prevent the deletion of the file. Classloading is done irrespective of threads so I don't think there would be a way, as long as the class is loaded, and the stock JVM won't allow unloading a class while a reference still exists (as far as I know).
     
  7. Offline

    xTrollxDudex

  8. Offline

    mythbusterma

    xTrollxDudex
    The thread to remove it would have to be declared somewhere in your jarfile though.
     
  9. Offline

    xTrollxDudex

    The plugin shouldn't be running the thread
     
  10. Offline

    MajorSkillage

    Wouldn't you be able to select a file from a path and just delete through java? ._. Not sure but this is a guess
     
  11. Offline

    teej107

    MajorSkillage Yes, but you won't be able to delete the file if it is being used by something. eg: craftbukkit
     
  12. Offline

    mythbusterma

    xTrollxDudex

    Where would the deletion code be declared? Unless there's something in the Java standard API or Apache that allows for the scheduled deletion of a file without maintaining a reference to the thing that scheduled it. Although, I would suppose you could do this by scheduling a delayed task via the command input of a computer, though that would be platform dependant.
     
  13. Offline

    timtower Moderator Moderator

    MetalGearDaner If it can't be used then remove the download link. Removing a plugin from a server while it is using the plugins functionality won't make you many friends.
     
  14. Offline

    ResultStatic

    MetalGearDaner xTrollxDudex maybe a shutdown hook would work. thats the last thing that gets called when its disabled it also runs it on a seperate thread created by the shutdown hook. i dont think any references to the thread would ever be in the plugin.
     
  15. Offline

    MajorSkillage

    How does hosting companies do it then?

    And on top of that eclipse also does it when i go to export and it replaces a jar file

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  16. Offline

    xTrollxDudex

    mythbusterma
    There are numerous secret bukkit hooks in the cb code...?
     
Thread Status:
Not open for further replies.

Share This Page