Skip to content

Instantly share code, notes, and snippets.

@hyperdefined
Last active February 26, 2024 00:29
Show Gist options
  • Save hyperdefined/ff223e472daee2f1fdbd2626a247b937 to your computer and use it in GitHub Desktop.
Save hyperdefined/ff223e472daee2f1fdbd2626a247b937 to your computer and use it in GitHub Desktop.
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);


public void checkForUpdates() {
        GitHubReleaseAPI api;
        try {
            api = new GitHubReleaseAPI("repo", "hyperdefined");
        } catch (IOException e) {
            logger.warning("Unable to check updates!");
            e.printStackTrace();
            return;
        }
        GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion());
        GitHubRelease latest = api.getLatestVersion();
        if (current == null) {
            logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!");
            return;
        }
        int buildsBehind = api.getBuildsBehind(current);
        if (buildsBehind == 0) {
            logger.info("You are running the latest version.");
        } else {
            logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
        }
    }
<dependency>
    <groupId>lol.hyper</groupId>
    <artifactId>github-release-api</artifactId>
    <version>1.0.0</version>
</dependency>
<plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>auto-clean</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment