Skip to content

Commit

Permalink
add getDownloadLink API method
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJeterLP committed Dec 26, 2022
1 parent 5cff162 commit e4beddd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Spigot-Updatechecker [![Build Status](https://github.com/TheJeterLP/Spigot-Updatechecker/actions/workflows/main.yml/badge.svg)](https://github.com/TheJeterLP/Spigot-Updatechecker/actions/workflows/main.yml)

Updatechecker for SpigotMC hosted plugins.

For usage see TheJeterLP/ChatEx
25 changes: 13 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.jeter</groupId>
<artifactId>Spigot-Updatechecker</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<scm>
<connection>scm:git:[email protected]:TheJeterLP/Spigot-Updatechecker.git</connection>
<url>scm:git:[email protected]:TheJeterLP/Spigot-Updatechecker.git</url>
<developerConnection>scm:git:[email protected]:TheJeterLP/Spigot-Updatechecker.git</developerConnection>
</scm>

<build>
<defaultGoal>clean install</defaultGoal>
<finalName>${project.name}</finalName>
Expand All @@ -27,27 +28,27 @@
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
<includes>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</resources>
</build>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependency>
</dependencies>

</project>
13 changes: 13 additions & 0 deletions src/main/java/de/jeter/updatechecker/GitHubUpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class GitHubUpdateChecker extends UpdateChecker {
Expand All @@ -16,6 +17,7 @@ public class GitHubUpdateChecker extends UpdateChecker {
private String url;
private Result result = Result.NO_UPDATE;
private String version;
private URL downloadLink;

/**
* Initiates and runs a new UpdateChecker gaining GitHub releases
Expand All @@ -27,6 +29,7 @@ public class GitHubUpdateChecker extends UpdateChecker {
public GitHubUpdateChecker(JavaPlugin plugin, String repoOwner, String repository) {
this.plugin = plugin;
this.url = "https://github.com/" + repoOwner + "/" + repository + "/releases/latest";
this.downloadLink = null;
super.init(plugin);
}

Expand All @@ -45,6 +48,16 @@ public String getUpdateMessage() {
return "Update found! Please consider downloading the newest version from " + url;
}

@Override
public URL getDownloadLink() {
try {
return new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}

@Override
protected void checkForUpdate() {
try {
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/de/jeter/updatechecker/SpigotUpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class SpigotUpdateChecker extends UpdateChecker {

private final JavaPlugin plugin;
private final int id;
private Result result = Result.NO_UPDATE;
private String version;
private static final String VERSIONS = "/versions/latest";
private static final String API_RESOURCE = "https://api.spiget.org/v2/resources/";
private final JavaPlugin plugin;
private final int id;
private final String USER_AGENT;
private final String url;
private Result result = Result.NO_UPDATE;
private String version;

public SpigotUpdateChecker(JavaPlugin plugin, int id) {
this.plugin = plugin;
Expand All @@ -44,6 +45,16 @@ public String getUpdateMessage() {
return "Update found! Please consider installing the latest version from " + url;
}

@Override
public URL getDownloadLink() {
try {
return new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}

@Override
protected void checkForUpdate() {
try {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/de/jeter/updatechecker/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.bukkit.plugin.java.JavaPlugin;

import java.net.URL;

public abstract class UpdateChecker {

/**
Expand All @@ -26,6 +28,13 @@ public abstract class UpdateChecker {
*/
public abstract String getUpdateMessage();

/**
* Gets the URL where the new version can be downloaded
*
* @return
*/
public abstract URL getDownloadLink();

/**
* Runs the actual checker itself.
*/
Expand Down

0 comments on commit e4beddd

Please sign in to comment.