Skip to content

Commit dc3de0b

Browse files
authored
Merge pull request #77 from OakLoaf/v2.0
Resolves #74
2 parents 74f177d + 65adc6b commit dc3de0b

30 files changed

+523
-259
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.lushplugins.pluginupdater.api.exception;
2+
3+
public class InvalidVersionFormatException extends RuntimeException {
4+
5+
public InvalidVersionFormatException(String message) {
6+
super(message);
7+
}
8+
9+
public InvalidVersionFormatException(String message, Throwable cause) {
10+
super(message, cause);
11+
}
12+
}

api/src/main/java/org/lushplugins/pluginupdater/api/platform/Platform.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import java.util.concurrent.Callable;
66

77
/**
8-
* @param rateLimit The endpoint's rate limit per second. Set to {@code -1} to remove limit.
9-
* @param updater
10-
* @param platformDataConstructor
8+
* @param rateLimit The endpoint's rate limit per second, set to {@code -1} to remove limit
119
*/
1210
public record Platform(
1311
int rateLimit,
1412
Callable<VersionChecker> updater,
1513
PlatformRegistry.PlatformDataConstructor platformDataConstructor
1614
) {
15+
1716
public boolean hasRateLimit() {
1817
return this.rateLimit > 0;
1918
}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
package org.lushplugins.pluginupdater.api.platform;
22

3+
import org.lushplugins.pluginupdater.api.version.comparator.SemVerComparator;
4+
import org.lushplugins.pluginupdater.api.version.comparator.VersionComparator;
5+
36
public abstract class PlatformData {
47
private final String name;
8+
private final VersionComparator defaultComparator;
59

6-
public PlatformData(String name) {
10+
public PlatformData(String name, VersionComparator defaultComparator) {
711
this.name = name;
12+
this.defaultComparator = defaultComparator;
13+
}
14+
15+
public PlatformData(String name) {
16+
this(name, SemVerComparator.INSTANCE);
817
}
918

1019
public String getName() {
1120
return name;
1221
}
22+
23+
public VersionComparator getDefaultComparator() {
24+
return defaultComparator;
25+
}
1326
}

api/src/main/java/org/lushplugins/pluginupdater/api/platform/github/GithubData.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
public class GithubData extends PlatformData {
77
private static final String NAME = "github";
88

9-
private final String githubRepo;
9+
private final String repo;
1010

11-
public GithubData(ConfigurationSection configurationSection) {
11+
public GithubData(ConfigurationSection config) {
1212
super(NAME);
13-
this.githubRepo = configurationSection.getString("github-repo");
13+
this.repo = config.getString("github-repo");
1414
}
1515

16-
public GithubData(String githubRepo) {
16+
public GithubData(String repo) {
1717
super(NAME);
18-
this.githubRepo = githubRepo;
18+
this.repo = repo;
1919
}
2020

21-
public String getGithubRepo() {
22-
return githubRepo;
21+
public String getRepo() {
22+
return repo;
2323
}
2424
}

api/src/main/java/org/lushplugins/pluginupdater/api/platform/github/GithubVersionChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public String getDownloadUrl(PluginData pluginData, PlatformData platformData) t
3636
}
3737

3838
private JsonObject getLatestRelease(PluginData pluginData, GithubData githubData) throws IOException, InterruptedException {
39-
HttpResponse<String> response = HttpUtil.sendRequest(String.format("%s/repos/%s/releases/latest", UpdaterConstants.Endpoint.GITHUB, githubData.getGithubRepo()));
39+
HttpResponse<String> response = HttpUtil.sendRequest(String.format("%s/repos/%s/releases/latest", UpdaterConstants.Endpoint.GITHUB, githubData.getRepo()));
4040

4141
if (response.statusCode() != 200) {
4242
throw new IllegalStateException("Received invalid response code (%s) whilst checking '%s' for updates.".formatted(response.statusCode(), pluginData.getPluginName()));

api/src/main/java/org/lushplugins/pluginupdater/api/platform/hangar/HangarData.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
public class HangarData extends PlatformData {
77
private static final String NAME = "hangar";
88

9-
private final String hangarProjectSlug;
9+
private final String projectSlug;
1010

11-
public HangarData(ConfigurationSection configurationSection) {
11+
public HangarData(ConfigurationSection config) {
1212
super(NAME);
13-
this.hangarProjectSlug = configurationSection.getString("hangar-project-slug");
13+
this.projectSlug = config.getString("hangar-project-slug");
1414
}
1515

1616
/**
17-
* @param hangarProjectSlug Your Modrinth Project Slug
17+
* @param projectSlug The Hangar Project Slug
1818
*/
19-
public HangarData(String hangarProjectSlug) {
19+
public HangarData(String projectSlug) {
2020
super(NAME);
21-
this.hangarProjectSlug = hangarProjectSlug;
21+
this.projectSlug = projectSlug;
2222
}
2323

24-
public String getHangarProjectSlug() {
25-
return hangarProjectSlug;
24+
public String getProjectSlug() {
25+
return projectSlug;
2626
}
2727
}

api/src/main/java/org/lushplugins/pluginupdater/api/platform/hangar/HangarVersionChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public String getLatestVersion(PluginData pluginData, PlatformData platformData)
1717
return null;
1818
}
1919

20-
HttpResponse<String> response = HttpUtil.sendRequest(String.format("%s/projects/%s/latestrelease", UpdaterConstants.Endpoint.HANGAR, hangarData.getHangarProjectSlug()));
20+
HttpResponse<String> response = HttpUtil.sendRequest(String.format("%s/projects/%s/latestrelease", UpdaterConstants.Endpoint.HANGAR, hangarData.getProjectSlug()));
2121

2222
if (response.statusCode() != 200) {
2323
throw new IllegalStateException("Received invalid response code (" + response.statusCode() + ") whilst checking '" + pluginData.getPluginName() + "' for updates.");
@@ -29,7 +29,7 @@ public String getLatestVersion(PluginData pluginData, PlatformData platformData)
2929
@Override
3030
public String getDownloadUrl(PluginData pluginData, PlatformData platformData) {
3131
return platformData instanceof HangarData hangarData ?
32-
String.format("%s/projects/%s/versions/%s/PAPER/download", UpdaterConstants.Endpoint.HANGAR, hangarData.getHangarProjectSlug(), pluginData.getLatestVersion()) :
32+
String.format("%s/projects/%s/versions/%s/PAPER/download", UpdaterConstants.Endpoint.HANGAR, hangarData.getProjectSlug(), pluginData.getLatestVersion()) :
3333
null;
3434
}
3535
}

api/src/main/java/org/lushplugins/pluginupdater/api/platform/modrinth/ModrinthData.java

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,78 +11,67 @@
1111
public class ModrinthData extends PlatformData {
1212
private static final String NAME = "modrinth";
1313

14-
private final String modrinthProjectId;
15-
private final @Nullable List<String> versionTypes;
16-
private final boolean featuredOnly;
14+
private final String projectId;
15+
private final @Nullable List<String> releaseChannels;
1716

18-
public ModrinthData(ConfigurationSection configurationSection) {
17+
public ModrinthData(ConfigurationSection config) {
1918
super(NAME);
20-
this.modrinthProjectId = configurationSection.getString("modrinth-project-id");
19+
this.projectId = config.getString("modrinth-project-id");
2120

22-
if (configurationSection.isString("channels")) {
23-
this.versionTypes = Collections.singletonList(configurationSection.getString("channels", "release").toLowerCase());
24-
} else if (configurationSection.isList("channels")) {
25-
this.versionTypes = configurationSection.getStringList("channels").stream()
21+
if (config.isString("channels")) {
22+
this.releaseChannels = Collections.singletonList(config.getString("channels", ReleaseChannel.RELEASE).toLowerCase());
23+
} else if (config.isList("channels")) {
24+
this.releaseChannels = config.getStringList("channels").stream()
2625
.map(String::toLowerCase)
2726
.toList();
2827
} else {
29-
this.versionTypes = null;
28+
this.releaseChannels = ReleaseChannel.ALL;
3029
}
31-
32-
this.featuredOnly = configurationSection.getBoolean("featured-only");
3330
}
3431

3532
/**
36-
* @param modrinthProjectId The Modrinth project id
37-
* @param versionTypes Which version types to filter (Set to 'null' to not filter)
38-
* @param featuredOnly Whether to filter updates by Featured only
33+
* @param projectId The Modrinth project id
34+
* @param releaseChannels Which release channels to filter, {@code null} will include all release channels
3935
*/
40-
public ModrinthData(String modrinthProjectId, @Nullable List<String> versionTypes, boolean featuredOnly) {
36+
public ModrinthData(String projectId, @Nullable List<String> releaseChannels) {
4137
super(NAME);
42-
this.modrinthProjectId = modrinthProjectId;
43-
this.versionTypes = versionTypes;
44-
this.featuredOnly = featuredOnly;
38+
this.projectId = projectId;
39+
this.releaseChannels = releaseChannels;
4540
}
4641

4742
/**
48-
* @param modrinthProjectId The Modrinth project id
49-
* @param versionType Which version type to filter (Set to 'null' to not filter)
50-
* @param featuredOnly Whether to filter updates by Featured only
43+
* @param projectId The Modrinth project id
44+
* @param releaseChannel Which release channel to filter, {@code null} will include all release channels
5145
*/
52-
public ModrinthData(String modrinthProjectId, @Nullable String versionType, boolean featuredOnly) {
53-
this(modrinthProjectId, Collections.singletonList(versionType), featuredOnly);
46+
public ModrinthData(String projectId, @Nullable String releaseChannel) {
47+
this(projectId, Collections.singletonList(releaseChannel));
5448
}
5549

5650
/**
57-
* @param modrinthProjectId The Modrinth project id
58-
* @param featuredOnly Whether to filter updates by Featured only
51+
* @param projectId The Modrinth project id
5952
*/
60-
public ModrinthData(String modrinthProjectId, boolean featuredOnly) {
61-
this(modrinthProjectId, VersionType.ALL, featuredOnly);
53+
public ModrinthData(String projectId) {
54+
this(projectId, ReleaseChannel.ALL);
6255
}
6356

64-
public String getModrinthProjectId() {
65-
return modrinthProjectId;
57+
public String getProjectId() {
58+
return projectId;
6659
}
6760

6861
public boolean specifiesVersionType() {
69-
return this.versionTypes != null;
62+
return this.releaseChannels != null;
7063
}
7164

7265
@ApiStatus.Internal
7366
public @Nullable String getVersionType() {
74-
return this.versionTypes != null ? this.versionTypes.get(0) : null;
75-
}
76-
77-
public @Nullable List<String> getVersionTypes() {
78-
return versionTypes;
67+
return this.releaseChannels != null ? this.releaseChannels.get(0) : null;
7968
}
8069

81-
public boolean includeFeaturedOnly() {
82-
return featuredOnly;
70+
public @Nullable List<String> getReleaseChannels() {
71+
return releaseChannels;
8372
}
8473

85-
public static class VersionType {
74+
public static class ReleaseChannel {
8675
public static final List<String> ALL = null;
8776
public static final String RELEASE = "release";
8877
public static final String BETA = "beta";

api/src/main/java/org/lushplugins/pluginupdater/api/platform/modrinth/ModrinthVersionChecker.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@ public String getDownloadUrl(PluginData pluginData, PlatformData platformData) t
3535
}
3636

3737
private JsonArray getVersions(PluginData pluginData, ModrinthData modrinthData) throws IOException, InterruptedException {
38-
StringBuilder uriBuilder = new StringBuilder(String.format("%s/project/%s/version", UpdaterConstants.Endpoint.MODRINTH, modrinthData.getModrinthProjectId()))
39-
.append("?loaders=[%22bukkit%22,%22spigot%22,%22paper%22,%22purpur%22,%22folia%22]");
38+
StringBuilder uriBuilder = new StringBuilder(String.format("%s/project/%s/version", UpdaterConstants.Endpoint.MODRINTH, modrinthData.getProjectId()))
39+
.append("?loaders=[%22bukkit%22,%22spigot%22,%22paper%22,%22purpur%22,%22folia%22]")
40+
.append("&include_changelog=false");
4041

4142
if (modrinthData.specifiesVersionType()) {
4243
uriBuilder.append("&version_type=").append(modrinthData.getVersionType());
4344
}
4445

45-
if (modrinthData.includeFeaturedOnly()) {
46-
uriBuilder.append("&featured=true");
47-
}
48-
4946
HttpResponse<String> response = HttpUtil.sendRequest(uriBuilder.toString());
5047

5148
if (response.statusCode() != 200) {

api/src/main/java/org/lushplugins/pluginupdater/api/platform/spigot/SpigotData.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
public class SpigotData extends PlatformData {
77
private static final String NAME = "spigot";
88

9-
private final String spigotResourceId;
9+
private final String resourceId;
1010

11-
public SpigotData(ConfigurationSection configurationSection) {
11+
public SpigotData(ConfigurationSection config) {
1212
super(NAME);
13-
spigotResourceId = configurationSection.getString("spigot-resource-id");
13+
resourceId = config.getString("spigot-resource-id");
1414
}
1515

1616
/**
17-
* @param spigotResourceId Your Spigot Resource Id
17+
* @param resourceId The Spigot Resource Id
1818
*/
19-
public SpigotData(String spigotResourceId) {
19+
public SpigotData(String resourceId) {
2020
super(NAME);
21-
this.spigotResourceId = spigotResourceId;
21+
this.resourceId = resourceId;
2222
}
2323

24-
public String getSpigotResourceId() {
25-
return spigotResourceId;
24+
public String getResourceId() {
25+
return resourceId;
2626
}
2727
}

0 commit comments

Comments
 (0)