Auto-Updater Library! Check versions, give reasons, update urgency and force updates!

Discussion in 'Resources' started by Adamki11s, Jun 13, 2011.

Thread Status:
Not open for further replies.
  1. Download ZIP File
    Download RAR Archive

    Youtube blocked my music :(


    Features:
    • Auto-Download the latest version of your plugin!
    • Notify users of what the update this.
    • Notify users whether the update is urgent or not.
    • Lightweight and easy to use :D
    I know a lot of people want to know how to make their plugins 'Auto-Update' so I thought I'd make a library you can use to do this.

    This library allows you to check the current version of your plugin against the latest version, give some details about what the update pertains to, Eg. Bug fixes, new features etc. You can also force the newest version of your plugin to be downloaded and the user can then move the updated version into their plugins folder whenever they want.

    Firstly you will need to create a simple website and upload it, preferably to a free host but if you already own one you can sue that. A good free web host which I would recommend is Zymic. And a nice'n easy FTP client is FileZilla (For uploading your new file).

    All you need to do is upload the sample file included with the library onto your webhost, make sure you modify the version numbers accordingly. Now that you've got this out of the way you can get onto actually using the library.

    First you need to import the library into your project, I show how to do this in the video. Now that you have the library import you'll need to create a variable so you can access the methods.
    PHP:
    private AUCore core;
    Then inside on enable you need to define the 'core'.
    PHP:
    Logger log Logger.getLogger("Minecraft");

    public 
    void onEnable(){

        
    core = new AUCore("http://www.regiosplugin.zxq.net/example.html"log"[AutoUpdaterExample]");

    }
    Now that you have the core initialised you can check the version:
    PHP:
    double currentVer 1.0currentSubVer 0;

    if(!
    core.checkVersion(currentVercurrentSubVer"AutoUpdaterExample")){
        
    core.forceDownload("http://linktoyourfile""AutoUpdaterExample");
    }
    This will check if the current version matches the latest one, if it doesn't then force a download of the latest version.

    Examples and templates can be found in the zip files above. I hope this helps and if you use this please remember to credit me :D
     
    bitWolfy, Kohle and TexasGamer like this.
  2. Offline

    iPhysX

    Nice one :3
    I will be using this :p
     
  3. Offline

    Tagette

    Hmm think this is something that should be added to my template?
     
  4. A template should probably be kept pretty simple but if you want to add this sure, as long as you credit me ;)
     
  5. Offline

    Torrent

    Ah, excellent.

    This will come in handy for LevelCraft etc.

    Good work.
     
  6. Thank you :)
     
  7. Offline

    Tagette

    Well yes simple but also I think a template should have all the available features so you can choose what you want from it. That way you can start coding your idea faster.
     
  8. Offline

    Tagette

    Btw I can hear the music o.o
     
  9. Sweet, will be added to restartNow. The question is, do i unzip it or make the user unzip it. Hmmmm
     
  10. Unzip what? The download is intented to be a raw jar file.
     
  11. So it wouldnt work to download a zip?
     
  12. Well it would but then you'd have to unzip the file yourself.
     
  13. Mmkay, thats great. One more question:
    Is it possible to get the name of the file downloaded?
    Basically, its because restartNow has 2 jars and a .bat file, and its easiest to put them in a zip.thx!

    Wait, it wouldnt be able to check the version or anything like that would it :confused:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  14. Version checking depends on what is o n your website
     
  15. Err, nvm. Im just going to make my jar auto extracting. RestartNow will use this soon ;)
     
  16. Mind if i make a couple changes to AUCore?
     
  17. Go ahead, if you make any notable changes send them to me and I might include them for everyone else to use ;)
     
  18. okay! Basically, i removed some error messages(well, customized them), and i converted most of the doubles to int's...
     
  19. Offline

    Tagette

    Ok I have added this into my template.

    You could just force download on all three files when an update is needed. No need for a zip.

    Anyways:
    Is there a way to make a optional update?

    EDIT: Nevermind I guess it is optional.. If they don't want the new update they wont replace their original plugin with the new one.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  20. Haha, thanks, i ended up just making my plugin auto-extracting(it was on my todo list, :D )
    Also, when the player downloads an update i automatically copy it from AutoUpdate, and then reload my plugin. lol, screw "optional"
     
  21. Offline

    Kalman Olah

    Will be using this, thanks a lot :).

    EDIT: Changed my mind and made a simpler auto-updater myself :p.
     
    Daniel Heppner likes this.
  22. I <3 this, and RestartNow will be using this in the next version!
     
    iPhysX likes this.
  23. Offline

    TopGear93

    im extremely sorry for the necro but @Adamki11s does this still work?
     
  24. Will still work fine yes, it's independent of Bukkit.
     
    JasonW likes this.
  25. Offline

    Sleaker

    @Adamki11s - Please PLEASE tell people not to include the 'library' source-for-source in their projects. If someone modifies the source to their liking and keeps the package names intact it will cause the same issues as Register. Plugin explosions. Please put in bold on the top that anyone wanting to use it needs to change the packages completely, so that there are no Class exceptions/issues.

    You can actually do all of this through the rss file feed on dev.bukkit.org - If you keep your file names consistent you don't even need to download anything but just do a filename check with an RSS reader.

    Code:
        public String updateCheck(String currentVersion) throws Exception {
            String pluginUrlString = "http://dev.bukkit.org/server-mods/vault/files.rss";
            try {
                URL url = new URL(pluginUrlString);
                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openConnection().getInputStream());
                doc.getDocumentElement().normalize();
                NodeList nodes = doc.getElementsByTagName("item");
                Node firstNode = nodes.item(0);
                if (firstNode.getNodeType() == 1) {
                    Element firstElement = (Element)firstNode;
                    NodeList firstElementTagName = firstElement.getElementsByTagName("title");
                    Element firstNameElement = (Element) firstElementTagName.item(0);
                    NodeList firstNodes = firstNameElement.getChildNodes();
                    return firstNodes.item(0).getNodeValue();
                }
            }
            catch (Exception localException) {
                return currentVersion;
            }
            return currentVersion;
        }
    
    This will return either the filename or the current version string of the plugin. It's also 100% thread safe. and the example code obviously checks if Vault is up to date.


    I like your idea, but I'm of the opinion that using the built-in dbo feeds is much much easier to handle than requiring people to push to another site completely different, along with keeping a text file updated. The dbo site has all the tools required to keep a plugin auto-updated much more easily than a seperate site.
     
    xboxhacks likes this.
  26. Are you sure? I didn't think that two plugins calling independent methods within themselves would cause a problem as the library is compiled with their project?
     
  27. Offline

    Sleaker

    It will if the library has changed at all between the two. The only way it will work is if the class files are nearly identical, or the library is used.. as a library and not compiled into the plugin source.

    Trust me when I say that telling people to compile your source into their plugin without changing package/classnames is a horrible idea and one of the reasons why Register is so bad.
     
  28. Am I allowed to use that code in RushMe? That would be awesome :)

    Anyway, is there any chance you could maybe make this LGPL? I want to use this for RushMe, but my code is LGPL, and I cannot use any of this because of it...I just don't like being forced into using a licence by a lib :p
     
  29. Offline

    Sleaker

    Vault's LGPL. and the code snippet is from Vault.
     
  30. Hehe, I don't worry about licensing much, unless its a really big project - no one really adheres to it :p. But I appreciate you asking and yeah of course you can.
     
Thread Status:
Not open for further replies.

Share This Page