From 722f61da2e2b09e647c4224f905090fe61569407 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:01:11 +0100 Subject: [PATCH] Remove legacy ServerMain and empty ICrashCallable (#77) --- .../net/neoforged/fml/ICrashCallable.java | 5 -- .../net/neoforged/fml/server/ServerMain.java | 68 ------------------- 2 files changed, 73 deletions(-) delete mode 100644 loader/src/main/java/net/neoforged/fml/ICrashCallable.java delete mode 100644 loader/src/main/java/net/neoforged/fml/server/ServerMain.java diff --git a/loader/src/main/java/net/neoforged/fml/ICrashCallable.java b/loader/src/main/java/net/neoforged/fml/ICrashCallable.java deleted file mode 100644 index 9aead232..00000000 --- a/loader/src/main/java/net/neoforged/fml/ICrashCallable.java +++ /dev/null @@ -1,5 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - diff --git a/loader/src/main/java/net/neoforged/fml/server/ServerMain.java b/loader/src/main/java/net/neoforged/fml/server/ServerMain.java deleted file mode 100644 index 6af4d522..00000000 --- a/loader/src/main/java/net/neoforged/fml/server/ServerMain.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - -package net.neoforged.fml.server; - -import cpw.mods.modlauncher.InvalidLauncherSetupException; -import cpw.mods.modlauncher.Launcher; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.security.CodeSource; -import java.security.ProtectionDomain; -import java.util.Optional; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - -public class ServerMain { - public static void main(String[] args) { - try { - Class.forName("cpw.mods.modlauncher.Launcher", false, ClassLoader.getSystemClassLoader()); - Class.forName("net.neoforged.neoforgespi.Environment", false, ClassLoader.getSystemClassLoader()); - } catch (ClassNotFoundException cnfe) { - System.err.println("FATAL ERROR, You need to run the installer. The libraries required to launch a server are missing"); - System.exit(1); - } - - final String launchArgs = Optional.ofNullable(ServerMain.class.getProtectionDomain()). - map(ProtectionDomain::getCodeSource). - map(CodeSource::getLocation). - map(ServerMain::urlToManifest). - map(Manifest::getMainAttributes). - map(a -> a.getValue("ServerLaunchArgs")). - orElseThrow(ServerMain::throwMissingManifest); - String[] defaultargs = launchArgs.split(" "); - String[] result = new String[args.length + defaultargs.length]; - System.arraycopy(defaultargs, 0, result, 0, defaultargs.length); - System.arraycopy(args, 0, result, defaultargs.length, args.length); - // separate class, so the exception can resolve - new Runner().runLauncher(result); - } - - private static class Runner { - private void runLauncher(final String[] result) { - try { - Launcher.main(result); - } catch (InvalidLauncherSetupException e) { - System.err.println("The server is missing critical libraries and cannot load. Please run the installer to correct this"); - System.exit(1); - } - } - } - private static Manifest urlToManifest(URL url) { - try { - return new JarFile(new File(url.toURI())).getManifest(); - } catch (URISyntaxException | IOException e) { - return null; - } - } - - private static RuntimeException throwMissingManifest() { - System.err.println("This is not being run from a valid JAR file, essential data is missing."); - return new RuntimeException("Missing the manifest"); - } -}