Get latest spigot version of a resource using Spiget.
This has both Kotlin & Java Options. Just use whatever language your plugin is in!
To get your resource id, go to your resource page. For example, PlaceholderAPI is at
Then the numbers at the end are your resource id. In the PlacholderAPI example above, the resource id is 6245
.
First, you will need to include KHttp in your project. I did this via jitpack, but on their wiki they have other options if you prefer those.
class Plugin : JavaPlugin() {
override fun onEnable() {
if (getLatestVersion(6245) != this.description.version) {
// they need to update
// maybe log to console and let them know
}
}
}
public final class Plugin extends JavaPlugin {
@Override
public void onEnable() {
if (YourUtilsClass.getLatestVersion(6245) != this.getDescription().getVersion()) {
// you gotta update
// log to console
}
}
}
This was just an example usage. This could also be run when an admin logs in to the server, or any other time you want!