From fc13442c89d9ad4bc163c0390ee0a66bb81f21c6 Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 26 Mar 2021 22:06:44 +0700 Subject: [PATCH] [FEATURE] Updates and profiles sync in new thread --- .../pro/gravit/launchserver/LaunchServer.java | 28 +++++++++++-------- .../events/LaunchServerProfilesSyncEvent.java | 12 ++++++++ .../events/LaunchServerUpdatesSyncEvent.java | 12 ++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 3c34c5b5..ce374017 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -15,10 +15,7 @@ import pro.gravit.launchserver.launchermodules.LauncherModuleLoader; import pro.gravit.launchserver.manangers.*; import pro.gravit.launchserver.manangers.hook.AuthHookManager; -import pro.gravit.launchserver.modules.events.LaunchServerFullInitEvent; -import pro.gravit.launchserver.modules.events.LaunchServerInitPhase; -import pro.gravit.launchserver.modules.events.LaunchServerPostInitPhase; -import pro.gravit.launchserver.modules.events.NewLaunchServerInstanceEvent; +import pro.gravit.launchserver.modules.events.*; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler; import pro.gravit.utils.command.Command; @@ -163,14 +160,23 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La LogHelper.debug("Init components successful"); } // Sync updates dir - if (!IOHelper.isDir(updatesDir)) - Files.createDirectory(updatesDir); - syncUpdatesDir(null); + CommonHelper.newThread("Profiles and updates sync", true, () -> { + try { + if (!IOHelper.isDir(updatesDir)) + Files.createDirectory(updatesDir); + syncUpdatesDir(null); + modulesManager.invokeEvent(new LaunchServerUpdatesSyncEvent(this)); - // Sync profiles dir - if (!IOHelper.isDir(profilesDir)) - Files.createDirectory(profilesDir); - syncProfilesDir(); + // Sync profiles dir + if (!IOHelper.isDir(profilesDir)) + Files.createDirectory(profilesDir); + syncProfilesDir(); + modulesManager.invokeEvent(new LaunchServerProfilesSyncEvent(this)); + } catch (IOException e) { + LogHelper.error(e); + LogHelper.error("Updates/Profiles not synced"); + } + }); launcherModuleLoader.init(); nettyServerSocketHandler = new NettyServerSocketHandler(this); // post init modules diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java new file mode 100644 index 00000000..c49ff4a5 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java @@ -0,0 +1,12 @@ +package pro.gravit.launchserver.modules.events; + +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launchserver.LaunchServer; + +public class LaunchServerProfilesSyncEvent extends LauncherModule.Event { + public final LaunchServer server; + + public LaunchServerProfilesSyncEvent(LaunchServer server) { + this.server = server; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java new file mode 100644 index 00000000..c8afddf8 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java @@ -0,0 +1,12 @@ +package pro.gravit.launchserver.modules.events; + +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launchserver.LaunchServer; + +public class LaunchServerUpdatesSyncEvent extends LauncherModule.Event { + public final LaunchServer server; + + public LaunchServerUpdatesSyncEvent(LaunchServer server) { + this.server = server; + } +}