diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index a0505386..5400b2b4 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -141,14 +141,16 @@ public void run(String... args) throws Throwable { } Class mainClass; if (config.classpath != null && !config.classpath.isEmpty()) { - if (!ServerAgent.isAgentStarted()) { - LogHelper.warning("JavaAgent not found. Using URLClassLoader"); + if(config.classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) { URL[] urls = config.classpath.stream().map(Paths::get).map(IOHelper::toURL).toArray(URL[]::new); ucp = new PublicURLClassLoader(urls); Thread.currentThread().setContextClassLoader(ucp); loader = ucp; - } else { - LogHelper.info("Found %d custom classpath elements", config.classpath.size()); + } else if(config.classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) { + if (!ServerAgent.isAgentStarted()) { + LogHelper.error("JavaAgent not found"); + System.exit(-1); + } for (String c : config.classpath) ServerAgent.addJVMClassPath(c); } @@ -207,6 +209,7 @@ public Config getDefaultConfig() { newConfig.args = new ArrayList<>(); newConfig.classpath = new ArrayList<>(); newConfig.address = "ws://localhost:9274/api"; + newConfig.classLoaderConfig = ClientProfile.ClassLoaderConfig.SYSTEM_ARGS; newConfig.env = LauncherConfig.LauncherEnvironment.STD; return newConfig; } @@ -219,6 +222,7 @@ public static final class Config { public boolean autoloadLibraries; public String logFile; public List classpath; + public ClientProfile.ClassLoaderConfig classLoaderConfig; public String librariesDir; public String mainclass; public List args; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index ef95b185..94194432 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -1,5 +1,6 @@ package pro.gravit.launcher.server.setup; +import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.StdWebSocketService; import pro.gravit.launcher.server.ServerWrapper; @@ -57,6 +58,7 @@ public void run() throws Exception { System.out.println("Print your server name:"); wrapper.config.serverName = commands.commandHandler.readLine(); wrapper.config.mainclass = mainClassName; + boolean altMode = false; for (int i = 0; i < 10; ++i) { if(!Request.isAvailable() || Request.getRequestService().isClosed()) { System.out.println("Print launchserver websocket host( ws://host:port/api ):"); @@ -84,6 +86,12 @@ public void run() throws Exception { ((AutoCloseable) Request.getRequestService()).close(); } } + if(wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfile.Version.MC118) >= 0) { + LogHelper.info("Switch to alternative start mode (1.18)"); + wrapper.config.classpath.add(jarName); + wrapper.config.classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER; + altMode = true; + } } wrapper.saveConfig(); LogHelper.info("Generate start script"); @@ -116,10 +124,12 @@ public void run() throws Exception { writer.append("-cp "); String pathServerWrapper = IOHelper.getCodeSource(ServerWrapper.class).getFileName().toString(); writer.append(pathServerWrapper); - if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { - writer.append(";"); - } else writer.append(":"); - writer.append(jarName); + if(!altMode) { + if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { + writer.append(";"); + } else writer.append(":"); + writer.append(jarName); + } writer.append(" "); writer.append(ServerWrapper.class.getName()); writer.append("\n");