Skip to content

Commit e141657

Browse files
committed
Add support for ignored dependencies.
Add support for loading a custom Branch Config. Add support for Modrinth api dependencies. Add Admin option to update dependencies Modrinth mods in a branch config.
1 parent 7b9dac3 commit e141657

16 files changed

Lines changed: 232 additions & 73 deletions

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
# against bad commits.
55

66
name: build
7-
on: [push]
7+
on: [ push ]
88

99
jobs:
1010
build:
1111

1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v4
16-
- uses: actions/setup-java@v4
15+
- uses: actions/checkout@v6
16+
- uses: actions/setup-java@v5
1717
with:
1818
distribution: 'temurin' # See 'Supported distributions' for available options
19-
java-version: '21'
19+
java-version: '25'
2020

2121
- name: build
2222
run: mvn package
2323

2424
- name: capture build artifacts
25-
uses: actions/upload-artifact@v4
25+
uses: actions/upload-artifact@v7
2626
with:
2727
name: Artifacts
28-
path: target/dist/
28+
path: target/dist/

DEFAULT_BRANCHES.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
{
44
"name": "Battle 1.20.4",
55
"url": "https://github.com/Legacy-Edition-Minigames/Minigames/tree/battle-1.20.4",
6-
"desc": "Latest version of Battle for 1.20.4 (Recommended)"
7-
},
8-
{
9-
"name": "LEM ToolBox Testing",
10-
"url": "https://github.com/Legacy-Edition-Minigames/Minigames/tree/toolbox-testing",
11-
"desc": "LEM branch for testing Toolbox [1.20.4]"
6+
"desc": "Latest Version of Battle 1.0 [1.20.4] (Recommended)"
127
},
138
{
149
"name": "Battle 1.20.1",
1510
"url": "https://github.com/Legacy-Edition-Minigames/Minigames/tree/battle-1.20.1",
16-
"desc": "Old version of Battle for 1.20.1"
11+
"desc": "Archived Version of Battle [1.20.1]"
1712
},
1813
{
1914
"name": "April Fools 2024",
2015
"url": "https://github.com/Legacy-Edition-Minigames/Minigames/tree/aprilfools/2024/battle",
21-
"desc": "April Fools event from 2024 [1.20.4]"
16+
"desc": "April Fools Event from 2024. (Terraria) [1.20.4]"
17+
},
18+
{
19+
"name": "April Fools 2026",
20+
"url": "https://github.com/Legacy-Edition-Minigames/Minigames/tree/aprilfools/2026/battle",
21+
"desc": "April Fools Event from 2026. (MODTOOLS!!!!!) [1.20.4]"
2222
},
2323
{
24-
"name": "Rewrite Testing",
24+
"name": "Battle 2.0",
2525
"url": "https://github.com/Legacy-Edition-Minigames/Minigames/tree/rewrite",
26-
"desc": "Rewrite Testing [1.21.8]"
26+
"desc": "Battle 2.0 / Rewrite [26.1.2]"
2727
}
2828
],
2929
"config_version": 1
30-
}
30+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# LEM ToolBox
2+
23
[![forthebadge](https://forthebadge.com/images/badges/made-with-java.svg)](https://forthebadge.com)
34

45
# **Important Notice**
56

67
## This project is currently undergoing a complete rewrite, not all features from the old version are available yet!
78

8-
Feel free to test it, but don't expect a fully finished experience yet. [Latest Build](https://nightly.link/Legacy-Edition-Minigames/ToolBox/workflows/build/java/Artifacts.zip)
9+
Feel free to test it, but don't expect a fully finished experience yet. [Latest Build](https://nightly.link/Legacy-Edition-Minigames/ToolBox/workflows/build/java/Artifacts.zip)

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
<groupId>net.kyrptonaught</groupId>
88
<artifactId>ToolBox2.0</artifactId>
9-
<version>2.2.0</version>
9+
<version>2.3.0</version>
1010
<packaging>jar</packaging>
1111

1212
<properties>
13-
<maven.compiler.source>21</maven.compiler.source>
14-
<maven.compiler.target>21</maven.compiler.target>
13+
<maven.compiler.source>25</maven.compiler.source>
14+
<maven.compiler.target>25</maven.compiler.target>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1616
</properties>
1717

1818
<dependencies>
1919
<dependency>
2020
<groupId>com.google.code.gson</groupId>
2121
<artifactId>gson</artifactId>
22-
<version>2.13.1</version>
22+
<version>2.13.2</version>
2323
</dependency>
2424
</dependencies>
2525

@@ -52,4 +52,4 @@
5252
</plugin>
5353
</plugins>
5454
</build>
55-
</project>
55+
</project>

src/main/java/net/kyrptonaught/ToolBox/AutoHash.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,43 @@ public static void autoHash() {
1515
String toolboxJson = FileHelper.readFile(Path.of("toolbox.json"));
1616
BranchConfig config = ConfigLoader.parseToolboxConfig(toolboxJson);
1717

18+
autoHash(config);
19+
20+
FileHelper.writeFile(Path.of("toolbox.json"), ConfigLoader.serializeToolboxInstall(config));
21+
}
22+
23+
public static void autoHash(BranchConfig config) {
1824
for (BranchConfig.Dependency dependency : config.dependencies) {
19-
if (dependency.gitRepo) {
25+
if (dependency.type == BranchConfig.TYPE.GIT) {
2026
String apiCall = GithubHelper.convertRepoToApiCall(dependency.url);
2127
JsonObject response = FileHelper.download(apiCall, JsonObject.class);
2228
String hash = response.getAsJsonObject("commit").getAsJsonPrimitive("sha").getAsString();
2329
dependency.autoGeneratedHash = hash;
2430
System.out.println("Generated Git Hash for " + dependency.getDisplayName() + ": " + hash);
31+
} else if (dependency.type == BranchConfig.TYPE.MODRINTH) {
32+
JsonObject urlOBJ = ConfigLoader.gson.fromJson(dependency.url, JsonObject.class);
33+
String version = urlOBJ.get("version").getAsString();
34+
35+
String url = FileHelper.download("https://api.modrinth.com/v2/version/" + version, JsonObject.class).getAsJsonArray("files").get(0).getAsJsonObject().get("url").getAsString();
36+
urlOBJ.addProperty("url", url);
37+
dependency.url = urlOBJ.toString();
38+
dependency.autoGeneratedHash = hash(url);
2539
} else {
26-
try (InputStream in = FileHelper.openFileOrURL(dependency.url)) {
27-
byte[] data = in.readAllBytes();
28-
String hash = FileHelper.hashFile(data);
29-
dependency.autoGeneratedHash = hash;
30-
System.out.println("Generated Hash for " + dependency.getDisplayName() + ": " + hash);
31-
} catch (Exception e) {
32-
e.printStackTrace();
33-
}
40+
dependency.autoGeneratedHash = hash(dependency.url);
3441
}
3542
}
43+
}
3644

37-
FileHelper.writeFile(Path.of("toolbox.json"), ConfigLoader.serializeToolboxInstall(config));
45+
private static String hash(String url) {
46+
try (InputStream in = FileHelper.openFileOrURL(url)) {
47+
byte[] data = in.readAllBytes();
48+
String hash = FileHelper.hashFile(data);
49+
System.out.println("Generated Hash for " + url + ": " + hash);
50+
return hash;
51+
} catch (Exception e) {
52+
e.printStackTrace();
53+
}
54+
55+
return null;
3856
}
39-
}
57+
}

src/main/java/net/kyrptonaught/ToolBox/Automation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public static void installServer() {
6363
if (name != null) serverInfo.setName(name);
6464
serverInfo.setPath();
6565

66-
int allocatedRam = CMDArgsParser.getNewServerRam();
67-
if (allocatedRam < 1) allocatedRam = 3;
66+
String allocatedRam = CMDArgsParser.getNewServerRam();
67+
if (allocatedRam.isBlank()) allocatedRam = "3";
6868
serverInfo.setRAMArgs(allocatedRam);
6969

7070
Installer.installAndCheckForUpdates(serverInfo);
@@ -84,4 +84,4 @@ public static void installServer() {
8484
Menu.setState(State.EXISTING_INSTALL, serverInfo);
8585
}
8686
}
87-
}
87+
}

