Merge pull request #587 from microwin7/patch-8

Java recommend don't valid for starting minecraft client
This commit is contained in:
Gravit 2022-05-29 14:51:15 +07:00 committed by GitHub
commit 2c1129aa5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,20 +98,24 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
optionals.add(optionalOther); optionals.add(optionalOther);
} }
Optional<MakeProfileOptionLog4j> logFile = findOption(options, MakeProfileOptionLog4j.class); Optional<MakeProfileOptionLog4j> logFile = findOption(options, MakeProfileOptionLog4j.class);
if(logFile.isPresent()) { if (logFile.isPresent()) {
var log4jOption = logFile.get(); var log4jOption = logFile.get();
if(log4jOption.logFile != null) { if (log4jOption.logFile != null) {
jvmArgs.add("-Dlog4j.configurationFile=".concat(logFile.get().logFile)); jvmArgs.add("-Dlog4j.configurationFile=".concat(logFile.get().logFile));
} else if(log4jOption.affected) { } else if (log4jOption.affected) {
if(version.compareTo(ClientProfile.Version.MC117) >= 0 && version.compareTo(ClientProfile.Version.MC118) < 0) { if (version.compareTo(ClientProfile.Version.MC117) >= 0 && version.compareTo(ClientProfile.Version.MC118) < 0) {
jvmArgs.add("-Dlog4j2.formatMsgNoLookups=true"); jvmArgs.add("-Dlog4j2.formatMsgNoLookups=true");
} }
} }
} }
if (version.compareTo(ClientProfile.Version.MC117) >= 0) { if (version.compareTo(ClientProfile.Version.MC117) >= 0 && version.compareTo(ClientProfile.Version.MC118) < 0) {
builder.setMinJavaVersion(16); builder.setMinJavaVersion(16);
builder.setRecommendJavaVersion(16); builder.setRecommendJavaVersion(16);
} }
if (version.compareTo(ClientProfile.Version.MC118) >= 0) {
builder.setMinJavaVersion(17);
builder.setRecommendJavaVersion(17);
}
jvmArgs.add("-Dfml.ignorePatchDiscrepancies=true"); jvmArgs.add("-Dfml.ignorePatchDiscrepancies=true");
jvmArgs.add("-Dfml.ignoreInvalidMinecraftCertificates=true"); jvmArgs.add("-Dfml.ignoreInvalidMinecraftCertificates=true");
builder.setJvmArgs(jvmArgs); builder.setJvmArgs(jvmArgs);
@ -168,20 +172,20 @@ public static String getMainClassByVersion(ClientProfile.Version version, MakePr
} }
private static boolean isAffectedLog4jVersion(String version) { private static boolean isAffectedLog4jVersion(String version) {
if(version == null) { if (version == null) {
return true; return true;
} }
String[] split = version.split("\\."); String[] split = version.split("\\.");
if(split.length < 2) return true; if (split.length < 2) return true;
if(!split[0].equals("2")) return false; if (!split[0].equals("2")) return false;
return Integer.parseInt(split[1]) < 15; return Integer.parseInt(split[1]) < 15;
} }
private static String getLog4jVersion(Path dir) throws IOException { private static String getLog4jVersion(Path dir) throws IOException {
Path log4jCore = dir.resolve("org/apache/logging/log4j/log4j-core"); Path log4jCore = dir.resolve("org/apache/logging/log4j/log4j-core");
if(Files.exists(log4jCore)) { if (Files.exists(log4jCore)) {
Path target = Files.list(log4jCore).findFirst().orElse(null); Path target = Files.list(log4jCore).findFirst().orElse(null);
if(target != null) { if (target != null) {
return target.getFileName().toString(); return target.getFileName().toString();
} }
} }
@ -192,9 +196,8 @@ public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientP
List<MakeProfileOption> options = new ArrayList<>(2); List<MakeProfileOption> options = new ArrayList<>(2);
if (Files.exists(dir.resolve("forge.jar"))) { if (Files.exists(dir.resolve("forge.jar"))) {
options.add(new MakeProfileOptionForge()); options.add(new MakeProfileOptionForge());
} } else if (Files.exists(dir.resolve("libraries/net/minecraftforge/forge"))) {
else if (Files.exists(dir.resolve("libraries/net/minecraftforge/forge"))) { if (version.compareTo(ClientProfile.Version.MC1122) > 0) {
if(version.compareTo(ClientProfile.Version.MC1122) > 0) {
options.add(new MakeProfileOptionForge(dir)); options.add(new MakeProfileOptionForge(dir));
} else { } else {
options.add(new MakeProfileOptionForge()); options.add(new MakeProfileOptionForge());
@ -205,10 +208,10 @@ else if (Files.exists(dir.resolve("libraries/net/minecraftforge/forge"))) {
} }
{ {
String log4jVersion = getLog4jVersion(dir); String log4jVersion = getLog4jVersion(dir);
if(log4jVersion != null) { if (log4jVersion != null) {
boolean affected = isAffectedLog4jVersion(log4jVersion); boolean affected = isAffectedLog4jVersion(log4jVersion);
if(Files.exists(dir.resolve("log4j2_custom.xml"))) { if (Files.exists(dir.resolve("log4j2_custom.xml"))) {
options.add(new MakeProfileOptionLog4j(affected, "log4j2_custom.xml")); options.add(new MakeProfileOptionLog4j(affected, "log4j2_custom.xml"));
} else { } else {
options.add(new MakeProfileOptionLog4j(affected, null)); options.add(new MakeProfileOptionLog4j(affected, null));