Class UpdateChecker
- All Implemented Interfaces:
org.bukkit.event.Listener
Before using this class, you'll have to invoke the checkForUpdates() method
at least once. The method can be invoked multiple times if you want to recheck for updates.
The automatic downloader uses SpiGet API.
You can only download the plugin if it's a free plugin. Premium resources are not supported
and will not be supported as it needs the user's information to access the account, which is
something that you shouldn't really bother doing.
Also it's not possible to update the plugin automatically using the downloaded JAR file.
The owner must manually change it unless you make another plugin that handles your updates,
which is not recommended.
No schedulers or async tasks need to be performed for any of the methods.
They're already handled by CompletableFuture.
Example:
The simplest and most common way of doing this in your main class is:
UpdateChecker updater = new UpdateChecker(this, $RESOURCE_ID);
updater.checkForUpdates()
.thenRunAsync(updater::sendUpdates) // notify console
.thenRunAsync(updater::downloadUpdate); // Only for free plugins - not really recommended.
To get your $RESOURCE_ID you need to go to your plugin's Spigot page and the link should look like this https://www.spigotmc.org/resources/PLUGIN-NAME.$RESOURCE_ID/
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanYou need to runcheckForUpdates()first to use this.static CompletableFuture<Void>Initialization - Can be called multiple times.
A simple of waiting and preparing for the next action is to useCompletableFuture.thenRunAsync(Runnable)static CompletableFuture<Void>static CompletableFuture<Void>static CompletableFuture<Void>Downloads any available update to plugin's data folder using SpiGet API asynchronous.
Only works with free plugins. Don't waste your time making one for premium ones.static CompletableFuture<String>static @NotNull CompletableFuture<String>Gets the version of a Spigot plugin resource asynchronous.static Stringstatic Pathstatic Stringstatic intGets the last HTTP response code received fromfetchLatestVersion()()} A list of response codes with names can be found inHttpURLConnectionAny other codes other thanHttpURLConnection.HTTP_OKis not normal.static StringYou need to runcheckForUpdates()first to use this.static booleanCompares two program versions.
This also supports BETA and SNAPSHOT suffixes.static voidonJoinNotify(org.bukkit.event.player.PlayerJoinEvent event) Notify admins about updates when they join the server.static voidSends plugin updates to console.static String
-
Constructor Details
-
UpdateChecker
public UpdateChecker()
-
-
Method Details
-
getCurrentVersion
-
getLastHttpResponseCode
public static int getLastHttpResponseCode()Gets the last HTTP response code received fromfetchLatestVersion()()} A list of response codes with names can be found inHttpURLConnectionAny other codes other thanHttpURLConnection.HTTP_OKis not normal.- Returns:
- the last HTTP response code received while getting the version.
- Since:
- 1.0.0
-
checkForUpdates
Initialization - Can be called multiple times.
A simple of waiting and preparing for the next action is to useCompletableFuture.thenRunAsync(Runnable)- Since:
- 1.0.0
- See Also:
-
canUpdate
public static boolean canUpdate()You need to runcheckForUpdates()first to use this.- Returns:
- true if there's a new version available and you should update, otherwise false.
- Since:
- 1.0.0
- See Also:
-
getLatestVersion
You need to runcheckForUpdates()first to use this.- Returns:
- the latest version that was obtained from
fetchLatestVersion()()} - Since:
- 1.0.0
- See Also:
-
sendUpdates
public static void sendUpdates()Sends plugin updates to console.- Since:
- 1.0.0
-
onJoinNotify
public static void onJoinNotify(org.bukkit.event.player.PlayerJoinEvent event) Notify admins about updates when they join the server.- Since:
- 1.0.0
-
updateText
- Returns:
- the update text used when an update is available.
- Since:
- 1.0.0
-
fetchLatestVersionLegacy
Gets the version of a Spigot plugin resource asynchronous.- Returns:
- the plugin's version or null if no response or empty version string.
- Since:
- 1.0.0
- See Also:
-
fetchLatestVersion
-
downloadUpdate
Downloads any available update to plugin's data folder using SpiGet API asynchronous.
Only works with free plugins. Don't waste your time making one for premium ones. Uses HTTP request.- Returns:
- a future task which you don't really need to do anything with it.
- Since:
- 1.0.0
-
isHigher
Compares two program versions.
This also supports BETA and SNAPSHOT suffixes. Note that these versions are ignored as a new update. If you want to change this, you have to refer to the prereleases region inside the method.
It also supports multiple version schemes such as 1.0.0 or 1.0.2.0.5.7b
Examples2.0.0 > 1.0.0, 2.2.0 > 2.0.0, 2.2.2 > 2.2.0 1.0.0.0.0 > 1.0.0 (Not really, but still...) 1.0.0 = 1.0.0-beta = 1.0.0-SNAPSHOT = 1.0.0b = 1.0.0a- Parameters:
newVer- the new version.- Returns:
- true if the newVer is higher than oldVer, otherwise false.
- Since:
- 1.0.0
-
getJarName
-
getDownloadPath
-
downloadRepositoryToConfiguredPath
-
downloadRepository
-