Solved In a pickle

Discussion in 'Plugin Development' started by microgeek, May 18, 2013.

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

    microgeek

    I'm working on a utility plugin for people who run server networks, and need to push plugin updates regularly to all of the servers. It's quite simple in concept, but getting the server to reload after updating the plugins, without sending the server into an endless loop is where I'm stuck. Does anyone have some ideas to prevent the server from reloading in a loop? I've tried startup: startup in plugin.yml, but this is still to late, and Bukkit has already starting loading all of the plugins, and wont try to load new ones. If anyone has a better title, just let me know.
    Edit:
    Solved it myself, here's the code if anyone has the same issue.
    Code:
            Config config = ConfigUtilities.newConfig("config", false, this);
            if(config.getConfig().getBoolean("flush")) {
                for(String s : config.getConfig().getConfigurationSection("plugins").getKeys(false)) {
                    long start = System.currentTimeMillis();
                    File filename = new File(this.getDataFolder().getParent(), "plugins." + s + ".jar");
                    String location = config.getConfig().getString("plugins." + s + ".location");
                    try {
                        URL url = new URL(location);
                        ReadableByteChannel rbc = Channels.newChannel(url.openStream());
                        FileOutputStream fos = new FileOutputStream(filename);
                        fos.getChannel().transferFrom(rbc, 0, 1 << 24);
                        fos.close();
                    }catch(Exception e) {
                        e.printStackTrace();
                    }
                    getLogger().info("Updated " + s + ", took " + (System.currentTimeMillis() - start) + " ms");
                }
                getLogger().info("Updates completed");
                config.getConfig().set("flush", false);
                config.saveConfig();
                //Dependent on server looping in shell script
                if(config.getConfig().getBoolean("restart")) {
                    Bukkit.shutdown();
                }else {
                    Bukkit.reload();
                }
            }else {
                config.getConfig().set("flush", true);
            }
            config.saveConfig();
     
Thread Status:
Not open for further replies.

Share This Page