Solved Syncing jars from web server

Discussion in 'Plugin Development' started by travja, Aug 30, 2015.

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

    travja

    What I'm attempting to do is download jars from a web server so that all servers on my network only have to be restarted to get all the latest code. Keep everything synced up just fine and running smoothly. The problem I'm running into is that when I download the file, it isn't loaded by Bukkit as the updated file, but rather the old file before the new one was downloaded. I'm downloading it using onLoad and then running all my download code and stuff. Basically, it downloads but isn't loaded correctly. I tried using static {} to download things before Bukkit cached all the jar stuff but then when Bukkit tried to load my plugin it broke it because it had "already been initialized" because of my code in the static block.

    Static (open)
    Code:java
    1. static {
    2. load(new Sync());
    3. }
    4.  
    5. public static void load(Sync sync) {
    6. log = sync.getLogger();
    7. database = new DatabaseManager();
    8. instance = sync;
    9. config = instance.getConfig();
    10. if(!new File(instance.getDataFolder(), "config.yml").exists())
    11. instance.saveConfig();
    12.  
    13. sync.getDataFolder().mkdir();
    14. log.info("Enabling. This should be before Spigot sees anything..");
    15. init();
    16. }


    The init method just downloads the files and replaces the old files basically. Not anything too complex persay. Really just MySQL stuff. Now again, this works, but only for plugins that are already installed. If I'm installing something that didn't previously exist, another restart is required and then the plugin properly loads as it is seen by Bukkit when it initializes.
     
  2. Offline

    mythbusterma

    @travja

    This isn't going to work because once that static block is initialized, your class has already been class-loaded, which means that all of the code for that class and dependant classes has been loaded into memory already. At this point you couldn't change it without restarting the JVM (or using a special classloader). You would be better off having an external program running to update the plugins occasionally, or having a separate plugin that will change out the file and restart the server.
     
  3. You need to download it in onDisable and maybe put the jar file in /plugins/update
     
    Last edited: Aug 31, 2015
  4. Offline

    au2001

    Well if you use Plugin#getConfig(), how could bukkit not be launched?
    And I think you class is loaded when the server enables anyway so you can't do anything before it loads.

    You could check for changes, and if there is any (with md5 checksums), you reload the server.

    Or check onDisable for updates, so that when it starts again, it has the fresh code installed when it stopped :)
    That's what I personally do for my autoupdated plugins (I also update the jar file of the server like that).

    @FisheyLP The hole point is not to have to move the plugins by hand, if you have 10-20 servers running (like mini games servers or a large network), you don't want to update the plugins manually...
     
  5. Edited post. I mean't onDisable. So when you restart/reload the server, the new jar file will be the plugin that loads instead of the old one. Connect to a database or something to make the update checking and new file downloading
     
  6. Offline

    travja

    Yeah, what I ended up doing was downloading onDisable as the server has to wait for all the code to run before it fully disables. That works well enough :)
     
Thread Status:
Not open for further replies.

Share This Page