Skip to content
Rossi Lorenzo edited this page Feb 27, 2018 · 1 revision

The Update API is a quite simple method to give warnings about your plugin's updates to the clients.

Basic setup

Downloadable plugins setup

You have to get your spigot plugin id, just get the last part of your resource site URL, for example the id of https://www.spigotmc.org/resources/quakecraft.45928/ is quakecraft.45928.
If you want your updates to be downloaded automatically you also have to get the spiget id, to do that go to https://spiget.org/search/, find your plugin and copy the "id" value that is displayed in the json block.

public static final String SPIGOT_ID = "uppercore.45866";
public static final long SPIGET_ID = 45866;
//... inside onEnable
updater = new SpigetUpdateChecker(this, SPIGOT_ID, SPIGET_ID);

And that's it, UpperCore will check the plugin updates and eventually download the plugin for you.

Undownloadable plugins setup

Sometimes Uppercore is unable to download the plugin by himself, that may happen in various situations, the most common one is found in non-free plugins
If that's the case then you just need the spigot id:

public static final String SPIGOT_ID = "quakecraft.45928";
//... inside onEnable
UpdateChecker updater = new SpigotUpdateChecker(this, SPIGOT_ID);

Change version comparison

By default the version comparison is done with point-divided versions (ex. 1.2.3 or 1.12.3.1). Sometimes the version identifier might be parsed differently.
In those cases you have to provide the comparator yourself overriding the default one.

updater.setComparator((strCurrent, strOther) -> {
    int current = Integer.parseInt(strCurrent);
    int other = Integer.parseInt(strOther);
    if      (current == other) return VersionComparator.Result.SAME;
    else if (other > current)  return VersionComparator.Result.NEWER;
    else  /*(current > other)*/return VersionComparator.Result.OLDER;
});

In this example the two versions are integers (for educational reasons, never do that please).
The comparator should return:

  • SAME if the current version is the same as the upstream one
  • NEWER if the other version is newer than the current one
  • OLDER if the current version is the newer between the two of them

Custom download notifier

While downloading a percentage might be displayed signaling how the download is proceding. By default the download notifier prints the progress in both the console and the chat of the one that issued the update command.
If you want to override that you can use

DownloadableUpdateChecker updater = new SpigetUpdateChecker(...);
updater.setDownloadNotifierConstructor(myDownloadNotifierFactory);

This can only be done with Spiget for obvious reasons.

Change the replace method

By default when a new version is found the update file is downloaded and replaces the current plugin jar. Sometimes the update file might be a little bit more complex than that.
There's a built-in update method that unzips a zipped folder containing both the plugin jar, its resources (if found) and the UpperCore jar (if configured).

DownloadableUpdateChecker updater = new SpigetUpdateChecker(...);
updater.setMethod(new UpperResourceZipMethod("MyPlugin", true));

The first parameter is your plugin name (without the .jar ending) while the second parameter must be set to true if the UpperCore.jar file is present.
This can only be done with Spiget for obvious reasons.