Skip to content

Commit 8ec2dfc

Browse files
committed
Support bungeecord & velocity for plugin updates
1 parent fb1ebb0 commit 8ec2dfc

6 files changed

Lines changed: 54 additions & 12 deletions

File tree

src/main/java/com/osiris/autoplug/client/console/Commands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.osiris.autoplug.client.utils.tasks.MyBThreadManager;
5858
import com.osiris.autoplug.client.utils.tasks.UtilsTasks;
5959
import com.osiris.jlib.logger.AL;
60+
import com.osiris.autoplug.client.tasks.updater.plugins.InstalledPluginLoader;
6061

6162
/**
6263
* Listens for input started with .
@@ -427,7 +428,7 @@ public static boolean installPlugin(String command) throws Exception {
427428
MinecraftPlugin plugin2 = new MinecraftPlugin(new File(pluginsDir + "/" + tempName).getAbsolutePath(),
428429
tempName, "0", "", 0, 0, "");
429430
plugin2.setModrinthId(input.replace(repo, "").trim());
430-
result = new ResourceFinder().findPluginByModrinthId(plugin2, mcVersion);
431+
result = new ResourceFinder().findPluginByModrinthId(new InstalledPluginLoader(updaterConfig.server_software.asString()).getLoaderList(), plugin2, mcVersion);
431432
}
432433
/*
433434
Nothing of the above worked thus do search by name

src/main/java/com/osiris/autoplug/client/tasks/updater/mods/ModrinthAPI.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.File;
1919
import java.time.Instant;
20+
import java.util.List;
2021

2122

2223
public class ModrinthAPI {
@@ -38,16 +39,15 @@ private boolean isInt(String s) {
3839
*/
3940
public SearchResult searchUpdateMod(InstalledModLoader modLoader, MinecraftMod mod, String mcVersion) {
4041
if (mod.modrinthId == null && !isInt(mod.curseforgeId)) mod.modrinthId = mod.curseforgeId; // Slug
41-
SearchResult res = searchUpdate((modLoader.isFabric || modLoader.isQuilt ? "fabric" : "forge"),mod.modrinthId,mcVersion, mod.installationPath, mod.forceLatest);
42+
SearchResult res = searchUpdate((modLoader.isFabric || modLoader.isQuilt ? List.of("fabric") : List.of("forge")),mod.modrinthId,mcVersion, mod.installationPath, mod.forceLatest);
4243
res.mod = mod;
4344
return res;
4445
}
45-
public SearchResult searchUpdatePlugin(MinecraftPlugin plugin, String mcVersion) { //TODO: probably don't hardcode spigot and papermc
46-
return searchUpdate("spigot\",\"paper", plugin.getModrinthId(), mcVersion, plugin.getInstallationPath(), false);
46+
public SearchResult searchUpdatePlugin(List<String> loaders, MinecraftPlugin plugin, String mcVersion) {
47+
return searchUpdate(loaders, plugin.getModrinthId(), mcVersion, plugin.getInstallationPath(), false);
4748
}
48-
private SearchResult searchUpdate(String loader, String id, String mcVersion, String installPath, boolean forceLatest) {
49-
50-
String url = baseUrl + "/project/" + id + "/version?loaders=[\"" + loader + "\"]&game_versions=[\"" + mcVersion + "\"]";
49+
private SearchResult searchUpdate(List<String> loaders, String id, String mcVersion, String installPath, boolean forceLatest) {
50+
String url = baseUrl + "/project/" + id + "/version?loaders=[\"" + String.join( "\",\"", loaders) + "\"]&game_versions=[\"" + mcVersion + "\"]";
5151
url = new UtilsURL().clean(url);
5252
Exception exception = null;
5353
String latest = null;
@@ -67,7 +67,7 @@ private SearchResult searchUpdate(String loader, String id, String mcVersion, St
6767
if (!isInt(id)) { // Try another url, with slug replaced _ with -
6868
url = baseUrl + "/project/" + id.replace("_", "-")
6969
+ "/version?loaders=[\"" +
70-
loader + "\"]" + (forceLatest ? "" : "&game_versions=[\"" + mcVersion + "\"]");
70+
String.join( "\",\"", loaders) + "\"]" + (forceLatest ? "" : "&game_versions=[\"" + mcVersion + "\"]");
7171
AL.debug(this.getClass(), url);
7272
release = Json.getAsJsonArray(url)
7373
.get(0).getAsJsonObject();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.osiris.autoplug.client.tasks.updater.plugins;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.List;
6+
7+
public class InstalledPluginLoader {
8+
public Loader loader;
9+
10+
public InstalledPluginLoader(@NotNull String software) {
11+
if (software.equalsIgnoreCase("velocity")) {
12+
loader = Loader.VELOCITY;
13+
} else if (software.equalsIgnoreCase("bungeecord")) {
14+
loader = Loader.BUNGEECORD;
15+
} else loader = Loader.SPIGOT_AND_FORKS;
16+
}
17+
18+
public List<String> getLoaderList() {
19+
switch (loader) {
20+
case VELOCITY:
21+
return List.of("velocity");
22+
case BUNGEECORD:
23+
return List.of("bungeecord", "waterfall");
24+
case SPIGOT_AND_FORKS:
25+
return List.of("spigot", "paper", "purpur");
26+
}
27+
return List.of();
28+
}
29+
30+
public enum Loader {
31+
VELOCITY,
32+
BUNGEECORD,
33+
SPIGOT_AND_FORKS
34+
}
35+
36+
}

src/main/java/com/osiris/autoplug/client/tasks/updater/plugins/ResourceFinder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.osiris.autoplug.client.tasks.updater.search.spigot.SpigotSearchById;
2323
import com.osiris.autoplug.client.tasks.updater.search.spigot.SpigotSearchByName;
2424

25+
import java.util.List;
26+
2527
public class ResourceFinder {
2628

2729
/**
@@ -77,8 +79,8 @@ public SearchResult findPluginByBukkitId(MinecraftPlugin plugin) {
7779
sr.plugin = plugin;
7880
return sr;
7981
}
80-
public SearchResult findPluginByModrinthId(MinecraftPlugin plugin, String mcVersion) {
81-
SearchResult sr = new ModrinthAPI().searchUpdatePlugin(plugin, mcVersion);
82+
public SearchResult findPluginByModrinthId(List<String> loaders, MinecraftPlugin plugin, String mcVersion) {
83+
SearchResult sr = new ModrinthAPI().searchUpdatePlugin(loaders, plugin, mcVersion);
8284
sr.plugin = plugin;
8385
return sr;
8486
}

src/main/java/com/osiris/autoplug/client/tasks/updater/plugins/TaskPluginsUpdater.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ else if (installedPlugin.getVersion() == null || installedPlugin.getVersion().tr
302302
if (mcVersion == null) updaterConfig.server_updater_version.asString();
303303
if (mcVersion == null) mcVersion = Server.getMCVersion();
304304

305+
List<String> loaders = new InstalledPluginLoader(updaterConfig.server_software.asString()).getLoaderList();
306+
305307
for (MinecraftPlugin pl :
306308
includedPlugins) {
307309
try {
@@ -325,7 +327,7 @@ else if (installedPlugin.getVersion() == null || installedPlugin.getVersion().tr
325327
} else if (pl.getModrinthId() != null) { // MODRINTH PLUGIN
326328
sizeModrinthPlugins++;
327329
String finalMcVersion = mcVersion;
328-
activeFutures.add(executorService.submit(() -> new ResourceFinder().findPluginByModrinthId(pl, finalMcVersion)));
330+
activeFutures.add(executorService.submit(() -> new ResourceFinder().findPluginByModrinthId(loaders, pl, finalMcVersion)));
329331
} else {
330332
sizeUnknownPlugins++; // UNKNOWN PLUGIN
331333
pl.setIgnoreContentType(true); // TODO temporary workaround for xamazon-json content type curseforge/bukkit issue: https://github.com/Osiris-Team/AutoPlug-Client/issues/109

src/test/java/com/osiris/autoplug/client/tasks/updater/TestPluginUpdaters.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.junit.jupiter.api.Test;
1717

1818
import java.io.IOException;
19+
import java.util.List;
1920

2021
import static org.junit.jupiter.api.Assertions.assertSame;
2122

@@ -36,7 +37,7 @@ void testModrinth() throws IOException {
3637
UtilsTest.init();
3738
MinecraftPlugin pl = new MinecraftPlugin("./plugins/", "BMMarker", "0.0.0", "Miraculixx", 0, 0, null);
3839
pl.modrinthId = "a8UoyV2h";
39-
SearchResult sr = new ModrinthAPI().searchUpdatePlugin(pl, "1.21.1");
40+
SearchResult sr = new ModrinthAPI().searchUpdatePlugin(List.of("paper"), pl, "1.21.1");
4041
assertSame(SearchResult.Type.UPDATE_AVAILABLE, sr.type);
4142
}
4243
}

0 commit comments

Comments
 (0)