Pass mainclass and gameargs to the main game via system properties (#3692)

This commit is contained in:
TheKodeToad 2025-04-28 09:47:25 +01:00 committed by GitHub
commit 0f7cb916cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -97,6 +97,19 @@ public final class StandardLauncher extends AbstractLauncher {
gameArgs.add(worldName); gameArgs.add(worldName);
} }
StringBuilder joinedGameArgs = new StringBuilder();
for (String gameArg : gameArgs) {
if (joinedGameArgs.length() > 0) {
joinedGameArgs.append('\u001F'); // unit separator, designed for this purpose
}
joinedGameArgs.append(gameArg);
}
// pass the real main class and game arguments in so mods can access them
System.setProperty("org.prismlauncher.launch.mainclass", mainClassName);
// unit separator ('\u001F') delimited list of game args
System.setProperty("org.prismlauncher.launch.gameargs", joinedGameArgs.toString());
// find and invoke the main method // find and invoke the main method
MethodHandle method = ReflectionUtils.findMainMethod(mainClassName); MethodHandle method = ReflectionUtils.findMainMethod(mainClassName);
method.invokeExact(gameArgs.toArray(new String[0])); method.invokeExact(gameArgs.toArray(new String[0]));