Skip to content

Commit

Permalink
8.1.5
Browse files Browse the repository at this point in the history
- fix issue with force-update being unset
- added force-update to mods too
- increase code readability (regarding state/type of a search result)
  • Loading branch information
Osiris-Team committed Jun 23, 2024
1 parent 176dd66 commit f9a7e21
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 96 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
// Important for AutoPlugs Self-Updater!
// Also take a look at the generateAutoplugProperties task where these properties get turned into the actual autoplug.properties file.
group = 'com.osiris.autoplug.client'
version = '8.1.4'
version = '8.1.5'
description = 'Responsible for all the main actions.'

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public ModsConfig() throws IOException, DuplicateKeyException, YamlReaderExcepti
"curseforge-id: Is also called 'Project-ID' and can be found on the mods curseforge site inside of the 'About' box at the right.\n" +
"ignore-content-type: If true, does not check if the downloaded file is of type jar or zip, and downloads it anyway.\n" +
"force-latest: If true, does not search for updates compatible with this Minecraft version and simply picks the latest release.\n" +
"force-update: If true, downloads the update every time even if its already on the latest version.\n" +
"custom-check-url: #### Must link to a json file which contains a list/array of plugin versions where each item/object contains specific keys for version (\"version_number\", \"version\") and download URL (\"download_url\", \"download\", \"file\", \"download_file\").\n" +
"custom-download-url: must be a static url to the mods latest jar file.\n" +
"alternatives.github.repo-name: Example: 'EssentialsX/Essentials' (can be found in its url: https://github.com/EssentialsX/Essentials)\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public PluginsConfig() throws IOException, DuplicateKeyException, YamlReaderExce
" custom-check-url: #### Must link to a json file which contains a list/array of plugin versions where each item/object contains specific keys for version (\"version_number\", \"version\") and download URL (\"download_url\", \"download\", \"file\", \"download_file\").\n" +
" custom-download-url: #### Must be a static url to the plugins latest jar file.\n" +
" ignore-content-type: false #### When downloading a file the file host is asked for the file-type which must be .jar, when true this check is not performed.\n" +
" force-update: false #### If true, downloads the update every time even if its already on the latest version.\n" +
" alternatives: #### below both alternatives are used for demonstration purposes, make sure to use only one)\n" +
" github: \n" +
" repo-name: EssentialsX/Essentials #### Provided by you #### Can be found in its url: https://github.com/EssentialsX/Essentials\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public static boolean installPlugin(String command) throws Exception {
try{
int i = Integer.parseInt(input2.trim());
result.plugin = similarPlugins.get(i);
result.resultCode = 1;
result.type = SearchResult.Type.UPDATE_AVAILABLE;
break;
} catch (Exception e) {
AL.warn(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand Down Expand Up @@ -73,7 +73,7 @@ private void sendResultsOfPluginCheck() throws Exception {
else
out.writeUTF(result.getPlugin().getVersion());

out.writeByte(result.getResultCode());
out.writeByte(result.type.id);

if (result.getDownloadType() == null)
out.writeUTF("null");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Osiris-Team.
* Copyright (c) 2022-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand Down Expand Up @@ -43,7 +43,7 @@ public SearchResult searchUpdate(InstalledModLoader modLoader, MinecraftMod mod,
String latest = null;
String type = ".jar";
String downloadUrl = null;
byte code = 0;
SearchResult.Type resultType = SearchResult.Type.UP_TO_DATE;
String modInfo = mod.getName() + "/" + (modLoader.isFabric || modLoader.isQuilt ? "fabric" : "forge");
try {
if (!isIdNumber) { // Determine project id, since we only got slug
Expand Down Expand Up @@ -133,7 +133,7 @@ public SearchResult searchUpdate(InstalledModLoader modLoader, MinecraftMod mod,
throw new Exception("Failed to determine latest mod version!", e);
}
if (new File(mod.installationPath).lastModified() < fileDateToMs(release.get("fileDate").getAsString()))
code = 1;
resultType = SearchResult.Type.UPDATE_AVAILABLE;
downloadUrl = release.get("downloadUrl").getAsString();
try {
String fileName = release.get("fileName").getAsString();
Expand All @@ -142,9 +142,9 @@ public SearchResult searchUpdate(InstalledModLoader modLoader, MinecraftMod mod,
}
} catch (Exception e) {
exception = e;
code = 2;
resultType = SearchResult.Type.API_ERROR;
}
SearchResult result = new SearchResult(null, code, latest, downloadUrl, type, null, null, false);
SearchResult result = new SearchResult(null, resultType, latest, downloadUrl, type, null, null, false);
result.mod = mod;
result.setException(exception);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MinecraftMod {
public int jenkinsBuildId;
public boolean forceLatest;
public String customCheckURL;
public boolean forceUpdate;
private String name, author, version;

public MinecraftMod(String installationPath, String name, String version,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Osiris-Team.
* Copyright (c) 2022-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -17,8 +17,6 @@

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


public class ModrinthAPI {
Expand Down Expand Up @@ -55,7 +53,7 @@ private SearchResult searchUpdate(String loader, String id, String mcVersion, St
String latest = null;
String type = ".jar";
String downloadUrl = null;
byte code = 0;
SearchResult.Type resultType = SearchResult.Type.UP_TO_DATE;
try {
if (id == null)
throw new Exception("Modrinth-id is null!"); // Modrinth id can be slug or actual id
Expand All @@ -79,7 +77,7 @@ private SearchResult searchUpdate(String loader, String id, String mcVersion, St

latest = release.get("version_number").getAsString().replaceAll("[^0-9.]", ""); // Before passing over remove everything except numbers and dots
if (new File(installPath).lastModified() < Instant.parse(release.get("date_published").getAsString()).toEpochMilli())
code = 1;
resultType = SearchResult.Type.UPDATE_AVAILABLE;
JsonObject releaseDownload = release.getAsJsonArray("files").get(0).getAsJsonObject();
downloadUrl = releaseDownload.get("url").getAsString();
try {
Expand All @@ -89,9 +87,9 @@ private SearchResult searchUpdate(String loader, String id, String mcVersion, St
}
} catch (Exception e) {
exception = e;
code = 2;
resultType = SearchResult.Type.API_ERROR;
}
SearchResult result = new SearchResult(null, code, latest, downloadUrl, type, null, null, false);
SearchResult result = new SearchResult(null, resultType, latest, downloadUrl, type, null, null, false);
result.setException(exception);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void runAtStart() throws Exception {
YamlSection curseforgeId = modsConfig.put(name, plName, "curseforge-id");
YamlSection ignoreContentType = modsConfig.put(name, plName, "ignore-content-type").setDefValues("false");
YamlSection forceLatest = modsConfig.put(name, plName, "force-latest").setDefValues("false");
YamlSection forceUpdate = modsConfig.put(name, plName, "force-update").setDefValues("false");
YamlSection customCheckURL = modsConfig.put(name, plName, "custom-check-url");
YamlSection customDownloadURL = modsConfig.put(name, plName, "custom-download-url");
YamlSection githubRepoUrl = modsConfig.put(name, plName, "alternatives", "github", "repo-name");
Expand All @@ -123,6 +124,7 @@ public void runAtStart() throws Exception {
installedMod.jenkinsProjectUrl = (jenkinsProjectUrl.asString());
installedMod.jenkinsArtifactName = (jenkinsArtifactName.asString());
installedMod.jenkinsBuildId = (jenkinsBuildId.asInt());
installedMod.forceUpdate = forceUpdate.asBoolean();

// Check for missing author in internal config
if ((installedMod.getVersion() == null)
Expand Down Expand Up @@ -235,21 +237,21 @@ public void runAtStart() throws Exception {
SearchResult result = finishedFuture.get();
results.add(result);
MinecraftMod mod = result.mod;
byte code = result.getResultCode();
SearchResult.Type code = result.type;
String type = result.getDownloadType(); // The file type to download (Note: When 'external' is returned nothing will be downloaded. Working on a fix for this!)
String latest = result.getLatestVersion(); // The latest version as String
String downloadUrl = result.getDownloadUrl(); // The download url for the latest version
String resultModrinthId = mod.modrinthId;
String resultCurseForgeId = mod.curseforgeId;
this.setStatus("Checked '" + mod.getName() + "' mod (" + results.size() + "/" + includedSize + ")");
if (code == 0 || code == 1) {
if (code == SearchResult.Type.UP_TO_DATE || code == SearchResult.Type.UPDATE_AVAILABLE) {
doDownloadLogic(mod, result);
} else if (code == 2)
} else if (code == SearchResult.Type.API_ERROR)
if (result.getException() != null)
getWarnings().add(new BWarning(this, result.getException(), "There was an api-error for " + mod.getName() + "!"));
else
getWarnings().add(new BWarning(this, new Exception("There was an api-error for " + mod.getName() + "!")));
else if (code == 3)
else if (code == SearchResult.Type.RESOURCE_NOT_FOUND)
getWarnings().add(new BWarning(this, new Exception("Mod " + mod.getName() + " was not found by the search-algorithm! Specify an id in /autoplug/mods.yml file.")));
else
getWarnings().add(new BWarning(this, new Exception("Unknown error occurred! Code: " + code + "."), "Notify the developers. Fastest way is through discord (https://discord.gg/GGNmtCC)."));
Expand Down Expand Up @@ -296,10 +298,10 @@ else if (code == 3)
throw new Exception("This should not happen! Please report to the devs!");

if (download.isDownloadSuccessful())
matchingResult.setResultCode((byte) 5);
matchingResult.type = SearchResult.Type.UPDATE_DOWNLOADED;

if (download.isInstallSuccessful()) {
matchingResult.setResultCode((byte) 6);
matchingResult.type = SearchResult.Type.UPDATE_INSTALLED;
YamlSection jenkinsBuildId = modsConfig.get(
modsConfigName, download.getPlName(), "alternatives", "jenkins", "build-id");
jenkinsBuildId.setValues(String.valueOf(download.searchResult.jenkinsId));
Expand Down Expand Up @@ -335,13 +337,16 @@ else if (code == 3)
}

private void doDownloadLogic(@NotNull MinecraftMod mod, SearchResult result) {
byte code = result.getResultCode();
SearchResult.Type code = result.type;
String type = result.getDownloadType(); // The file type to download (Note: When 'external' is returned nothing will be downloaded. Working on a fix for this!)
String latest = result.getLatestVersion(); // The latest version as String
String downloadUrl = result.getDownloadUrl(); // The download url for the latest version
if (mod.customDownloadURL != null) downloadUrl = mod.customDownloadURL;

if (code == 0) {
if (mod.forceUpdate && code == SearchResult.Type.UP_TO_DATE)
code = SearchResult.Type.UPDATE_AVAILABLE;

if (code == SearchResult.Type.UP_TO_DATE) {
//getSummary().add("Mod " +pl.getName()+ " is already on the latest version (" + pl.getVersion() + ")"); // Only for testing right now
} else {
updatesAvailable++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -12,9 +12,9 @@ public class MinecraftPlugin {
public boolean isPremium;
public String configPath;
public String installationPath;
public String name;
public String version;
public String author;
private String name;
private String version;
private String author;
public int spigotId;
public int bukkitId;
public boolean ignoreContentType;
Expand All @@ -26,7 +26,7 @@ public class MinecraftPlugin {
public String jenkinsArtifactName;
public int jenkinsBuildId;
public String modrinthId;
public String forceUpdate;
public boolean forceUpdate;

public MinecraftPlugin(String installationPath, String name, String version, String author, int spigotId, int bukkitId, String customDownloadURL) {
this.installationPath = installationPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public SearchResult findByModrinthOrCurseforge(InstalledModLoader modLoader, Min
// TODO actualy do search by name, since currently it still searches by id
SearchResult sr = new ModrinthAPI().searchUpdateMod(modLoader, mod, mcVersion);

if (sr == null || sr.getResultCode() == 2 || sr.getResultCode() == 3) {
if (sr == null || sr.type == SearchResult.Type.API_ERROR || sr.type == SearchResult.Type.RESOURCE_NOT_FOUND) {
//Couldn't find author or resource via first search
//Do alternative search:
sr = new CurseForgeAPI().searchUpdate(modLoader, mod, mcVersion, checkNameForModLoader);
Expand Down
Loading

0 comments on commit f9a7e21

Please sign in to comment.