Update CHECKER. Simple method for copying and pasting

Discussion in 'Resources' started by gomeow, Jan 27, 2013.

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

    gomeow

    Well I know Gravity has his own updater, here is just a simple method you can use:

    Your file names for this need to be in this format: "v[major].[minor].[build]" eg. "v1.3.2", but this method can be easily modified to suit your needs.
    Code:java
    1. public boolean getUpdate() throws Exception {
    2. String version = getDescription().getVersion();
    3. String yourSlug = "putSlugHere";
    4. String urlString = "[url]http://dev.bukkit.org/server-mods/[/url]"+yourSlug+"/files.rss";
    5. //Remove the [url="http:// part, as that is BBCode's fault
    6. URL url = new URL(urlString);
    7. InputStreamReader isr = null;
    8. try {
    9. isr = new InputStreamReader(url.openStream());
    10. }
    11. return false; //Cannot connect
    12. }
    13. String line;
    14. int lineNum = 0;
    15. while((line = in.readLine()) != null) {
    16. if(line.length() != line.replace("<title>", "").length()) {
    17. line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1); //Substring 1 for me, takes off the beginning v on my file name "v1.3.2"
    18. if(lineNum == 1) {
    19. Integer newVer = Integer.parseInt(line.replace(".", ""));
    20. Integer oldVer = Integer.parseInt(version.replace(".", ""));
    21. if(oldVer < newVer) {
    22. return true; //They are using an old version
    23. }
    24. else if(oldVer > newVer) {
    25. return false; //They are using a FUTURE version!
    26. }
    27. else {
    28. return false; //They are up to date!
    29. }
    30. }
    31. lineNum = lineNum + 1;
    32. }
    33. }
    34. in.close();
    35. return false;
    36. }



    Now to use it:
    Code:java
    1. boolean needsUpdate;
    2. try {
    3. if(getConfig().get("Check-For-Updates", false)) {
    4. needsUpdate = getUpdate();
    5. }
    6. else {
    7. needsUpdate = false;
    8. }
    9. }
    10. catch(Exception e) {
    11. needsUpdate = false;
    12. }

    Implement it however you wish.


    np98765 told me to post this, so blame him"
     
    Timpotim likes this.
  2. Offline

    Gravity

    Please remember that you need to include a configuration option in your plugins to disable any sorts of offsite connections or file downloads. Not doing so could be considered a backdoor or phone-home system, and will result in file removal for security reasons.
     
  3. Offline

    gomeow

    I agree about the config checking part, but about the phone-home part, this connects to DBO, which isn't a back door?
     
  4. Offline

    Gravity

    As I said doing it without checking could be viewed as such. We don't delete it because it IS a backdoor or whatever but because it will cause problems because people think it is.
     
  5. Offline

    Timpotim

    This is the best update checker ever! I tried many update checkers but this is the best. Thank you!
     
    gomeow likes this.
Thread Status:
Not open for further replies.

Share This Page