Skip to content

Commit

Permalink
7.2.26
Browse files Browse the repository at this point in the history
- Also checks for quilt when trying to determine installed mod loader, which fixes wrongfully falling back on forge.
  • Loading branch information
Osiris-Team committed May 26, 2023
1 parent 7a6ff9e commit f119799
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.osiris.autoplug.client</groupId>
<artifactId>autoplug-client</artifactId>
<version>7.2.25</version>
<version>7.2.26</version>
<packaging>jar</packaging>

<name>AutoPlug-Client</name>
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/osiris/autoplug/client/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,12 @@
public final class Server {

private static final AtomicBoolean isKill = new AtomicBoolean(false);
/**
* True if current dir contains the .fabric folder.
*/
public static boolean isFabric;
@Nullable
public static AsyncInputStream ASYNC_SERVER_IN;
private static Process process;
private static Thread threadServerAliveChecker;
private static boolean colorServerLog;

static {
for (File f :
new File(System.getProperty("user.dir")).listFiles()) {
if (f.getName().equals(".fabric")) {
isFabric = true;
break;
}
}
}

public static File getServerExecutable() throws NotLoadedException, YamlReaderException, YamlWriterException, IOException, IllegalKeyException, DuplicateKeyException, IllegalListException {
File serverExe = null;
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.osiris.autoplug.client.Server;
import com.osiris.autoplug.client.tasks.updater.search.SearchResult;
import com.osiris.autoplug.client.utils.UtilsURL;
import com.osiris.jlib.logger.AL;
Expand All @@ -37,15 +36,15 @@ public class CurseForgeAPI {
/**
* Requires curseforgeId not null.
*/
public SearchResult searchUpdate(MinecraftMod mod, String mcVersion, boolean checkNameForModLoader) {
public SearchResult searchUpdate(InstalledModLoader modLoader, MinecraftMod mod, String mcVersion, boolean checkNameForModLoader) {
boolean isIdNumber = isInt(mod.curseforgeId);
String url;
Exception exception = null;
String latest = null;
String type = ".jar";
String downloadUrl = null;
byte code = 0;
String modInfo = mod.getName() + "/" + (Server.isFabric ? "fabric" : "forge");
String modInfo = mod.getName() + "/" + (modLoader.isFabric || modLoader.isQuilt ? "fabric" : "forge");
try {
if (!isIdNumber) { // Determine project id, since we only got slug
try {
Expand Down Expand Up @@ -97,7 +96,7 @@ public SearchResult searchUpdate(MinecraftMod mod, String mcVersion, boolean che
}

// If the release has no fabric or forge tag, then we expect only forge support.
if (Server.isFabric) { // FABRIC
if (modLoader.isFabric || modLoader.isQuilt) { // FABRIC or QUILT
for (JsonElement el : tempRelease.get("gameVersions").getAsJsonArray()) { // check if game versions contain fabric
if (StringUtils.containsIgnoreCase(el.getAsString(), "fabric")) {
isModLoaderCompatible = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
* of the MIT-License. Consult the "LICENSE" file for details.
*/

package com.osiris.autoplug.client.tasks.updater.mods;

public class InstalledModLoader {
public boolean isForge, isFabric, isQuilt;

public InstalledModLoader(boolean isForge, boolean isFabric, boolean isQuilt) {
this.isForge = isForge;
this.isFabric = isFabric;
this.isQuilt = isQuilt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package com.osiris.autoplug.client.tasks.updater.mods;

import com.google.gson.JsonObject;
import com.osiris.autoplug.client.Server;
import com.osiris.autoplug.client.tasks.updater.search.SearchResult;
import com.osiris.autoplug.client.utils.UtilsURL;
import com.osiris.jlib.json.Json;
Expand All @@ -36,10 +35,10 @@ private boolean isInt(String s) {
* Requires a modrithId (chars or number), or curseforgeId (no number, but chars).
* If the id contains chars its usually the mods slugs.
*/
public SearchResult searchUpdate(MinecraftMod mod, String mcVersion) {
public SearchResult searchUpdate(InstalledModLoader modLoader, MinecraftMod mod, String mcVersion) {
if (mod.modrinthId == null && !isInt(mod.curseforgeId)) mod.modrinthId = mod.curseforgeId; // Slug
String url = baseUrl + "/project/" + mod.modrinthId + "/version?loaders=[\"" +
(Server.isFabric ? "fabric" : "forge") + "\"]&game_versions=[\"" + mcVersion + "\"]";
(modLoader.isFabric || modLoader.isQuilt ? "fabric" : "forge") + "\"]&game_versions=[\"" + mcVersion + "\"]";
url = new UtilsURL().clean(url);
Exception exception = null;
String latest = null;
Expand All @@ -59,7 +58,7 @@ public SearchResult searchUpdate(MinecraftMod mod, String mcVersion) {
if (!isInt(mod.modrinthId)) { // Try another url, with slug replaced _ with -
url = baseUrl + "/project/" + mod.modrinthId.replace("_", "-")
+ "/version?loaders=[\"" +
(Server.isFabric ? "fabric" : "forge") + "\"]" + (mod.forceLatest ? "" : "&game_versions=[\"" + mcVersion + "\"]");
(modLoader.isFabric || modLoader.isQuilt ? "fabric" : "forge") + "\"]" + (mod.forceLatest ? "" : "&game_versions=[\"" + mcVersion + "\"]");
AL.debug(this.getClass(), url);
release = Json.getAsJsonArray(url)
.get(0).getAsJsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.osiris.dyml.Yaml;
import com.osiris.dyml.YamlSection;
import com.osiris.dyml.exceptions.DuplicateKeyException;
import com.osiris.jlib.logger.AL;
import org.jetbrains.annotations.NotNull;

import java.io.DataInputStream;
Expand Down Expand Up @@ -220,6 +221,23 @@ public void runAtStart() throws Exception {
executorService = Executors.newFixedThreadPool(includedSize);
else
executorService = Executors.newSingleThreadExecutor();
InstalledModLoader modLoader = new InstalledModLoader(false, false, false);
try {
for (File f :
new File(System.getProperty("user.dir")).listFiles()) {
if (f.getName().equals(".fabric")) {
modLoader.isFabric = true;
break;
}
if (f.getName().equals(".quilt")) {
modLoader.isQuilt = true;
break;
}
}
} catch (Exception e) {
AL.warn("Failed to determine installed Minecraft mod loader, fallback to forge.", e);
modLoader.isForge = true;
}
List<Future<SearchResult>> activeFutures = new ArrayList<>();
for (MinecraftMod mod :
includedMods) {
Expand All @@ -235,7 +253,7 @@ public void runAtStart() throws Exception {
sizeUnknownMods++; // MODRINTH OR CURSEFORGE MOD
mod.ignoreContentType = true; // TODO temporary workaround for xamazon-json content type curseforge/bukkit issue: https://github.com/Osiris-Team/AutoPlug-Client/issues/109
String finalMcVersion = mcVersion;
activeFutures.add(executorService.submit(() -> new ResourceFinder().findByModrinthOrCurseforge(mod, finalMcVersion, updaterConfig.mods_update_check_name_for_mod_loader.asBoolean())));
activeFutures.add(executorService.submit(() -> new ResourceFinder().findByModrinthOrCurseforge(modLoader, mod, finalMcVersion, updaterConfig.mods_update_check_name_for_mod_loader.asBoolean())));
}
} catch (Exception e) {
this.getWarnings().add(new BWarning(this, e, "Critical error while searching for update for '" + mod.getName() + "' mod!"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Osiris-Team.
* Copyright (c) 2021-2023 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -10,6 +10,7 @@


import com.osiris.autoplug.client.tasks.updater.mods.CurseForgeAPI;
import com.osiris.autoplug.client.tasks.updater.mods.InstalledModLoader;
import com.osiris.autoplug.client.tasks.updater.mods.MinecraftMod;
import com.osiris.autoplug.client.tasks.updater.mods.ModrinthAPI;
import com.osiris.autoplug.client.tasks.updater.search.GithubSearch;
Expand Down Expand Up @@ -45,14 +46,14 @@ public SearchResult findUnknownPlugin(MinecraftPlugin plugin) {
* If the modrinth/bukkit id is not given this type of search
* based on the mods' name and author will be executed.
*/
public SearchResult findByModrinthOrCurseforge(MinecraftMod mod, String mcVersion, boolean checkNameForModLoader) {
public SearchResult findByModrinthOrCurseforge(InstalledModLoader modLoader, MinecraftMod mod, String mcVersion, boolean checkNameForModLoader) {
// Do spigot search by name
SearchResult sr = new ModrinthAPI().searchUpdate(mod, mcVersion);
SearchResult sr = new ModrinthAPI().searchUpdate(modLoader, mod, mcVersion);

if (sr == null || sr.getResultCode() == 2 || sr.getResultCode() == 3) {
//Couldn't find author or resource via first search
//Do alternative search:
sr = new CurseForgeAPI().searchUpdate(mod, mcVersion, checkNameForModLoader);
sr = new CurseForgeAPI().searchUpdate(modLoader, mod, mcVersion, checkNameForModLoader);
}

sr.mod = mod;
Expand All @@ -73,14 +74,14 @@ public SearchResult findPluginByBukkitId(MinecraftPlugin plugin) {
return sr;
}

public SearchResult findModByModrinthId(MinecraftMod mod, String mcVersion) {
SearchResult sr = new ModrinthAPI().searchUpdate(mod, mcVersion);
public SearchResult findModByModrinthId(InstalledModLoader modLoader, MinecraftMod mod, String mcVersion) {
SearchResult sr = new ModrinthAPI().searchUpdate(modLoader, mod, mcVersion);
sr.mod = mod;
return sr;
}

public SearchResult findModByCurseforgeId(MinecraftMod mod, String mcVersion, boolean checkNameForModLoader) {
SearchResult sr = new CurseForgeAPI().searchUpdate(mod, mcVersion, checkNameForModLoader);
public SearchResult findModByCurseforgeId(InstalledModLoader modLoader, MinecraftMod mod, String mcVersion, boolean checkNameForModLoader) {
SearchResult sr = new CurseForgeAPI().searchUpdate(modLoader, mod, mcVersion, checkNameForModLoader);
sr.mod = mod;
return sr;
}
Expand Down

0 comments on commit f119799

Please sign in to comment.