From b638efc0d186d819489a706076041c26253f59ef Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:57:37 +0700 Subject: [PATCH] [FEATURE] Support compat classes in ServerWrapper --- .../pro/gravit/launcher/server/ServerWrapper.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 266edc6a..42f2aa47 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -24,6 +24,9 @@ import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.launch.*; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.lang.reflect.Type; import java.nio.file.Path; import java.nio.file.Paths; @@ -191,6 +194,13 @@ public void run(String... args) throws Throwable { LogHelper.info("Start Minecraft Server"); LogHelper.debug("Invoke main method %s with %s", classname, launch.getClass().getName()); try { + if(config.compatClasses != null) { + for (String e : config.compatClasses) { + Class clazz = classLoaderControl.getClass(e); + MethodHandle runMethod = MethodHandles.lookup().findStatic(clazz, "run", MethodType.methodType(void.class, ClassLoaderControl.class)); + runMethod.invoke(classLoaderControl); + } + } launch.launch(config.mainclass, config.mainmodule, Arrays.asList(real_args)); } catch (Throwable e) { LogHelper.error(e); @@ -242,6 +252,7 @@ public static final class Config { public String mainmodule; public String nativesDir = "natives"; public List args; + public List compatClasses; public String authId; public AuthRequestEvent.OAuthRequestEvent oauth; public long oauthExpireTime;