Solved Version API? (Plugin latest version)

Discussion in 'Spigot Plugin Development' started by chibill, May 2, 2017.

  1. Is there an api for getting the latest version of a plugin from the spigot resources?

    I have seen people saying tell devs that use 3rd party api's getting told to use spigots but I have been unable to find docs about it.
     
  2. This is what I do:

    Code (Text):
    if(updateCheck)
            {
                PluginDescriptionFile pdfFile = getDescription();
                Logger logger = getLogger();
                double currentVersion = Double.parseDouble(pdfFile.getVersion());

                double checkedVersion = checkUpdate();

                logger.info("Checking for updates...");

                if(checkedVersion != 0)
                {
                    if(currentVersion < checkedVersion)
                    {
                        logger.info("There is a new update available! (V." + checkUpdate() +
                                ") You are currently using V." + currentVersion + "!");
                    }else if(currentVersion == checkedVersion)
                    {
                        logger.info("You are on the current version!");
                    }else if(currentVersion > checkedVersion)
                    {
                        logger.info("You're on a version that isn't publicly released yet! You must be special. ;)");
                    }
                }
            }

    private Double checkUpdate()
        {
            Logger logger = getLogger();

            double versionNum;

            try {
                HttpURLConnection con = (HttpURLConnection) new URL(
                        "http://www.spiromarshes.com/BetterWarpsVersion.txt").openConnection();
                con.setDoOutput(true);
                String version = new BufferedReader(new InputStreamReader(
                        con.getInputStream())).readLine();
                if (version.length() <= 7) {
                    versionNum = Double.parseDouble(version);
                    return versionNum;
                }
            } catch (Exception ex) {
                logger.info("Failed to check for an update.");
            }
            return versionNum = 0;
        }
    You basically store a text file on a webserver with the current version of the plugin, and check against that on startup.
     
  3. People seem to not like devs doing this. (From what I have seen while looking around.... I was asking if SpigotMC has something built-in like an API for the latest. (Considering it shows it on the web page automatically.)
     
  4. Use this then: https://spiget.org/
     
  5. Is that not just as bad as using a 3rd party site. (Which I am trying to avoid as a few devs are getting hated on for doing so)
     
  6. Choco

    Moderator

    erm... no. That website uses web-requests and returns a JSON result. This is called a RESTful API. Just read results from the website and parse it as JSON, retrieve what you need, badda-bing badda-boom, you have version information. It's also a very trusted website from a well-trusted developer
     
  7. Okay. (Just tested it out... Seems cool but the docs for the request don't match what it really returns..) :(

    Only problem will be that its beta and seems to change more then its docs do... :(
     
  8. WAS

    WAS

    Really would be cool if there was a universal CKAN like plugin for Spigot (or built in). Wouldnt be to expensive and could have any numbet of failsafes.

    That website looks very intuitive. If not you can just do it manually with a specific resource and spigot website and some parsing. So long as CloudFare doesnt recognize your servers user agent and IP as something blacklisted. Seen this on a few hosts now.