mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] ServerWrapper 1.18 support
This commit is contained in:
parent
9cc1cf5feb
commit
9c289cd1cb
2 changed files with 22 additions and 8 deletions
|
@ -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<String> classpath;
|
||||
public ClientProfile.ClassLoaderConfig classLoaderConfig;
|
||||
public String librariesDir;
|
||||
public String mainclass;
|
||||
public List<String> args;
|
||||
|
|
|
@ -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(!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");
|
||||
|
|
Loading…
Reference in a new issue