Skip to content

Commit 2e4fb16

Browse files
authored
Merge pull request #4 from Goldenfield192/master
Update some outdated properties
2 parents 2f6f8c6 + 65912ea commit 2e4fb16

3 files changed

Lines changed: 82 additions & 23 deletions

File tree

src/main/java/cam72cam/universalmodcore/Config.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@ public UMC(JsonObject data) {
7474
}
7575
}
7676

77-
public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOException {
77+
public Config(JsonObject data, String mcVersion, Loader brand) throws GitAPIException, IOException {
7878
mod = new Mod(data.get("mod").getAsJsonObject());
7979
integration = data.has("integration") ? new Integration(data.get("integration").getAsJsonObject()) : null;
8080
umc = new UMC(data.get("umc").getAsJsonObject());
81-
String minecraft = loaderBranch.split("-")[0];
82-
String loader = loaderBranch.split("-")[1];
83-
this.minecraftLoader = minecraft + "-" + loader;
81+
this.minecraftLoader = mcVersion + "-" + brand.toString();
8482

8583
vars.clear();
8684
vars.put("PACKAGE", require("mod.package", mod.pkg));
@@ -89,9 +87,9 @@ public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOEx
8987
vars.put("NAME", require("mod.name", mod.name));
9088
vars.put("ID", require("mod.id", mod.id));
9189
vars.put("VERSION", require("mod.version", mod.version));
92-
vars.put("LOADER_VERSION", loaderBranch);
93-
vars.put("MINECRAFT", minecraft);
94-
vars.put("LOADER", loader);
90+
vars.put("LOADER_VERSION", minecraftLoader);
91+
vars.put("MINECRAFT", mcVersion);
92+
vars.put("LOADER", brand.toString());
9593

9694
String version = require("umc.version", umc.version);
9795

@@ -100,7 +98,7 @@ public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOEx
10098
File temp = null;
10199
if (umc.path == null) {
102100
temp = Files.createTempDirectory("umc-loader").toFile();
103-
Util.gitClone("https://github.com/TeamOpenIndustry/UniversalModCore.git", loaderBranch, temp, false);
101+
Util.gitClone("https://github.com/TeamOpenIndustry/UniversalModCore.git", minecraftLoader, temp, false);
104102
path = temp;
105103
} else {
106104
path = Paths.get(System.getProperty("user.dir"), umc.path).toFile();
@@ -128,8 +126,8 @@ public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOEx
128126
vars.put("UMC_VERSION", version);
129127

130128

131-
if (umc.path != null && umc.path.length() != 0) {
132-
File jar = new File(umc.path, String.format("build/libs/UniversalModCore-%s-%s.jar", loaderBranch, version));
129+
if (umc.path != null && !umc.path.isEmpty()) {
130+
File jar = new File(umc.path, String.format("build/libs/UniversalModCore-%s-%s.jar", minecraftLoader, version));
133131
if (!jar.exists()) {
134132
throw new RuntimeException(String.format("Unable to find UMC jar: %s", jar));
135133
}
@@ -138,8 +136,8 @@ public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOEx
138136
vars.put("UMC_FILE", jar.getPath());
139137
} else {
140138
vars.put("UMC_REPO", "repositories { maven { url = \"https://teamopenindustry.cc/maven\" }}");
141-
vars.put("UMC_DEPENDENCY", String.format("'cam72cam.universalmodcore:UniversalModCore:%s-%s'", loaderBranch, version));
142-
vars.put("UMC_DOWNLOAD", String.format("https://teamopenindustry.cc/maven/cam72cam/universalmodcore/UniversalModCore/%s-%s/UniversalModCore-%s-%s.jar", loaderBranch, version, loaderBranch, version));
139+
vars.put("UMC_DEPENDENCY", String.format("'cam72cam.universalmodcore:UniversalModCore:%s-%s'", minecraftLoader, version));
140+
vars.put("UMC_DOWNLOAD", String.format("https://teamopenindustry.cc/maven/cam72cam/universalmodcore/UniversalModCore/%s-%s/UniversalModCore-%s-%s.jar", minecraftLoader, version, minecraftLoader, version));
143141
}
144142

145143
ArrayList<Mod.Dependency> dependencies = new ArrayList<>(mod.dependencies);
@@ -155,14 +153,29 @@ public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOEx
155153
vars.put("FORGE_STRING_DEPENDENCIES", forgeStringDependencies);
156154

157155
String forgeTomlDependencies = dependencies.stream()
158-
.map(dep ->
159-
String.format("[[dependencies.%s]]%n", mod.id) +
160-
String.format(" modId=\"%s\"%n", dep.id) +
161-
String.format(" mandatory=true%n") +
162-
String.format(" versionRange=\"%s\"%n", dep.versions) +
163-
String.format(" ordering=\"BEFORE\"%n") +
164-
String.format(" side=\"BOTH\"%n")
165-
)
156+
.map(dep -> {
157+
switch (brand) {
158+
case FORGE:
159+
return String.format("[[dependencies.%s]]%n", mod.id) +
160+
String.format(" modId=\"%s\"%n", dep.id) +
161+
String.format(" mandatory=true%n") +
162+
String.format(" versionRange=\"%s\"%n", dep.versions) +
163+
String.format(" ordering=\"BEFORE\"%n") +
164+
String.format(" side=\"BOTH\"%n");
165+
case NEOFORGE:
166+
return String.format("[[dependencies.%s]]%n", mod.id) +
167+
String.format(" modId=\"%s\"%n", dep.id) +
168+
String.format(" type='required'%n") +
169+
String.format(" versionRange=\"%s\"%n", dep.versions) +
170+
String.format(" ordering=\"BEFORE\"%n") +
171+
String.format(" side=\"BOTH\"%n");
172+
case FABRIC:
173+
case QUILT:
174+
default:
175+
//TODO
176+
return null;
177+
}
178+
})
166179
.collect(Collectors.joining(System.lineSeparator() + System.lineSeparator()));
167180
vars.put("FORGE_TOML_DEPENDENCIES", forgeTomlDependencies);
168181

@@ -171,7 +184,7 @@ public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOEx
171184

172185

173186
private String require(String name, String s) {
174-
if (s == null || s.trim().length() == 0) {
187+
if (s == null || s.trim().isEmpty()) {
175188
throw new RuntimeException(String.format("Missing variable %s in config: %s", name, s));
176189
}
177190
return s;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cam72cam.universalmodcore;
2+
3+
import java.util.Arrays;
4+
5+
public enum Loader {
6+
FORGE("forge"),
7+
NEOFORGE("neoforge"),
8+
FABRIC("fabric"),
9+
QUILT("quilt");
10+
11+
private final String name;
12+
13+
Loader(String str) {
14+
this.name = str;
15+
}
16+
17+
public static Loader parse(String str) {
18+
if (str.equalsIgnoreCase(FORGE.name)) {
19+
return FORGE;
20+
} else if (str.equalsIgnoreCase(NEOFORGE.name)) {
21+
return NEOFORGE;
22+
} else if (str.equalsIgnoreCase(FABRIC.name)) {
23+
return FABRIC;
24+
} else if (str.equalsIgnoreCase(QUILT.name)) {
25+
return QUILT;
26+
}
27+
throw new IllegalArgumentException("Mod loader must be one of followings: " + Arrays.toString(Loader.values()));
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return name;
33+
}
34+
}

src/main/java/cam72cam/universalmodcore/Setup.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,24 @@ public static void main(String[] args) throws IOException, GitAPIException {
3030
}
3131
String loaderBranch = args[0];
3232
String[] split = loaderBranch.split("-");
33-
if (split.length < 2 || !split[0].matches("1\\.\\d*\\.\\d*") || !split[1].matches("[\\w-]+")) {
33+
if (split.length < 2) {
3434
System.err.println("Invalid loader branch! It should be in the format '<minecraft-version>-<loader>'. For example, '1.12.2-forge'.");
3535
return;
3636
}
37+
String version = split[0];
38+
Loader brand = Loader.parse(split[1]);
39+
String intermediary = version;
3740

38-
Config config = new Config(configObj, loaderBranch);
41+
if (intermediary.startsWith("1.")) {
42+
intermediary = intermediary.substring(2);
43+
}
44+
45+
if (!intermediary.matches("\\d*\\.\\d*")) {
46+
System.err.println("Invalid Minecraft version: " + version + ", it should be 1.xx.xx for 1.21.11 and below or xx.x for 26.1 and up");
47+
return;
48+
}
49+
50+
Config config = new Config(configObj, version, brand);
3951

4052
ZipInputStream zip = new ZipInputStream(config.openJarStream());
4153
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {

0 commit comments

Comments
 (0)