Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.osiris.autoplug.client.utils.tasks.MyBThreadManager;
import com.osiris.autoplug.client.utils.tasks.UtilsTasks;
import com.osiris.jlib.logger.AL;
import com.osiris.autoplug.client.tasks.updater.plugins.InstalledPluginLoader;

/**
* Listens for input started with .
Expand Down Expand Up @@ -427,7 +428,7 @@ public static boolean installPlugin(String command) throws Exception {
MinecraftPlugin plugin2 = new MinecraftPlugin(new File(pluginsDir + "/" + tempName).getAbsolutePath(),
tempName, "0", "", 0, 0, "");
plugin2.setModrinthId(input.replace(repo, "").trim());
result = new ResourceFinder().findPluginByModrinthId(plugin2, mcVersion);
result = new ResourceFinder().findPluginByModrinthId(new InstalledPluginLoader(updaterConfig.server_software.asString()).getLoaderList(), plugin2, mcVersion);
}
/*
Nothing of the above worked thus do search by name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.time.Instant;
import java.util.List;


public class ModrinthAPI {
Expand All @@ -38,16 +39,15 @@ private boolean isInt(String s) {
*/
public SearchResult searchUpdateMod(InstalledModLoader modLoader, MinecraftMod mod, String mcVersion) {
if (mod.modrinthId == null && !isInt(mod.curseforgeId)) mod.modrinthId = mod.curseforgeId; // Slug
SearchResult res = searchUpdate((modLoader.isFabric || modLoader.isQuilt ? "fabric" : "forge"),mod.modrinthId,mcVersion, mod.installationPath, mod.forceLatest);
SearchResult res = searchUpdate((modLoader.isFabric || modLoader.isQuilt ? List.of("fabric") : List.of("forge")),mod.modrinthId,mcVersion, mod.installationPath, mod.forceLatest);
res.mod = mod;
return res;
}
public SearchResult searchUpdatePlugin(MinecraftPlugin plugin, String mcVersion) { //TODO: probably don't hardcode spigot and papermc
return searchUpdate("spigot\",\"paper", plugin.getModrinthId(), mcVersion, plugin.getInstallationPath(), false);
Comment thread
Zoriot marked this conversation as resolved.
public SearchResult searchUpdatePlugin(List<String> loaders, MinecraftPlugin plugin, String mcVersion) {
return searchUpdate(loaders, plugin.getModrinthId(), mcVersion, plugin.getInstallationPath(), false);
}
private SearchResult searchUpdate(String loader, String id, String mcVersion, String installPath, boolean forceLatest) {

String url = baseUrl + "/project/" + id + "/version?loaders=[\"" + loader + "\"]&game_versions=[\"" + mcVersion + "\"]";
private SearchResult searchUpdate(List<String> loaders, String id, String mcVersion, String installPath, boolean forceLatest) {
String url = baseUrl + "/project/" + id + "/version?loaders=[\"" + String.join( "\",\"", loaders) + "\"]&game_versions=[\"" + mcVersion + "\"]";
url = new UtilsURL().clean(url);
Exception exception = null;
String latest = null;
Expand All @@ -67,7 +67,7 @@ private SearchResult searchUpdate(String loader, String id, String mcVersion, St
if (!isInt(id)) { // Try another url, with slug replaced _ with -
url = baseUrl + "/project/" + id.replace("_", "-")
+ "/version?loaders=[\"" +
loader + "\"]" + (forceLatest ? "" : "&game_versions=[\"" + mcVersion + "\"]");
String.join( "\",\"", loaders) + "\"]" + (forceLatest ? "" : "&game_versions=[\"" + mcVersion + "\"]");
AL.debug(this.getClass(), url);
release = Json.getAsJsonArray(url)
.get(0).getAsJsonObject();
Expand Down
Comment thread
Zoriot marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.osiris.autoplug.client.tasks.updater.plugins;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Locale;
import java.util.Set;

public class InstalledPluginLoader {
public Loader loader;

private static final Set<String> BUNGEE_FORKS = Set.of(
"bungeecord",
"waterfall"
);

private static final Set<String> FOLIA_FORKS = Set.of(
"folia",
"luminolmc",
"canvas",
"shreddedpaper"
);

public InstalledPluginLoader(@NotNull String software) {
String type = software.toLowerCase(Locale.ROOT);

if (type.equals("velocity")) {
loader = Loader.VELOCITY;
} else if (BUNGEE_FORKS.contains(type)) {
loader = Loader.BUNGEECORD;
} else if (FOLIA_FORKS.contains(type)) {
loader = Loader.FOLIA_COMPATIBLE;
} else {
loader = Loader.SPIGOT_AND_FORKS;
}
}

public List<String> getLoaderList() {
switch (loader) {
case VELOCITY:
return List.of("velocity");
case BUNGEECORD:
return List.of("bungeecord", "waterfall");
case SPIGOT_AND_FORKS:
return List.of("spigot", "paper", "purpur", "bukkit");
case FOLIA_COMPATIBLE:
return List.of("folia");
}
return List.of();
}

public enum Loader {
VELOCITY,
BUNGEECORD,
SPIGOT_AND_FORKS,
FOLIA_COMPATIBLE
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.osiris.autoplug.client.tasks.updater.search.spigot.SpigotSearchById;
import com.osiris.autoplug.client.tasks.updater.search.spigot.SpigotSearchByName;

import java.util.List;

public class ResourceFinder {

/**
Expand Down Expand Up @@ -77,8 +79,8 @@ public SearchResult findPluginByBukkitId(MinecraftPlugin plugin) {
sr.plugin = plugin;
return sr;
}
public SearchResult findPluginByModrinthId(MinecraftPlugin plugin, String mcVersion) {
SearchResult sr = new ModrinthAPI().searchUpdatePlugin(plugin, mcVersion);
public SearchResult findPluginByModrinthId(List<String> loaders, MinecraftPlugin plugin, String mcVersion) {
SearchResult sr = new ModrinthAPI().searchUpdatePlugin(loaders, plugin, mcVersion);
sr.plugin = plugin;
return sr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ else if (installedPlugin.getVersion() == null || installedPlugin.getVersion().tr
if (mcVersion == null) updaterConfig.server_updater_version.asString();
if (mcVersion == null) mcVersion = Server.getMCVersion();

List<String> loaders = new InstalledPluginLoader(updaterConfig.server_software.asString()).getLoaderList();

for (MinecraftPlugin pl :
includedPlugins) {
try {
Expand All @@ -325,7 +327,7 @@ else if (installedPlugin.getVersion() == null || installedPlugin.getVersion().tr
} else if (pl.getModrinthId() != null) { // MODRINTH PLUGIN
sizeModrinthPlugins++;
String finalMcVersion = mcVersion;
activeFutures.add(executorService.submit(() -> new ResourceFinder().findPluginByModrinthId(pl, finalMcVersion)));
activeFutures.add(executorService.submit(() -> new ResourceFinder().findPluginByModrinthId(loaders, pl, finalMcVersion)));
} else {
sizeUnknownPlugins++; // UNKNOWN PLUGIN
pl.setIgnoreContentType(true); // TODO temporary workaround for xamazon-json content type curseforge/bukkit issue: https://github.com/Osiris-Team/AutoPlug-Client/issues/109
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;

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

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