src/main/java/net/kyrptonaught/ToolBox/CMDArgsParser.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ public static boolean installServer() {
7171
return containsArgs("--installServer");
7272
}
7373

74-
public static int getNewServerRam() {
74+
public static String getNewServerRam() {
7575
for (int i = 0; i < args.length - 1; i++) {
7676
if (args[i].equalsIgnoreCase("--newServerRam") && !args[i + 1].startsWith("--")) {
77-
return Integer.parseInt(args[i + 1]);
77+
return args[i + 1];
7878
}
7979
}
80-
return 3;
80+
81+
return "3";
8182
}
8283

8384
public static BranchesConfig.BranchInfo getNewServerBranch() {
@@ -113,4 +114,4 @@ public static boolean doesNewServerAgreeToEULA() {
113114
public static boolean unattendedInstall() {
114115
return containsArgs("--unattendedInstall");
115116
}
116-
}
117+
}

src/main/java/net/kyrptonaught/ToolBox/Executer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public static void startServer(InstalledServerInfo serverInfo) {
3535
public static void updateServer(InstalledServerInfo serverInfo) {
3636
String url = GithubHelper.convertRepoToToolboxConfig(serverInfo.getBranchInfo().url);
3737
BranchConfig branch = ConfigLoader.parseToolboxConfig(FileHelper.download(url));
38+
if (serverInfo.customInstall) AutoHash.autoHash(branch);
3839
serverInfo.updateBranchConfig(branch);
3940
Installer.installAndCheckForUpdates(serverInfo);
4041
}
41-
}
42+
}

src/main/java/net/kyrptonaught/ToolBox/IO/GithubHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ public static String convertRepoToZipball(String repo) {
66
}
77

