Package wtf.choco.arrows.util
Class UpdateChecker
java.lang.Object
wtf.choco.arrows.util.UpdateChecker
public final class UpdateChecker extends Object
A utility class to assist in checking for updates for plugins uploaded to
SpigotMC. Before any members of this
class are accessed,
init(JavaPlugin, int)
must be invoked by the plugin,
preferrably in its JavaPlugin.onEnable()
method, though that is not a
requirement.
This class performs asynchronous queries to Spigot's API. If the results of
requestUpdateCheck()
are inconsistent with what is published on SpigotMC, it
may be due to the REST API cache. Results will be updated in due time.
- Author:
- Parker Hawke - Choco
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UpdateChecker.UpdateReason
A constant reason for the result ofUpdateChecker.UpdateResult
.class
UpdateChecker.UpdateResult
Represents a result for an update query performed byrequestUpdateCheck()
.static interface
UpdateChecker.VersionScheme
A functional interface to compare two version Strings with similar version schemes. -
Field Summary
Fields Modifier and Type Field Description static UpdateChecker.VersionScheme
VERSION_SCHEME_DECIMAL
-
Method Summary
Modifier and Type Method Description static @NotNull UpdateChecker
get()
Get the initialized instance of UpdateChecker.@Nullable UpdateChecker.UpdateResult
getLastResult()
Get the last update result that was queried byrequestUpdateCheck()
.static UpdateChecker
init(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, int pluginID)
Initialize this update checker with the specified values and return its instance.static UpdateChecker
init(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, int pluginID, @NotNull UpdateChecker.VersionScheme versionScheme)
Initialize this update checker with the specified values and return its instance.static boolean
isInitialized()
Check whether the UpdateChecker has been initialized or not (ifinit(JavaPlugin, int)
has been invoked) andget()
is safe to use.@NotNull CompletableFuture<UpdateChecker.UpdateResult>
requestUpdateCheck()
Request an update check to Spigot.
-
Field Details
-
VERSION_SCHEME_DECIMAL
-
-
Method Details
-
requestUpdateCheck
Request an update check to Spigot. This request is asynchronous and may not complete immediately as an HTTP GET request is published to the Spigot API.- Returns:
- a future update result
-
getLastResult
Get the last update result that was queried byrequestUpdateCheck()
. If no update check was performed since this class' initialization, this method will return null.- Returns:
- the last update check result. null if none.
-
init
public static UpdateChecker init(@NotNull @NotNull org.bukkit.plugin.java.JavaPlugin plugin, int pluginID, @NotNull @NotNull UpdateChecker.VersionScheme versionScheme)Initialize this update checker with the specified values and return its instance. If an instance of UpdateChecker has already been initialized, this method will act similarly toget()
(which is recommended after initialization).- Parameters:
plugin
- the plugin for which to check updates. Cannot be nullpluginID
- the ID of the plugin as identified in the SpigotMC resource link. For example, "https://www.spigotmc.org/resources/veinminer.12038/" would expect "12038" as a value. The value must be greater than 0versionScheme
- a custom version scheme parser. Cannot be null- Returns:
- the UpdateChecker instance
-
init
public static UpdateChecker init(@NotNull @NotNull org.bukkit.plugin.java.JavaPlugin plugin, int pluginID)Initialize this update checker with the specified values and return its instance. If an instance of UpdateChecker has already been initialized, this method will act similarly toget()
(which is recommended after initialization).- Parameters:
plugin
- the plugin for which to check updates. Cannot be nullpluginID
- the ID of the plugin as identified in the SpigotMC resource link. For example, "https://www.spigotmc.org/resources/veinminer.12038/" would expect "12038" as a value. The value must be greater than 0- Returns:
- the UpdateChecker instance
-
get
Get the initialized instance of UpdateChecker. Ifinit(JavaPlugin, int)
has not yet been invoked, this method will throw an exception.- Returns:
- the UpdateChecker instance
-
isInitialized
public static boolean isInitialized()Check whether the UpdateChecker has been initialized or not (ifinit(JavaPlugin, int)
has been invoked) andget()
is safe to use.- Returns:
- true if initialized, false otherwise
-