Class UpdateChecker

java.lang.Object
wtf.choco.veinminer.utils.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 SpiGet, an REST server which is updated periodically. If the results of requestUpdateCheck() are inconsistent with what is published on SpigotMC, it may be due to SpiGet's cache. Results will be updated in due time.

Author:
Parker Hawke - 2008Choco
  • Field Details

  • Method Details

    • requestUpdateCheck

      @NotNull public @NotNull CompletableFuture<UpdateChecker.UpdateResult> requestUpdateCheck()
      Request an update check to SpiGet. This request is asynchronous and may not complete immediately as an HTTP GET request is published to the SpiGet API.
      Returns:
      a future update result
    • getLastResult

      @Nullable public @Nullable UpdateChecker.UpdateResult getLastResult()
      Get the last update result that was queried by requestUpdateCheck(). 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 to get() (which is recommended after initialization).
      Parameters:
      plugin - the plugin for which to check updates. Cannot be null
      pluginID - 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
      versionScheme - 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 to get() (which is recommended after initialization).
      Parameters:
      plugin - the plugin for which to check updates. Cannot be null
      pluginID - 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

      @NotNull public static @NotNull UpdateChecker get()
      Get the initialized instance of UpdateChecker. If init(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 (if init(JavaPlugin, int) has been invoked) and get() is safe to use.
      Returns:
      true if initialized, false otherwise