88
public static String convertRepoToToolboxConfig(String repo) {
9+
if (repo.startsWith("file://")) return repo;
910
return repo.replace("github.com", "raw.githubusercontent.com").replace("tree/", "") + "/.toolbox/toolbox.json";
1011
}
1112

1213
public static String convertRepoToApiCall(String repo) {
1314
return repo.replace("github.com", "api.github.com/repos").replace("/tree/", "/branches/");
1415
}
15-
}
16+
}

src/main/java/net/kyrptonaught/ToolBox/Installer.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.kyrptonaught.ToolBox;
22

3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonObject;
35
import net.kyrptonaught.ToolBox.IO.ConfigLoader;
46
import net.kyrptonaught.ToolBox.IO.FileHelper;
57
import net.kyrptonaught.ToolBox.IO.GithubHelper;
@@ -102,9 +104,12 @@ private static void installDependencies(InstalledServerInfo serverInfo) {
102104
String hash = dependency.autoGeneratedHash;
103105

104106
if (hash != null && (installedDependency == null || !hash.equals(installedDependency.hash))) {
105-
System.out.print("downloading...");
106-
installFile(serverInfo, new InstalledDependencyInfo(dependency), hash);
107-
System.out.println("installed");
107+
if (dependency.ignore != null && dependency.ignore) System.out.println("skipping...");
108+
else {
109+
System.out.print("downloading...");
110+
installFile(serverInfo, new InstalledDependencyInfo(dependency), hash);
111+
System.out.println("installed");
112+
}
108113
} else {
109114
System.out.println("Already exists");
110115
}
@@ -117,16 +122,19 @@ private static void installFile(InstalledServerInfo serverInfo, InstalledDepende
117122
Path destination = serverInfo.getDependencyInstallPath(dependency);
118123
FileHelper.createDir(destination);
119124

120-
if (dependency.gitRepo) {
125+
if (dependency.type == BranchConfig.TYPE.GIT) {
121126
FileHelper.download(GithubHelper.convertRepoToZipball(dependency.url), downloadPath);
127+
} else if (dependency.type == BranchConfig.TYPE.MODRINTH) {
128+
JsonObject urlOBJ = ConfigLoader.gson.fromJson(dependency.url, JsonObject.class);
129+
FileHelper.download(urlOBJ.get("url").getAsString(), downloadPath);
122130
} else {
123131
FileHelper.download(dependency.url, downloadPath);
124132
}
125133

126134
clearOldFiles(serverInfo, dependency.installedFiles);
127135

128136
List<String> installedFiles;
129-
if (dependency.unzip) {
137+
if (dependency.type == BranchConfig.TYPE.ZIP) {
130138
installedFiles = FileHelper.unzipFile(downloadPath, destination, true);
131139
} else {
132140
installedFiles = FileHelper.copyFile(downloadPath, destination.resolve(dependency.name));
@@ -142,7 +150,7 @@ private static void replaceMissingFiles(InstalledServerInfo serverInfo, Installe
142150
Path destination = serverInfo.getDependencyInstallPath(dependency);
143151
FileHelper.createDir(destination);
144152

145-
if (dependency.unzip) {
153+
if (dependency.type == BranchConfig.TYPE.ZIP) {
146154
List<String> installedFiles = new ArrayList<>(List.copyOf(dependency.installedFiles));
147155
if (installedFiles != null) {
148156
Path unzipPath = serverInfo.getTempPath(dependency);
@@ -204,4 +212,23 @@ private static InstalledDependencyInfo getInstalledDependency(InstalledServerInf
204212
}
205213
return null;
206214
}
215+
216+
public static void checkForModrinthUpdate(BranchConfig.Dependency dependency, String gameVersion, String loader) {
217+
if (dependency.type == BranchConfig.TYPE.MODRINTH) {
218+
JsonObject urlOBJ = ConfigLoader.gson.fromJson(dependency.url, JsonObject.class);
219+
String id = urlOBJ.get("id").getAsString();
220+
String version = urlOBJ.get("version").getAsString();
221+
222+
JsonArray obj = FileHelper.download("https://api.modrinth.com/v2/project/" + id + "/version?game_versions=[%22" + gameVersion + "%22]&loaders=[%22" + loader.toLowerCase() + "%22]&include_changelog=false", JsonArray.class);
223+
if (obj.isEmpty()) {
224+
System.out.println(dependency.name + "(" + id + "): Skipping");
225+
return;
226+
}
227+
urlOBJ.addProperty("version", obj.get(0).getAsJsonObject().get("id").getAsString());
228+
229+
System.out.println(dependency.name + "(" + id + "): " + version + " -> " + obj.get(0).getAsJsonObject().get("version_number").getAsString() + "(" + urlOBJ.get("version").getAsString() + ")");
230+
231+
dependency.url = ConfigLoader.serializeToolboxInstall(urlOBJ);
232+
}
233+
}
207234
}

0 commit comments

Comments
 (0)