-
Notifications
You must be signed in to change notification settings - Fork 32
Support multiple loaders for plugin updates via Modrinth API #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| import java.io.File; | ||
| import java.time.Instant; | ||
| import java.util.List; | ||
|
|
||
|
|
||
| public class ModrinthAPI { | ||
|
|
@@ -38,16 +39,16 @@ 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); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Osiris-Team Plugin updating worked only for spigot/paper because it was hardcoded here. Now it also works for velocity and specific paper forks like Folia. It get's the loader either via
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay it seems counterintuitive to be able to provide multiple mod loaders from a user-perspective, because usually the server only has one loader, thus I'd like to keep these options away from the user and under the hood as API implementation details. Instead it would be great to enhance the automatic detection in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you want a general logic it can be complicated quite quickly, e.g you would have only supply folia for folia, Purpur > Paper > Spigot for Purpur. It would be nice when it correctly updates FAWE through with the paper build on paper. What's your (simple) idea for that?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also wonder if you are open in merging that and creating an issue for moving that to internal again. With proper handling
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Zoriot I'd like to see this implemented in this PR directly 👍. I'm not sure the implementation is that complicated. We could even remove or simplify the auto detection to instead just check what the user entered in the server-updater software section of the config, and use that to determine the compatible mod loader.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understandable. What's your proposed solution to make preferred option/handling possible? Add a (optional) fiel to the field where we safe the data about plugins? E.g. https://modrinth.com/plugin/fastasyncworldedit/versions needs that, on a Paper (Fork) it should always install the paper version not the spigot version.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Zoriot Why not just install the best match automatically? For example If the server is paper we prefer paper mod/plugin builds and only fallback on spigot if needed. |
||
| 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) { | ||
| private SearchResult searchUpdate(List<String> loaders, String id, String mcVersion, String installPath, boolean forceLatest) { | ||
|
|
||
| String url = baseUrl + "/project/" + id + "/version?loaders=[\"" + loader + "\"]&game_versions=[\"" + mcVersion + "\"]"; | ||
| String url = baseUrl + "/project/" + id + "/version?loaders=[\"" + String.join( "\",\"", loaders) + "\"]&game_versions=[\"" + mcVersion + "\"]"; | ||
| url = new UtilsURL().clean(url); | ||
| Exception exception = null; | ||
| String latest = null; | ||
|
|
@@ -67,7 +68,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(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an API endpoint that returns the available loaders that we can include here, so the user can view a valid list of available loaders to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is https://api.modrinth.com/v3/tag/loader but without parsing & filtering it's not shown nicely.
Probably specifying manually would make sense if we go that route