Getting a plugin to reload its code

Discussion in 'Plugin Development' started by Callum Aitchison, Aug 24, 2011.

Thread Status:
Not open for further replies.
  1. Hi, I am building an auto updater for my plugin and I don't want to reload the whole server to reload the updated plugin.
    The plugin is updated by having an old plugin file and a new plugin file in a folder in plugins so it isn't automatically loaded, a byte array is extracted from the new version and then is written to the old file. This bypasses the being unable to delete a file in use. The problem with this is that the file is not re read after disabling and enabling the plugin and you have to reload the server to get it to read again. (related thread: This causes lag. At the moment the plugin loads another plugin which does the update but while writing this I realised the plugin itself can update itself using this method.

    Instead of reloading the server can I get the plugin to reload its own code from the file? If so, how? I suppose this would be more Java than Bukkit. Is this not possible because it's running as a part of bukkit?
  2. Offline


    Afraid you will have to make bukkit handle this; loading a jar is not as simple as copying and pasting the data into memory; java need to interpret it as well.

    To load a certain plugin file, try this:
    this.getServer().getPluginManager().getPlugin("plugin name").getPluginLoader().loadPlugin(File file);
    I haven't tested it (a 20 sec write), but I guess it will give you some directions. :)
  3. I installed a plugin named PlugMan to test loading using that (/plugman load) and that didn't work. I guess that will use the same method but I will try your code anyway, shouldn't be long, thanks.

    @bergerkiller Nope, doesn't work.

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


    NO idea if this works, but who knows....

            Plugin plugin = getServer().getPluginManager().getPlugin("Plugin name");
  5. Tried disabling and re enabling afterwards too. I'm starting to think this can't be done.
Thread Status:
Not open for further replies.

Share This Page