Class AutoUpdater

java.lang.Object
net.realdarkstudios.commons.util.AutoUpdater
Direct Known Subclasses:
RDSCommonsUpdater

public abstract class AutoUpdater extends Object
  • Constructor Details

    • AutoUpdater

      public AutoUpdater(org.bukkit.plugin.Plugin plugin, String dataURL, String versionURL, AutoUpdater.Parser parser)
      Creates an auto-updater for a given Plugin. There is no need to create more than one auto updater, as this may have bad consequences.
      Parameters:
      plugin - The Plugin that owns this auto updater.
      dataURL - The URL to check for updates from. Put '%b%' wherever the branch would go in the URL.
      versionURL - The URL to grab a version file from. Put '%b%' where the branch would go, and '%v%' where the version would go.
      parser - The AutoUpdater.Parser to use, which determines how to parse the URL data. For a CUSTOM parser type, use Parser.CUSTOM.setParser() to set your custom parsing method
  • Method Details

    • getParser

      public AutoUpdater.Parser getParser()
      Gets the parser type of the current AutoUpdater
      Returns:
      The Parser
    • setParser

      public void setParser(AutoUpdater.Parser parser)
      Sets the parser.
      Parameters:
      parser - The custom parsing method, a Function of URL that returns a HashMap of Version and String
    • getReplacements

      public Map<String,String> getReplacements()
      Gets the map of replacements
      Returns:
      The Map with all replacements
    • setReplacements

      public void setReplacements(Map<String,String> replacements)
      Sets the map of replacements. For example, if you have a version that will not be correctly parsed, you can set a replacement for it.

      (snapshot-24w13a in this case is something that will not get parsed)
      Ex. Putting in ("snapshot-24w13a", "1.0.0.0-snapshot-24w13a") will plug in "1.0.0.0-snapshot-24w13a" into the Version#fromString call, which will be parsed.
      Parameters:
      replacements - The map of replacements
    • updateBranch

      public void updateBranch(String newBranch)
      Updates the branch of the readURL
      Parameters:
      newBranch - which branch to use
      Since:
      0.3.0.1
    • hasUpdate

      public boolean hasUpdate()
      Check if there is an update that needs to be downloaded/installed
      Returns:
      true if there is a newer version available for download, false if not
      Since:
      0.3.0.0
    • getNewestVersion

      public String getNewestVersion()
      Gets the new version string
      Returns:
      The newest version
      Since:
      0.3.0.0
    • getLastCheckResult

      public int getLastCheckResult()
      Returns the result of the last update check
      Returns:
      -1 if plugin version is BEHIND, 0 if it is UP-TO-DATE, 1 if it is AHEAD, and 10000 for ERROR
    • checkForUpdate

      public void checkForUpdate()
    • applyUpdate

      public void applyUpdate()
    • statusBehind

      protected abstract void statusBehind(Version newVer, String newVerInput)
    • statusUpToDate

      protected abstract void statusUpToDate()
    • statusAhead

      protected abstract void statusAhead()
    • errorChecking

      protected abstract void errorChecking()
    • ioExceptionHandler

      public static void ioExceptionHandler(IOException ioexc)
    • parseVersion

      public static Version parseVersion(String versionToParse)
    • parseMavenMetadata

      public static HashMap<Version,String> parseMavenMetadata(URL readURL, Map<String,String> replacements)