[FEATURE][EXPERIMENTAL] Новая система модулей в ServerWrapper и ClientLauncher/LauncherEngine

This commit is contained in:
Gravit 2019-08-26 18:22:24 +07:00
parent 497e07094a
commit d65d858bc9
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
27 changed files with 207 additions and 141 deletions

View file

@ -100,6 +100,12 @@ public static void main(String[] args) throws Exception {
IOHelper.write(publicKeyFile, publicKey.getEncoded());
IOHelper.write(privateKeyFile, privateKey.getEncoded());
}
modulesManager.invokeEvent(new PreConfigPhase());
generateConfigIfNotExists(configFile, localCommandHandler, env);
LogHelper.info("Reading LaunchServer config file");
try (BufferedReader reader = IOHelper.newReader(configFile)) {
config = Launcher.gsonManager.gson.fromJson(reader, LaunchServerConfig.class);
}
if (!Files.exists(runtimeConfigFile)) {
LogHelper.info("Reset LaunchServer runtime config file");
runtimeConfig = new LaunchServerRuntimeConfig();
@ -110,12 +116,6 @@ public static void main(String[] args) throws Exception {
runtimeConfig = Launcher.gsonManager.gson.fromJson(reader, LaunchServerRuntimeConfig.class);
}
}
modulesManager.invokeEvent(new PreConfigPhase());
generateConfigIfNotExists(configFile, localCommandHandler, env);
LogHelper.info("Reading LaunchServer config file");
try (BufferedReader reader = IOHelper.newReader(configFile)) {
config = Launcher.gsonManager.gson.fromJson(reader, LaunchServerConfig.class);
}
LaunchServer.LaunchServerConfigManager launchServerConfigManager = new LaunchServer.LaunchServerConfigManager() {
@Override

View file

@ -7,6 +7,8 @@
import pro.gravit.launcher.client.DirBridge;
import pro.gravit.launcher.client.FunctionalBridge;
import pro.gravit.launcher.client.LauncherUpdateController;
import pro.gravit.launcher.client.events.ClientEngineInitPhase;
import pro.gravit.launcher.client.events.ClientPreGuiPhase;
import pro.gravit.launcher.guard.LauncherGuardManager;
import pro.gravit.launcher.gui.JSRuntimeProvider;
import pro.gravit.launcher.gui.RuntimeProvider;
@ -14,6 +16,9 @@
import pro.gravit.launcher.managers.ClientGsonManager;
import pro.gravit.launcher.managers.ClientHookManager;
import pro.gravit.launcher.managers.ConsoleManager;
import pro.gravit.launcher.modules.LauncherModulesManager;
import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.launcher.modules.impl.SimpleModuleManager;
import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.RequestException;
import pro.gravit.launcher.request.auth.RestoreSessionRequest;
@ -33,10 +38,15 @@ public static void main(String... args) throws Throwable {
//if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
LogHelper.printVersion("Launcher");
LogHelper.printLicense("Launcher");
LauncherEngine.modulesManager = new ClientModuleManager();
LauncherConfig.getAutogenConfig().initModules();
LauncherEngine.modulesManager.initModules(null);
// Start Launcher
initGson();
initGson(LauncherEngine.modulesManager);
ConsoleManager.initConsole();
HWIDProvider.registerHWIDs();
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
LauncherConfig config = Launcher.getConfig();
if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) {
if (!LauncherAgent.isStarted()) throw new SecurityException("LauncherAgent must started");
@ -55,8 +65,8 @@ public static void main(String... args) throws Throwable {
System.exit(0);
}
public static void initGson() {
Launcher.gsonManager = new ClientGsonManager();
public static void initGson(ClientModuleManager modulesManager) {
Launcher.gsonManager = new ClientGsonManager(modulesManager);
Launcher.gsonManager.initGson();
}
@ -64,6 +74,8 @@ public static void initGson() {
private final AtomicBoolean started = new AtomicBoolean(false);
public RuntimeProvider runtimeProvider;
public static ClientModuleManager modulesManager;
private LauncherEngine() {
}
@ -71,9 +83,10 @@ private LauncherEngine() {
@LauncherAPI
public void start(String... args) throws Throwable {
Launcher.modulesManager = new ClientModuleManager(this);
LauncherConfig.getAutogenConfig().initModules();
Launcher.modulesManager.preInitModules();
//Launcher.modulesManager = new ClientModuleManager(this);
ClientPreGuiPhase event = new ClientPreGuiPhase(null);
LauncherEngine.modulesManager.invokeEvent(event);
runtimeProvider = event.runtimeProvider;
if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider();
ClientHookManager.initGuiHook.hook(runtimeProvider);
runtimeProvider.init(false);
@ -105,7 +118,7 @@ public void start(String... args) throws Throwable {
Objects.requireNonNull(args, "args");
if (started.getAndSet(true))
throw new IllegalStateException("Launcher has been already started");
Launcher.modulesManager.initModules();
LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this));
runtimeProvider.preLoad();
FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID);
FunctionalBridge.getHWID.start();

View file

@ -32,6 +32,7 @@
import pro.gravit.launcher.LauncherAgent;
import pro.gravit.launcher.LauncherConfig;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.client.events.ClientLauncherInitPhase;
import pro.gravit.launcher.guard.LauncherGuardManager;
import pro.gravit.launcher.gui.JSRuntimeProvider;
import pro.gravit.launcher.hasher.FileNameMatcher;
@ -39,6 +40,8 @@
import pro.gravit.launcher.hwid.HWIDProvider;
import pro.gravit.launcher.managers.ClientGsonManager;
import pro.gravit.launcher.managers.ClientHookManager;
import pro.gravit.launcher.modules.events.PostInitPhase;
import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launcher.request.Request;
@ -435,10 +438,12 @@ public static Process launch(
@LauncherAPI
public static void main(String... args) throws Throwable {
LauncherEngine engine = LauncherEngine.clientInstance();
Launcher.modulesManager = new ClientModuleManager(engine);
//Launcher.modulesManager = new ClientModuleManager(engine);
LauncherEngine.modulesManager = new ClientModuleManager();
LauncherConfig.getAutogenConfig().initModules(); //INIT
initGson();
Launcher.modulesManager.preInitModules();
initGson(LauncherEngine.modulesManager);
//Launcher.modulesManager.preInitModules();
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
JVMHelper.verifySystemProperties(ClientLauncher.class, true);
EnvHelper.checkDangerousParams();
JVMHelper.checkStackTrace(ClientLauncher.class);
@ -472,7 +477,7 @@ public static void main(String... args) throws Throwable {
playerProfile = params.pp;
Request.setSession(params.session);
checkJVMBitsAndVersion();
Launcher.modulesManager.initModules();
LauncherEngine.modulesManager.invokeEvent(new ClientLauncherInitPhase());
// Verify ClientLauncher sign and classpath
LogHelper.debug("Verifying ClientLauncher sign and classpath");
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath());
@ -524,7 +529,7 @@ public static void main(String... args) throws Throwable {
// else hdir.removeR(s.file);
//}
Launcher.profile.pushOptionalFile(clientHDir, false);
Launcher.modulesManager.postInitModules();
LauncherEngine.modulesManager.invokeEvent(new PostInitPhase());
// Start WatchService, and only then client
CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start();
CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start();
@ -555,8 +560,8 @@ private static Stream<Path> resolveClassPathStream(Path clientDir, String... cla
return builder.build();
}
private static void initGson() {
Launcher.gsonManager = new ClientGsonManager();
private static void initGson(ClientModuleManager moduleManager) {
Launcher.gsonManager = new ClientGsonManager(moduleManager);
Launcher.gsonManager.initGson();
}

View file

@ -1,30 +0,0 @@
package pro.gravit.launcher.client;
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.modules.ModuleContext;
import pro.gravit.launcher.modules.ModulesConfigManager;
import pro.gravit.launcher.modules.ModulesManager;
public class ClientModuleContext implements ModuleContext {
public final LauncherEngine engine;
ClientModuleContext(LauncherEngine engine) {
this.engine = engine;
}
@Override
public Type getType() {
return Type.CLIENT;
}
@Override
public ModulesManager getModulesManager() {
return Launcher.modulesManager;
}
@Override
public ModulesConfigManager getModulesConfigManager() {
return null; // ClientModuleContext не поддерживает modulesConfigManager
}
}

View file

@ -1,25 +1,28 @@
package pro.gravit.launcher.client;
import java.net.URL;
import java.util.ArrayList;
import pro.gravit.launcher.modules.LauncherModule;
import pro.gravit.launcher.modules.impl.SimpleModuleManager;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.managers.SimpleModuleManager;
import java.io.IOException;
import java.nio.file.Path;
public class ClientModuleManager extends SimpleModuleManager {
public ClientModuleManager(LauncherEngine engine) {
context = new ClientModuleContext(engine);
modules = new ArrayList<>();
public ClientModuleManager() {
super(null, null);
}
@Override
public void loadModule(URL jarpath, String classname) {
throw new SecurityException("Custom JAR's load not allowed here");
public void autoload() throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void loadModuleFull(URL jarpath) {
throw new SecurityException("Custom JAR's load not allowed here");
public void autoload(Path dir) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public LauncherModule loadModule(Path file) throws IOException {
throw new UnsupportedOperationException();
}
}

View file

@ -0,0 +1,12 @@
package pro.gravit.launcher.client.events;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.modules.events.InitPhase;
public class ClientEngineInitPhase extends InitPhase {
public final LauncherEngine engine;
public ClientEngineInitPhase(LauncherEngine engine) {
this.engine = engine;
}
}

View file

@ -0,0 +1,12 @@
package pro.gravit.launcher.client.events;
import pro.gravit.launcher.gui.RuntimeProvider;
import pro.gravit.launcher.modules.LauncherModule;
public class ClientGuiPhase extends LauncherModule.Event {
public final RuntimeProvider runtimeProvider;
public ClientGuiPhase(RuntimeProvider runtimeProvider) {
this.runtimeProvider = runtimeProvider;
}
}

View file

@ -0,0 +1,6 @@
package pro.gravit.launcher.client.events;
import pro.gravit.launcher.modules.events.InitPhase;
public class ClientLauncherInitPhase extends InitPhase {
}

View file

@ -0,0 +1,12 @@
package pro.gravit.launcher.client.events;
import pro.gravit.launcher.gui.RuntimeProvider;
import pro.gravit.launcher.modules.LauncherModule;
public class ClientPreGuiPhase extends LauncherModule.Event {
public RuntimeProvider runtimeProvider;
public ClientPreGuiPhase(RuntimeProvider runtimeProvider) {
this.runtimeProvider = runtimeProvider;
}
}

View file

@ -11,16 +11,13 @@
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import pro.gravit.launcher.JSApplication;
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.LauncherAPI;
import pro.gravit.launcher.LauncherConfig;
import pro.gravit.launcher.NewLauncherSettings;
import pro.gravit.launcher.*;
import pro.gravit.launcher.client.ClientLauncher;
import pro.gravit.launcher.client.DirBridge;
import pro.gravit.launcher.client.FunctionalBridge;
import pro.gravit.launcher.client.ServerPinger;
import pro.gravit.launcher.client.UserSettings;
import pro.gravit.launcher.client.events.ClientGuiPhase;
import pro.gravit.launcher.hasher.FileNameMatcher;
import pro.gravit.launcher.hasher.HashedDir;
import pro.gravit.launcher.hasher.HashedEntry;
@ -28,6 +25,7 @@
import pro.gravit.launcher.hwid.NoHWID;
import pro.gravit.launcher.hwid.OshiHWID;
import pro.gravit.launcher.managers.SettingsManager;
import pro.gravit.launcher.modules.events.ClosePhase;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launcher.profiles.Texture;
@ -163,9 +161,9 @@ public void run(String[] args) throws ScriptException, NoSuchMethodException, IO
preLoad();
loadScript(Launcher.INIT_SCRIPT_FILE);
LogHelper.info("Invoking start() function");
Launcher.modulesManager.postInitModules();
LauncherEngine.modulesManager.invokeEvent(new ClientGuiPhase(this));
((Invocable) engine).invokeFunction("start", (Object) args);
Launcher.modulesManager.finishModules();
LauncherEngine.modulesManager.invokeEvent(new ClosePhase());
}
@Override

View file

@ -2,18 +2,27 @@
import com.google.gson.GsonBuilder;
import pro.gravit.launcher.client.ClientModuleManager;
import pro.gravit.launcher.client.UserSettings;
import pro.gravit.launcher.hwid.HWID;
import pro.gravit.launcher.hwid.HWIDProvider;
import pro.gravit.launcher.modules.events.PreGsonPhase;
import pro.gravit.launcher.request.websockets.ClientWebSocketService;
import pro.gravit.utils.UniversalJsonAdapter;
public class ClientGsonManager extends GsonManager {
private final ClientModuleManager moduleManager;
public ClientGsonManager(ClientModuleManager moduleManager) {
this.moduleManager = moduleManager;
}
@Override
public void registerAdapters(GsonBuilder builder) {
super.registerAdapters(builder);
builder.registerTypeAdapter(UserSettings.class, new UniversalJsonAdapter<>(UserSettings.providers));
builder.registerTypeAdapter(HWID.class, new UniversalJsonAdapter<>(HWIDProvider.hwids));
ClientWebSocketService.appendTypeAdapters(builder);
moduleManager.invokeEvent(new PreGsonPhase(builder));
}
}

View file

@ -34,8 +34,6 @@ public final class Launcher {
private static final AtomicReference<LauncherConfig> CONFIG = new AtomicReference<>();
@LauncherAPI
public static ModulesManager modulesManager = null;
@LauncherAPI
public static final int PROTOCOL_MAGIC_LEGACY = 0x724724_00 + 24;
@LauncherAPI
public static final int PROTOCOL_MAGIC = 0xA205B064; // e = 2.718281828

View file

@ -18,7 +18,7 @@
import pro.gravit.utils.PublicURLClassLoader;
import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
@Deprecated
public class SimpleModuleManager implements ModulesManager {
protected final class ModulesVisitor extends SimpleFileVisitor<Path> {
private ModulesVisitor() {

View file

@ -1,7 +1,7 @@
package pro.gravit.launcher.modules;
import pro.gravit.utils.Version;
@Deprecated
public interface Module extends AutoCloseable {
String getName();

View file

@ -1,5 +1,5 @@
package pro.gravit.launcher.modules;
@Deprecated
public interface ModuleContext {
enum Type {
SERVER, CLIENT, LAUNCHSERVER

View file

@ -1,7 +1,7 @@
package pro.gravit.launcher.modules;
import java.net.URL;
@Deprecated
public interface ModulesManager extends AutoCloseable {
void initModules();

View file

@ -1,20 +0,0 @@
package pro.gravit.launcher.server;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import pro.gravit.launcher.managers.SimpleModuleManager;
import pro.gravit.launcher.managers.SimpleModulesConfigManager;
import pro.gravit.utils.PublicURLClassLoader;
public class ModulesManager extends SimpleModuleManager {
public SimpleModulesConfigManager modulesConfigManager;
public ModulesManager(ServerWrapper wrapper) {
modules = new ArrayList<>();
modulesConfigManager = new SimpleModulesConfigManager(Paths.get("modules-config"));
classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
context = new ServerModuleContext(wrapper, classloader, modulesConfigManager);
}
}

View file

@ -1,35 +0,0 @@
package pro.gravit.launcher.server;
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.managers.SimpleModulesConfigManager;
import pro.gravit.launcher.modules.ModuleContext;
import pro.gravit.launcher.modules.ModulesConfigManager;
import pro.gravit.launcher.modules.ModulesManager;
import pro.gravit.utils.PublicURLClassLoader;
public class ServerModuleContext implements ModuleContext {
public final PublicURLClassLoader classLoader;
public final ServerWrapper wrapper;
public final SimpleModulesConfigManager modulesConfigManager;
public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, SimpleModulesConfigManager modulesConfigManager) {
this.classLoader = classLoader;
this.wrapper = wrapper;
this.modulesConfigManager = modulesConfigManager;
}
@Override
public Type getType() {
return Type.SERVER;
}
@Override
public ModulesManager getModulesManager() {
return Launcher.modulesManager;
}
@Override
public ModulesConfigManager getModulesConfigManager() {
return modulesConfigManager;
}
}

View file

@ -17,6 +17,8 @@
import pro.gravit.launcher.LauncherConfig;
import pro.gravit.launcher.config.JsonConfigurable;
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
import pro.gravit.launcher.modules.events.PostInitPhase;
import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.RequestException;
@ -30,7 +32,7 @@
import pro.gravit.utils.helper.SecurityHelper;
public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
public ModulesManager modulesManager;
public static ServerWrapperModulesManager modulesManager;
public Config config;
public PublicURLClassLoader ucp;
public ClassLoader loader;
@ -38,6 +40,7 @@ public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
public static ServerWrapper wrapper;
public static Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir", "modules"));
public static Path modulesConfigDir = Paths.get(System.getProperty("serverwrapper.modulesConfigDir", "modules-config"));
public static Path configFile = Paths.get(System.getProperty("serverwrapper.configFile", "ServerWrapperConfig.json"));
public static Path publicKeyFile = Paths.get(System.getProperty("serverwrapper.publicKeyFile", "public.key"));
public static boolean disableSetup = Boolean.valueOf(System.getProperty("serverwrapper.disableSetup", "false"));
@ -93,13 +96,13 @@ public boolean loopAuth(int count, int sleeptime) {
return false;
}
public static void initGson() {
Launcher.gsonManager = new ServerWrapperGsonManager();
public static void initGson(ServerWrapperModulesManager modulesManager) {
Launcher.gsonManager = new ServerWrapperGsonManager(modulesManager);
Launcher.gsonManager.initGson();
}
public void run(String... args) throws Throwable {
initGson();
initGson(modulesManager);
if (args.length > 0 && args[0].equals("setup") && !disableSetup) {
LogHelper.debug("Read ServerWrapperConfig.json");
loadConfig();
@ -107,10 +110,7 @@ public void run(String... args) throws Throwable {
setup.run();
System.exit(0);
}
modulesManager = new ModulesManager(wrapper);
modulesManager.autoload(modulesDir);
Launcher.modulesManager = modulesManager;
modulesManager.preInitModules();
modulesManager.invokeEvent(new PreConfigPhase());
LogHelper.debug("Read ServerWrapperConfig.json");
loadConfig();
updateLauncherConfig();
@ -120,7 +120,7 @@ public void run(String... args) throws Throwable {
if (config.syncAuth) auth();
else
CommonHelper.newThread("Server Auth Thread", true, () -> loopAuth(config.reconnectCount, config.reconnectSleep));
modulesManager.initModules();
modulesManager.invokeEvent(new ServerWrapperInitPhase(this));
String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass;
if (classname.length() == 0) {
LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.cfg or first commandline argument");
@ -156,7 +156,7 @@ public void run(String... args) throws Throwable {
if (loader != null) mainClass = Class.forName(classname, true, loader);
else mainClass = Class.forName(classname);
MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
modulesManager.postInitModules();
modulesManager.invokeEvent(new PostInitPhase());
Request.service.reconnectCallback = () ->
{
LogHelper.debug("WebSocket connect closed. Try reconnect");
@ -202,6 +202,9 @@ public void updateLauncherConfig() {
public static void main(String... args) throws Throwable {
LogHelper.printVersion("ServerWrapper");
LogHelper.printLicense("ServerWrapper");
modulesManager = new ServerWrapperModulesManager(modulesDir, modulesConfigDir);
modulesManager.autoload();
modulesManager.initModules(null);
ServerWrapper.wrapper = new ServerWrapper(ServerWrapper.Config.class, configFile);
ServerWrapper.wrapper.run(args);
}

View file

@ -3,12 +3,20 @@
import com.google.gson.GsonBuilder;
import pro.gravit.launcher.managers.GsonManager;
import pro.gravit.launcher.modules.events.PreGsonPhase;
import pro.gravit.launcher.request.websockets.ClientWebSocketService;
public class ServerWrapperGsonManager extends GsonManager {
private final ServerWrapperModulesManager modulesManager;
public ServerWrapperGsonManager(ServerWrapperModulesManager modulesManager) {
this.modulesManager = modulesManager;
}
@Override
public void registerAdapters(GsonBuilder builder) {
super.registerAdapters(builder);
ClientWebSocketService.appendTypeAdapters(builder);
modulesManager.invokeEvent(new PreGsonPhase(builder));
}
}

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.server;
import pro.gravit.launcher.modules.LauncherInitContext;
public class ServerWrapperInitContext implements LauncherInitContext {
public final ServerWrapper serverWrapper;
public ServerWrapperInitContext(ServerWrapper serverWrapper) {
this.serverWrapper = serverWrapper;
}
}

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.server;
import pro.gravit.launcher.modules.LauncherModule;
public class ServerWrapperInitPhase extends LauncherModule.Event {
public final ServerWrapper serverWrapper;
public ServerWrapperInitPhase(ServerWrapper serverWrapper) {
this.serverWrapper = serverWrapper;
}
}

View file

@ -0,0 +1,15 @@
package pro.gravit.launcher.server;
import pro.gravit.launcher.modules.impl.SimpleModuleManager;
import java.nio.file.Path;
public class ServerWrapperModulesManager extends SimpleModuleManager {
public ServerWrapperModulesManager(Path modulesDir, Path configDir) {
super(modulesDir, configDir);
}
public void fullInitializeServerWrapper(ServerWrapper serverWrapper)
{
initContext = new ServerWrapperInitContext(serverWrapper);
}
}

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.server.setup;
import pro.gravit.launcher.modules.LauncherModule;
public class ServerWrapperPostSetupEvent extends LauncherModule.Event {
public final ServerWrapperSetup setup;
public ServerWrapperPostSetupEvent(ServerWrapperSetup setup) {
this.setup = setup;
}
}

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.server.setup;
import pro.gravit.launcher.modules.LauncherModule;
public class ServerWrapperPreSetupEvent extends LauncherModule.Event {
public final ServerWrapperSetup setup;
public ServerWrapperPreSetupEvent(ServerWrapperSetup setup) {
this.setup = setup;
}
}

View file

@ -20,6 +20,7 @@ public class ServerWrapperSetup {
public void run() throws IOException {
ServerWrapper wrapper = ServerWrapper.wrapper;
ServerWrapper.modulesManager.invokeEvent(new ServerWrapperPreSetupEvent(this));
System.out.println("Print jar filename:");
String jarName = commands.commandHandler.readLine();
Path jarPath = Paths.get(jarName);
@ -86,6 +87,7 @@ public void run() throws IOException {
Path startScriptBak = Paths.get("start.bak");
IOHelper.move(startScript, startScriptBak);
}
ServerWrapper.modulesManager.invokeEvent(new ServerWrapperSetupEvent(this));
try (Writer writer = IOHelper.newWriter(startScript)) {
if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
writer.append("#!/bin/sh\n\n");
@ -108,7 +110,7 @@ public void run() throws IOException {
writer.append(ServerWrapper.class.getName());
writer.append("\n");
}
ServerWrapper.modulesManager.invokeEvent(new ServerWrapperPostSetupEvent(this));
}
public ServerWrapperSetup() throws IOException {

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.server.setup;
import pro.gravit.launcher.modules.LauncherModule;
public class ServerWrapperSetupEvent extends LauncherModule.Event {
public final ServerWrapperSetup setup;
public ServerWrapperSetupEvent(ServerWrapperSetup setup) {
this.setup = setup;
}
}