Skip to content

Update Checking

SirBlobman edited this page Apr 29, 2023 · 3 revisions

If your plugin is uploaded to SpigotMC or Hangar, you can use BlueSlimeCore to check for newer versions.

SpigotUpdateManager

1. Find your resource identifier.

To find your resource identifier number, first navigate to the overview page for your plugin on SpigotMC. We will use CombatLogX as an example. Once the page has loaded, review the address URL for your plugin. You will notice the name of your plugin, then a period, then some numbers. The numbers are your resource identifier. In our example, the resource identifier for CombatLogX is 31689.

2. Create a method to register your plugin with the update checker.

Add the following code to your main plugin class. Your main class is the java file that extends JavaPlugin.

import com.github.sirblobman.api.core.CorePlugin;
import com.github.sirblobman.api.update.SpigotUpdateManager;

@Override
public void onEnable() {
    // Your other plugin code....

    registerUpdateChecker();
}

private void registerUpdateChecker() {
    long resourceId = 31689; // Replace this number with your plugin's identifier.
    CorePlugin corePlugin = JavaPlugin.getPlugin(CorePlugin.class);
    SpigotUpdateManager<?> updateManager = corePlugin.getSpigotUpdateManager();
    updateManager.addResource(this, resourceId);
}

3. Finished

BlueSlimeCore will now check for updates when a server using your plugin is started up. Here is an example output log. Server owners can disable the update checker by setting update-checker: false in the BlueSlimeCore config.yml file.

[BlueSlimeCore] [Update Checker] A possible update was found for plugin 'CombatLogX'.
[BlueSlimeCore] [Update Checker] Current Version: 11.1.0.2.915
[BlueSlimeCore] [Update Checker] New Version: 11.1.0.3.929
[BlueSlimeCore] [Update Checker] Download Link: https://www.spigotmc.org/resources/31689/

HangarUpdateManager

1. Find your resource author and project name

To find your resource identifier number, first navigate to the hangar page for your plugin on Hangar. We will use BlueSlimeCore as an example. Once the page has loaded, review the address URL for your plugin. You will notice the author and project name. The author is the first part of the URL, the project name is the second part. In our example, the author name is 'SirBlobman' and the project name is 'BlueSlimeCore'

2. Create a method to register your plugin with the update checker.

Add the following code to your main plugin class. Your main class is the java file that extends JavaPlugin.

import com.github.sirblobman.api.core.CorePlugin;
import com.github.sirblobman.api.update.HangarInfo;
import com.github.sirblobman.api.update.HangarUpdateManager;

@Override
public void onEnable() {
    // Your other plugin code....

    registerUpdateChecker();
}

private void registerUpdateChecker() {
    String author = "SirBlobman"; // Replace with your author
    String projectName = "BlueSlimeCore"; // Replace with your project name
    HangarInfo hangarInfo = new HangarInfo(author, projectName);

    CorePlugin corePlugin = JavaPlugin.getPlugin(CorePlugin.class);
    HangarUpdateManager<?> hangarUpdateManager = corePlugin.getHangarUpdateManager();
    hangarUpdateManager.addProject(this, hangarInfo);
}

3. Finished

BlueSlimeCore will now check for updates when a server using your plugin is started up. Here is an example output log. Server owners can disable the update checker by setting update-checker: false in the BlueSlimeCore config.yml file.

[Blue Slime Core] [Update Checker] Found a possible update for plugin 'BlueSlimeCore'.
[Blue Slime Core] [Update Checker] Local Version: 2.9.0.Beta-331
[Blue Slime Core] [Update Checker] Remote Version: 2.7.0.303
[Blue Slime Core] [Update Checker] Download Link: https://hangar.papermc.io/SirBlobman/BlueSlimeCore

Clone this wiki locally