Package com.jeff_media.updatechecker
Class UpdateChecker
java.lang.Object
com.jeff_media.updatechecker.UpdateChecker
Main class. Automatically checks for updates.
-
Constructor Summary
ConstructorsConstructorDescriptionUpdateChecker
(org.bukkit.plugin.java.JavaPlugin plugin, UpdateCheckSource updateCheckSource, String parameter) Initializes an UpdateChecker instance.UpdateChecker
(org.bukkit.plugin.java.JavaPlugin plugin, VersionSupplier supplier) Initializes an UpdateChecker instance with a customVersionSupplier
. -
Method Summary
Modifier and TypeMethodDescriptioncheckEveryXHours
(double hours) Starts to check every X hours for updates.checkNow()
Checks for updates now and sends the result to the console when notifyRequesters is set to true (default)checkNow
(org.bukkit.command.CommandSender... requesters) Checks for updates now and sends the result to the given list of CommandSenders.Returns a list of applicable Download links.Returns the changelog linkReturns the donation linkstatic UpdateChecker
Deprecated.As of SpigotUpdateChecker 1.4.0, more than one instance can exist at the same time.Returns the last successful UpdateCheckResultReturns the latest version string found by the UpdateChecker, or null if all checks until yet have failed.Returns the name/suffix of the free plugin versionReturns the name/suffix of the paid plugin versionReturns the permission required to receive UpdateChecker messages on joinBiConsumer<org.bukkit.command.CommandSender[],
Exception> Gets the task that will run when/after the update check fails.BiConsumer<org.bukkit.command.CommandSender[],
String> Gets the task that will run when/after the update check succeeds.protected org.bukkit.plugin.Plugin
Gets the plugin that instantiated this UpdateChecker instanceGets the Spigot User ID of the user who downloaded the plugin if it's a premium plugin, otherwise "%%__USER__%%"Returns the support linkGets the version string of the currently used plugin versionstatic UpdateChecker
init
(org.bukkit.plugin.java.JavaPlugin plugin, int spigotResourceId) Deprecated.UseUpdateChecker(JavaPlugin, UpdateCheckSource, String)
instead.static UpdateChecker
Deprecated.UseUpdateChecker(JavaPlugin, UpdateCheckSource, String)
instead.boolean
Checks whether the update checker already ran.boolean
Returns whether colored console output is enabledboolean
Returns whether OPs will be notified on join when a new version is availableboolean
Gets whether the given CommandSenders will be informed about UpdateChecker resultsstatic boolean
isOtherVersionNewer
(String myVersion, String otherVersion) Checks whether one version is really newer than another according to the semantic versioning scheme, including letters.boolean
Returns whether the message "You are using the latest version of" will be suppressed. boolean
Checks whether the latest found version of the plugin is being used.boolean
Returns whether the paid version of the plugin is installed.onFail
(BiConsumer<org.bukkit.command.CommandSender[], Exception> onFail) Sets a task that will run when/after the update check has failed.onSuccess
(BiConsumer<org.bukkit.command.CommandSender[], String> onSuccess) Sets a task that will run when/after the update check has succeeded.setChangelogLink
(int resourceId) Sets a link to your plugin's changelog generated from your plugin's SpigotMC/Polymart Resource IDsetChangelogLink
(String link) Sets a link to your plugin's changelog.setColoredConsoleOutput
(boolean coloredConsoleOutput) Sets whether or not the used and latest version will be displayed in color in the consolesetDonationLink
(String donationLink) Sets a link to your plugin's donation websitesetDownloadLink
(int resourceId) Sets the download link for your plugin generated from your plugin's SpigotMC/Polymart Resource ID.setDownloadLink
(String downloadLink) Sets the download link for your plugin.setFreeDownloadLink
(int resourceId) Sets the download link for the free version of your plugin generated from your plugin's SpigotMC/Polymart Resource ID.setFreeDownloadLink
(String freeDownloadLink) Sets the download link for the free version of your plugin.setNameFreeVersion
(String nameFreeVersion) Sets the name/suffix for the free version's name.setNamePaidVersion
(String namePaidVersion) Sets the name/suffix for the paid version's name.setNotifyByPermissionOnJoin
(String permission) Sets the permission needed to be informed about UpdateChecker results on join.setNotifyOpsOnJoin
(boolean notifyOpsOnJoin) Whether or not to inform OPs on join when there is a new version available.setNotifyRequesters
(boolean notify) Whether or not CommandSenders who request an update check will be notified of the result.setPaidDownloadLink
(int resourceId) Sets the download link for the paid version of your plugin generated from your plugin's SpigotMC/Polymart Resource ID.setPaidDownloadLink
(String link) Sets the download link for the paid version of your plugin.setSupportLink
(String link) Sets a link to your plugin's support channel.setTimeout
(int timeout) Sets the timeout for the HTTP(S) connection in milliseconds. 0 = use Java's default valuesetUsedVersion
(String usedVersion) Sets the version string of the currently used plugin version.setUserAgent
(UserAgentBuilder userAgentBuilder) Sets the UserAgent string using a UserAgentBuildersetUserAgent
(String userAgent) Sets the UserAgent string using plain textsetUsingPaidVersion
(boolean paidVersion) Tells the UpdateChecker whether the server already uses the paid version of your plugin.stop()
Stops the scheduled update checks.suppressUpToDateMessage
(boolean suppress) Sets whether the message "You are using the latest version of" should be suppressed.
-
Constructor Details
-
UpdateChecker
public UpdateChecker(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull VersionSupplier supplier) Initializes an UpdateChecker instance with a customVersionSupplier
.- Parameters:
plugin
- Instance of your pluginsupplier
- VersionSupplier that supplies the latest version of your plugin
-
UpdateChecker
public UpdateChecker(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull UpdateCheckSource updateCheckSource, @NotNull String parameter) Initializes an UpdateChecker instance.- Parameters:
plugin
- Instance of your pluginupdateCheckSource
- Source where to check for updates. To use a custom source, seeUpdateChecker(JavaPlugin, VersionSupplier)
parameter
- Parameter for the update checker source. SeeUpdateCheckSource
for more informatino
-
-
Method Details
-
getInstance
Deprecated.As of SpigotUpdateChecker 1.4.0, more than one instance can exist at the same time. Keep track of the instances you created yourself.Gets the current UpdateChecker singleton if it has been created, otherwise null.- Returns:
- UpdateChecker instance being ran, or null if
UpdateChecker(JavaPlugin, UpdateCheckSource, String)
wasn't called yet.
-
init
@Deprecated public static UpdateChecker init(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, int spigotResourceId) Deprecated.UseUpdateChecker(JavaPlugin, UpdateCheckSource, String)
instead.Initializes the UpdateChecker instance. HAS to be called before the UpdateChecker can run.- Parameters:
plugin
- Main class of your pluginspigotResourceId
- SpigotMC Resource ID to get the latest version String from the SpigotMC Web API- Returns:
- UpdateChecker instance being ran
-
init
@Deprecated public static UpdateChecker init(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull String apiLink) Deprecated.UseUpdateChecker(JavaPlugin, UpdateCheckSource, String)
instead.Initializes the UpdateChecker instance. HAS to be called before the UpdateChecker can run.- Parameters:
plugin
- Main class of your pluginapiLink
- HTTP(S) link to a file containing a string with the latest version of your plugin.- Returns:
- UpdateChecker instance being ran
-
isSuppressUpToDateMessage
public boolean isSuppressUpToDateMessage()Returns whether the message "You are using the latest version of" will be suppressed. - Returns:
- True when the message will be suppressed, otherwise false
-
checkEveryXHours
Starts to check every X hours for updates. If a task is already running, it gets cancelled and replaced with the new one, so don't be afraid to use this in your reload function. The first check will also happen after X hours so you might want to call checkNow() too. When you set notifyRequesters to true (default), the Console will get a notification about the check result.- Parameters:
hours
- Amount of hours in between checks- Returns:
- UpdateChecker instance being ran
-
stop
Stops the scheduled update checks. THIS IS NOT NEEDED when calling checkEveryXHours(double) again, as the UpdateChecker will automatically stop its previous task. -
checkNow
Checks for updates now and sends the result to the given list of CommandSenders. Can be null to silently check for updates.- Parameters:
requesters
- CommandSenders to send the result to, or null
-
isUsingLatestVersion
public boolean isUsingLatestVersion()Checks whether the latest found version of the plugin is being used.- Returns:
- true if the latest found version is the one currently in use, otherwise false
-
isOtherVersionNewer
Checks whether one version is really newer than another according to the semantic versioning scheme, including letters.- Parameters:
myVersion
- One version stringotherVersion
- Another version string- Returns:
- true if the other version is indeed newer, otherwise false
-
getOnFail
Gets the task that will run when/after the update check fails.- Returns:
- Task that will run when/after the update check fails.
-
getOnSuccess
Gets the task that will run when/after the update check succeeds.- Returns:
- Task that will run when/after the update check succeeds.
-
checkNow
Checks for updates now and sends the result to the console when notifyRequesters is set to true (default) -
getAppropriateDownloadLinks
Returns a list of applicable Download links.If using the free version and there are links for the free and paid version, element 0 will be the link to the paid version and element will be the link to the free version
If using the paid version, there will be only one element containing the link to the paid version, or, if that is not set, the link to the free version.
If there is no paid version, there will be only one element containing the link to the free version, or, if that is not set, the link to the plus version.
If no download links are set, returns an empty list.
- Returns:
- List of zero to two download links. If the list contains two links, the first element is the paid download link.
-
getChangelogLink
Returns the changelog link- Returns:
- Changelog Link
-
setChangelogLink
Sets a link to your plugin's changelog generated from your plugin's SpigotMC/Polymart Resource ID- Parameters:
resourceId
- Spigot/Polymart Resource ID- Returns:
- UpdateChecker instance being ran
-
setChangelogLink
Sets a link to your plugin's changelog.- Parameters:
link
- Changelog link- Returns:
- UpdateChecker instance being ran
-
getSupportLink
Returns the support link- Returns:
- Support Link
-
setSupportLink
Sets a link to your plugin's support channel.- Parameters:
link
- Support link- Returns:
- UpdateChecker instance being ran
-
getDonationLink
Returns the donation link- Returns:
- Donation link
-
setDonationLink
Sets a link to your plugin's donation website- Parameters:
donationLink
- Donation link- Returns:
- UpdateChecker instance being ran
-
getLastCheckResult
Returns the last successful UpdateCheckResult- Returns:
- Last successful UpdateCheckResult
-
getLatestVersion
Returns the latest version string found by the UpdateChecker, or null if all checks until yet have failed.- Returns:
- Latest version string found by the UpdateChecker
-
getNameFreeVersion
Returns the name/suffix of the free plugin version- Returns:
- Name/suffix of the free plugin version
-
setNameFreeVersion
Sets the name/suffix for the free version's name. E.g. when you set this to "Free", the Download link for the free version will be shown as "Download (Free): [Link]"- Parameters:
nameFreeVersion
- Name/suffix of the free plugin version- Returns:
- UpdateChecker instance being ran
-
getNamePaidVersion
Returns the name/suffix of the paid plugin version- Returns:
- Name/suffix of the paid plugin version
-
setNamePaidVersion
Sets the name/suffix for the paid version's name. E.g. when you set this to "Platinum version", the Download link for the paid version will be shown as "Download (Platinum version): [Link]"- Parameters:
namePaidVersion
- Name/suffix of the paid plugin version- Returns:
- UpdateChecker instance being ran
-
getNotifyPermission
Returns the permission required to receive UpdateChecker messages on join- Returns:
- Permission required to receive UpdateChecker messages on join, or null if not set
-
getPlugin
protected org.bukkit.plugin.Plugin getPlugin()Gets the plugin that instantiated this UpdateChecker instance- Returns:
- Plugin that instantiated this UpdateChecker instance
-
getSpigotUserId
Gets the Spigot User ID of the user who downloaded the plugin if it's a premium plugin, otherwise "%%__USER__%%"- Returns:
- Spigot User ID of the user who downloaded the plugin if it's a premium plugin, otherwise "%%__USER__%%"
-
getUsedVersion
Gets the version string of the currently used plugin version- Returns:
- Version string of the currently used plugin version
-
setUsedVersion
Sets the version string of the currently used plugin version. By default, this is the version defined in the plugin.yml file.- Parameters:
usedVersion
- new version string
-
isCheckedAtLeastOnce
public boolean isCheckedAtLeastOnce()Checks whether the update checker already ran.- Returns:
- True when the update checker already ran, otherwise false
-
isColoredConsoleOutput
public boolean isColoredConsoleOutput()Returns whether colored console output is enabled- Returns:
- true when colored console output is enabled, otherwise false
-
setColoredConsoleOutput
Sets whether or not the used and latest version will be displayed in color in the console- Parameters:
coloredConsoleOutput
- Whether to use color in the console output- Returns:
- UpdateChecker instance being ran
-
isNotifyOpsOnJoin
public boolean isNotifyOpsOnJoin()Returns whether OPs will be notified on join when a new version is available- Returns:
- true when OPs will be notified on join when a new version is available, otherwise false
-
setNotifyOpsOnJoin
Whether or not to inform OPs on join when there is a new version available.- Parameters:
notifyOpsOnJoin
- Whether to inform on OPs on join when there is a new version available- Returns:
- UpdateChecker instance being ran
-
isNotifyRequesters
public boolean isNotifyRequesters()Gets whether the given CommandSenders will be informed about UpdateChecker results- Returns:
- Whether or not to inform given CommandSenders about UpdateChecker results
-
setNotifyRequesters
Whether or not CommandSenders who request an update check will be notified of the result. When you use your own tasks using onSuccess and onFail, consider setting this to false.- Parameters:
notify
- Whether or not to notify given CommandSenders about UpdateChecker results- Returns:
- true when CommandSenders will be notified, otherwise false
-
isUsingPaidVersion
public boolean isUsingPaidVersion()Returns whether the paid version of the plugin is installed.- Returns:
- True if the paid version is used, otherwise false
-
setUsingPaidVersion
Tells the UpdateChecker whether the server already uses the paid version of your plugin. If yes, the downloads to the free version are not shown. You can ignore this if you only offer one version of your plugin. When this value is not set, the Update Checker automatically sets this to true by checking the %%__USER__%% placeholder, see https://www.spigotmc.org/wiki/premium-resource-placeholders-identifiers/- Parameters:
paidVersion
- Whether or not the user is using the paid version of your plugin- Returns:
- UpdateChecker instance being ran
-
onFail
Sets a task that will run when/after the update check has failed.- Parameters:
onFail
- Task that will run when/after the update check has failed.- Returns:
- UpdateChecker instance being ran
-
onSuccess
Sets a task that will run when/after the update check has succeeded.- Parameters:
onSuccess
- Task that will run when/after the update check has succeeded.- Returns:
- UpdateChecker instance being ran
-
setDownloadLink
Sets the download link for your plugin generated from your plugin's SpigotMC/Polymart Resource ID. Use this if there is only one version of your plugin, either only a free or only a paid version.- Parameters:
resourceId
- Spigot/Polymart Resource ID- Returns:
- UpdateChecker instance being ran
-
setDownloadLink
Sets the download link for your plugin. Use this if there is only one version of your plugin, either only a free or only a paid version.- Parameters:
downloadLink
- Download link- Returns:
- UpdateChecker instance being ran
-
suppressUpToDateMessage
Sets whether the message "You are using the latest version of" should be suppressed. Defaults to false - Parameters:
suppress
- Whether to suppress the message "You are using the latest version of" - Returns:
- UpdateChecker instance being ran
-
setFreeDownloadLink
Sets the download link for the free version of your plugin generated from your plugin's SpigotMC/Polymart Resource ID. Use this if there is both, a free and a paid version of your plugin available.- Parameters:
resourceId
- Spigot/Polymart Resource ID of the free version- Returns:
- UpdateChecker instance being ran
-
setFreeDownloadLink
Sets the download link for the free version of your plugin. Use this if there is both, a free and a paid version of your plugin available.- Parameters:
freeDownloadLink
- Download link of the free version- Returns:
- UpdateChecker instance being ran
-
setNotifyByPermissionOnJoin
Sets the permission needed to be informed about UpdateChecker results on join.- Parameters:
permission
- Permission needed to be informed about UpdateChecker results on join- Returns:
- UpdateChecker instance being ran
-
setPaidDownloadLink
Sets the download link for the paid version of your plugin generated from your plugin's SpigotMC/Polymart Resource ID. Use this if there is both, a free and a paid version of your plugin available.- Parameters:
resourceId
- Spigot/Polymart Resource ID of the paid version- Returns:
- UpdateChecker instance being ran
-
setPaidDownloadLink
Sets the download link for the paid version of your plugin. Use this if there is both, a free and a paid version of your plugin available.- Parameters:
link
- Download link of the paid version- Returns:
- UpdateChecker instance being ran
-
setTimeout
Sets the timeout for the HTTP(S) connection in milliseconds. 0 = use Java's default value- Parameters:
timeout
- Timeout in milliseconds, or 0 to use Java's default value
-
setUserAgent
Sets the UserAgent string using a UserAgentBuilder- Parameters:
userAgentBuilder
- UserAgentBuilder instance- Returns:
- UpdateChecker instance being ran
-
setUserAgent
Sets the UserAgent string using plain text- Parameters:
userAgent
- UserAgent string- Returns:
- UpdateChecker instance being ran
-