Plugin Update Checkers
08-09-2022 - 3 minutes
I have a decent chunk of plugins that I created for Minecraft. One feature I really like in them are update checkers. Server admins usually get lazy and don’t check themselves, so having the plugin automatically tell them is easier. There’s a few ways to achieve this.
One of the main methods is to use the SpigotMC's API in order to check the latest version of a resource. This is used by many, and even has a wiki page dedicated to it here.
For example, calling the URL https://api.spigotmc.org/legacy/update.php?resource=99606 will show the latest version on SpigotMC for my plugin ToolStats.
This method is extremely easy to setup. All you have to do is read the contents of a URL, and see if it matches your current plugin’s version. If it doesn’t, then the plugin is outdated. This can have some problems. SpigotMC sometimes goes down, it doesn’t tell you how many versions behind you are, or how old your version is.
I eventually found out about GitHub's API, specifically it's API for releases. Once I found out about this, I got to work converting my plugins over. I use GitHub releases in order to publish my plugins, so this is perfect.
Because I am reusing code, I eventually figured it would be better to make a library that my plugins can use. Instead of copying a bunch of annoying code, I can make a library to simplify the process. And thus, GitHubReleaseAPI was born.
GitHubReleaseAPI is simply a JSON reader that converts all information about releases into GitHubRelease objects. This is how you first access the API.
For each GitHubRelease object, you can access a lot of information.
This can solve the problem above, I can tell a server owner when a release came out. I can tell them how many versions behind they are, I can even send them the direct download link to the release. I am very happy with how this library turned out, even if it’s extremely simple. This library is on Maven Central if you wish to use it!
Both methods work great for their own purposes (yes this was a subtle advertisement for my library).