From 37db7b99a800099ad898cb782cde67e5d2c2d138 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Sep 2019 03:27:02 +0700 Subject: [PATCH 1/7] =?UTF-8?q?[FIX]=20=D0=9E=D0=BF=D0=B5=D1=87=D0=B0?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8?= =?UTF-8?q?=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20ProGuard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/pro/gravit/launchserver/defaults/proguard.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg index c15bcd6c..5a4eb1ef 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg @@ -20,9 +20,9 @@ -keepattributes Signature -adaptresourcefilecontents META-INF/MANIFEST.MF --keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.client.api.** +-keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.** --keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.client.api.** { +-keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.** { *; } From cc81494e4549a24dc192051638ca1d0261aa3fbd Mon Sep 17 00:00:00 2001 From: sasha0552 Date: Thu, 19 Sep 2019 20:30:43 +0000 Subject: [PATCH 2/7] GitLab CI --- .gitlab-ci.yml | 70 ++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f5cc7c9d..fc383772 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,41 +1,49 @@ -image: frekele/java +image: docker:latest +services: +- docker:dind + +variables: + DOCKER_DRIVER: overlay2 + CI_VERSION: '6.6.$CI_PIPELINE_IID' stages: - - build - - test - - deploy - -before_script: - # - echo `pwd` # debug - # - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug - - export GRADLE_USER_HOME=`pwd`/.gradle - - apt-get update -qq && apt-get install -y -qq git git-core - -cache: - key: ${CI_COMMIT_REF_NAME} - paths: - - .gradle/wrapper - - .gradle/caches +- build +- test build: + image: frekele/java stage: build + before_script: + - apt-get -y update + - apt-get -y install zip git + - export GRADLE_USER_HOME=`pwd`/.gradle + - chmod +x gradlew + - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules + - git submodule sync + - git submodule update --init --recursive script: - - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules - - git submodule sync - - git submodule update --init --recursive - - ./gradlew assemble - - mv LaunchServer/build/libs/*.jar LaunchServer - - mv ServerWrapper/build/libs/*.jar ServerWrapper - - mv modules/*_module/build/libs/*.jar modules - artifacts: + - ./gradlew assemble + after_script: + - mkdir -p artifacts/modules + - cd LaunchServer/build/libs/ + - zip -r -9 ../../../artifacts/libraries.zip * -x "LaunchServer.jar" -x "LaunchServer-clean.jar" + - mv LaunchServer.jar ../../../artifacts/LaunchServer.jar + - cd ../../../ServerWrapper/build/libs + - mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar + - cd ../../../ + - mv modules/*_module/build/libs/*.jar artifacts/modules + - mv modules/*_swmodule/build/libs/*.jar artifacts/modules + - mv modules/*_lmodule/build/libs/*.jar artifacts/modules + cache: paths: - - LaunchServer/*.jar - - ServerWrapper/*.jar - - modules/*.jar + - .gradle + artifacts: + expire_in: 6 week + paths: + - artifacts + test: + image: frekele/java stage: test script: - - ./gradlew check - -after_script: - - echo "End CI" + - ./gradlew check \ No newline at end of file From 8f42175ad47c6f3767c737b01c47a3119325b697 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Sep 2019 03:55:34 +0700 Subject: [PATCH 3/7] [FEATURE] ClientLaunchPhase event --- .../main/java/pro/gravit/launchserver/dao/User.java | 6 ------ .../pro/gravit/launcher/client/ClientLauncher.java | 2 ++ .../launcher/client/events/ClientLaunchPhase.java | 12 ++++++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java index 6dedae53..5c53dfde 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java @@ -39,12 +39,6 @@ public class User { public String serverID; private String password_salt; public long permissions; - //TODO: заменить EAGER на LASY и придумать способ сохранить сессию - // [ERROR] org.hibernate.LazyInitializationException: - // failed to lazily initialize a collection of role: pro.gravit.launchserver.dao.User.hwids, could not initialize proxy - no Session - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinColumn(name = "user_id") - public Collection hwids; public void setPassword(String password) { password_salt = SecurityHelper.randomStringAESKey(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 75458e4c..0c49f46e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -34,6 +34,7 @@ import pro.gravit.launcher.LauncherEngine; import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.ClientService; +import pro.gravit.launcher.client.events.ClientLaunchPhase; import pro.gravit.launcher.client.events.ClientLauncherInitPhase; import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.gui.JSRuntimeProvider; @@ -543,6 +544,7 @@ public static void main(String... args) throws Throwable { CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); verifyHDir(params.assetDir, assetHDir, assetMatcher, digest); verifyHDir(params.clientDir, clientHDir, clientMatcher, digest); + LauncherEngine.modulesManager.invokeEvent(new ClientLaunchPhase(params)); launch(profile, params); } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java new file mode 100644 index 00000000..a7429d53 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java @@ -0,0 +1,12 @@ +package pro.gravit.launcher.client.events; + +import pro.gravit.launcher.client.ClientLauncher; +import pro.gravit.launcher.modules.LauncherModule; + +public class ClientLaunchPhase extends LauncherModule.Event { + public final ClientLauncher.Params params; + + public ClientLaunchPhase(ClientLauncher.Params params) { + this.params = params; + } +} From 05b214c11a5d98b11418778e863cd72edddafb11 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Sep 2019 04:03:32 +0700 Subject: [PATCH 4/7] =?UTF-8?q?[FEATURE][FIX]=20=D0=9D=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20API=20=D0=B4=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=83=D0=BF=D0=B0=20=D0=BA=20=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B0=D0=BC=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B5=20=D0=BA=D0=BB=D0=B8?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientLauncher.java | 25 ++++++++++++++++--- .../client/events/ClientLaunchPhase.java | 6 ++--- .../events/ClientLauncherInitPhase.java | 6 +++++ .../events/ClientLauncherPostInitPhase.java | 12 +++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherPostInitPhase.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 0c49f46e..e0438ab8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -36,6 +36,7 @@ import pro.gravit.launcher.api.ClientService; import pro.gravit.launcher.client.events.ClientLaunchPhase; import pro.gravit.launcher.client.events.ClientLauncherInitPhase; +import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase; import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.gui.JSRuntimeProvider; import pro.gravit.launcher.hasher.FileNameMatcher; @@ -437,6 +438,21 @@ public static Process launch( clientStarted = false; return process; } + public static class ClientLaunchContext + { + public final Params params; + public final ClientProfile profile; + public final HashedDir assetHDir, clientHDir; + public DirWatcher assetWatcher, clientWatcher; + + + public ClientLaunchContext(Params params, ClientProfile profile, HashedDir assetHDir, HashedDir clientHDir) { + this.params = params; + this.profile = profile; + this.assetHDir = assetHDir; + this.clientHDir = clientHDir; + } + } @LauncherAPI public static void main(String... args) throws Throwable { @@ -477,11 +493,12 @@ public static void main(String... args) throws Throwable { System.exit(-98); return; } + ClientLaunchContext context = new ClientLaunchContext(params, profile, assetHDir, clientHDir); Launcher.profile = profile; playerProfile = params.pp; Request.setSession(params.session); checkJVMBitsAndVersion(); - LauncherEngine.modulesManager.invokeEvent(new ClientLauncherInitPhase()); + LauncherEngine.modulesManager.invokeEvent(new ClientLauncherInitPhase(context)); // Verify ClientLauncher sign and classpath LogHelper.debug("Verifying ClientLauncher sign and classpath"); LinkedList classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); @@ -537,14 +554,16 @@ public static void main(String... args) throws Throwable { // if (params.updateOptional.contains(s)) s.mark = true; // else hdir.removeR(s.file); //} + context.assetWatcher = assetWatcher; + context.clientWatcher = clientWatcher; Launcher.profile.pushOptionalFile(clientHDir, false); - LauncherEngine.modulesManager.invokeEvent(new PostInitPhase()); + LauncherEngine.modulesManager.invokeEvent(new ClientLauncherPostInitPhase(context)); // Start WatchService, and only then client CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); verifyHDir(params.assetDir, assetHDir, assetMatcher, digest); verifyHDir(params.clientDir, clientHDir, clientMatcher, digest); - LauncherEngine.modulesManager.invokeEvent(new ClientLaunchPhase(params)); + LauncherEngine.modulesManager.invokeEvent(new ClientLaunchPhase(context)); launch(profile, params); } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java index a7429d53..10db8ba1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLaunchPhase.java @@ -4,9 +4,9 @@ import pro.gravit.launcher.modules.LauncherModule; public class ClientLaunchPhase extends LauncherModule.Event { - public final ClientLauncher.Params params; + public final ClientLauncher.ClientLaunchContext context; - public ClientLaunchPhase(ClientLauncher.Params params) { - this.params = params; + public ClientLaunchPhase(ClientLauncher.ClientLaunchContext context) { + this.context = context; } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherInitPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherInitPhase.java index 4f10e732..83eea342 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherInitPhase.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherInitPhase.java @@ -1,6 +1,12 @@ package pro.gravit.launcher.client.events; +import pro.gravit.launcher.client.ClientLauncher; import pro.gravit.launcher.modules.events.InitPhase; public class ClientLauncherInitPhase extends InitPhase { + public final ClientLauncher.ClientLaunchContext context; + + public ClientLauncherInitPhase(ClientLauncher.ClientLaunchContext context) { + this.context = context; + } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherPostInitPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherPostInitPhase.java new file mode 100644 index 00000000..952ad735 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientLauncherPostInitPhase.java @@ -0,0 +1,12 @@ +package pro.gravit.launcher.client.events; + +import pro.gravit.launcher.client.ClientLauncher; +import pro.gravit.launcher.modules.events.PostInitPhase; + +public class ClientLauncherPostInitPhase extends PostInitPhase { + public final ClientLauncher.ClientLaunchContext context; + + public ClientLauncherPostInitPhase(ClientLauncher.ClientLaunchContext context) { + this.context = context; + } +} From d5692bd5750f1b046386e2197a6f35f8988fe75f Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Sep 2019 04:55:57 +0700 Subject: [PATCH 5/7] =?UTF-8?q?[FEATURE]=20=D0=9D=D0=BE=D0=B2=D0=BE=D0=B5?= =?UTF-8?q?=20API=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=B4=D0=BE=D0=B1=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/managers/SettingsManager.java | 5 -- .../launcher/config/JsonConfigurable.java | 69 ++-------------- .../config/JsonConfigurableInterface.java | 82 +++++++++++++++++++ .../launcher/config/SimpleConfigurable.java | 32 ++++++++ .../managers/SimpleModulesConfigManager.java | 6 ++ .../modules/ModulesConfigManager.java | 14 ++++ 6 files changed, 143 insertions(+), 65 deletions(-) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java index 6df99215..5aaa9a55 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java @@ -102,9 +102,4 @@ public void loadHDirStore() throws IOException { public void saveHDirStore() throws IOException { saveHDirStore(DirBridge.dirProjectStore); } - - @Override - public void setType(Type type) { - super.setType(type); - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java index 6972e023..63258b6c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java @@ -11,19 +11,9 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; -public abstract class JsonConfigurable { - private Type type; - protected Path configPath; - - @LauncherAPI - public void saveConfig() throws IOException { - saveConfig(configPath); - } - - @LauncherAPI - public void loadConfig() throws IOException { - loadConfig(configPath); - } +public abstract class JsonConfigurable implements JsonConfigurableInterface { + private transient final Type type; + protected transient final Path configPath; @LauncherAPI public JsonConfigurable(Type type, Path configPath) { @@ -31,55 +21,14 @@ public JsonConfigurable(Type type, Path configPath) { this.configPath = configPath; } - @LauncherAPI - public void saveConfig(Path configPath) throws IOException { - try (BufferedWriter writer = IOHelper.newWriter(configPath)) { - Launcher.gsonManager.configGson.toJson(getConfig(), type, writer); - } + @Override + public Path getPath() { + return configPath; } - @LauncherAPI - public void loadConfig(Path configPath) throws IOException { - if (generateConfigIfNotExists(configPath)) return; - try (BufferedReader reader = IOHelper.newReader(configPath)) { - setConfig(Launcher.gsonManager.configGson.fromJson(reader, type)); - } catch (Exception e) - { - LogHelper.error(e); - resetConfig(configPath); - } - } - - @LauncherAPI - public void resetConfig() throws IOException { - setConfig(getDefaultConfig()); - saveConfig(); - } - - @LauncherAPI - public void resetConfig(Path newPath) throws IOException { - setConfig(getDefaultConfig()); - saveConfig(newPath); - } - - @LauncherAPI - public boolean generateConfigIfNotExists(Path path) throws IOException { - if (IOHelper.isFile(path)) - return false; - resetConfig(path); - return true; - } - - @LauncherAPI - public boolean generateConfigIfNotExists() throws IOException { - if (IOHelper.isFile(configPath)) - return false; - resetConfig(); - return true; - } - - protected void setType(Type type) { - this.type = type; + @Override + public Type getType() { + return type; } @LauncherAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java new file mode 100644 index 00000000..dc02c2cc --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java @@ -0,0 +1,82 @@ +package pro.gravit.launcher.config; + +import com.google.gson.Gson; +import pro.gravit.launcher.Launcher; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Path; + +public interface JsonConfigurableInterface { + default void saveConfig() throws IOException { + saveConfig(getPath()); + } + + default void loadConfig() throws IOException { + loadConfig(getPath()); + } + + default void saveConfig(Gson gson, Path configPath) throws IOException { + try (BufferedWriter writer = IOHelper.newWriter(configPath)) { + gson.toJson(getConfig(), getType(), writer); + } + } + + default void loadConfig(Gson gson, Path configPath) throws IOException { + if (generateConfigIfNotExists(configPath)) return; + try (BufferedReader reader = IOHelper.newReader(configPath)) { + setConfig(gson.fromJson(reader, getType())); + } catch (Exception e) + { + LogHelper.error(e); + resetConfig(configPath); + } + } + + default void saveConfig(Path configPath) throws IOException { + saveConfig(Launcher.gsonManager.configGson, configPath); + } + + default void loadConfig(Path configPath) throws IOException { + loadConfig(Launcher.gsonManager.configGson, configPath); + } + + default void resetConfig() throws IOException { + setConfig(getDefaultConfig()); + saveConfig(); + } + + default void resetConfig(Path newPath) throws IOException { + setConfig(getDefaultConfig()); + saveConfig(newPath); + } + + default boolean generateConfigIfNotExists(Path path) throws IOException { + if (IOHelper.isFile(path)) + return false; + resetConfig(path); + return true; + } + + default boolean generateConfigIfNotExists() throws IOException { + if (IOHelper.isFile(getPath())) + return false; + resetConfig(); + return true; + } + + T getConfig(); + + T getDefaultConfig(); + + void setConfig(T config); + + Path getPath(); + + Type getType(); + +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java new file mode 100644 index 00000000..5027e9eb --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java @@ -0,0 +1,32 @@ +package pro.gravit.launcher.config; + +import java.nio.file.Path; + +public class SimpleConfigurable extends JsonConfigurable { + public T config; + private final Class tClass; + + public SimpleConfigurable(Class type, Path configPath) { + super(type, configPath); + tClass = type; + } + + @Override + public T getConfig() { + return config; + } + + @Override + public T getDefaultConfig() { + try { + return tClass.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + return null; + } + } + + @Override + public void setConfig(T config) { + this.config = config; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java index 54b1754c..a5379675 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java @@ -4,6 +4,7 @@ import java.nio.file.Files; import java.nio.file.Path; +import pro.gravit.launcher.config.SimpleConfigurable; import pro.gravit.launcher.modules.ModulesConfigManager; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -34,4 +35,9 @@ public Path getModuleConfigDir(String moduleName) { } return configDir.resolve(moduleName); } + + @Override + public SimpleConfigurable getConfigurable(Class tClass, Path configPath) { + return new SimpleConfigurable<>(tClass, configPath); + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java index 3d5522e5..1016ac14 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java @@ -1,5 +1,7 @@ package pro.gravit.launcher.modules; +import pro.gravit.launcher.config.SimpleConfigurable; + import java.nio.file.Path; public interface ModulesConfigManager { @@ -8,4 +10,16 @@ public interface ModulesConfigManager { Path getModuleConfig(String moduleName, String configName); Path getModuleConfigDir(String moduleName); + + SimpleConfigurable getConfigurable(Class tClass, Path configPath); + + default SimpleConfigurable getConfigurable(Class tClass, String moduleName) + { + return getConfigurable(tClass, getModuleConfig(moduleName)); + } + + default SimpleConfigurable getConfigurable(Class tClass, String moduleName, String configName) + { + return getConfigurable(tClass, getModuleConfig(moduleName, configName)); + } } From 327d2437619ddf020bf4de615db5ea015da3ca8e Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Sep 2019 04:59:53 +0700 Subject: [PATCH 6/7] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/command/dao/GetUserCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java index d5788850..132ef15b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java @@ -31,9 +31,9 @@ public void invoke(String... args) throws Exception { return; } LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString()); - for(UserHWID hwid : user.hwids) - { - LogHelper.info("[%s] HWID: memory: %d | serial %s | hwdiskserial: %s | processorID %s | macAddr %s", user.username, hwid.totalMemory, hwid.serialNumber, hwid.HWDiskSerial, hwid.processorID, hwid.macAddr); - } + //for(UserHWID hwid : user.hwids) + //{ + // LogHelper.info("[%s] HWID: memory: %d | serial %s | hwdiskserial: %s | processorID %s | macAddr %s", user.username, hwid.totalMemory, hwid.serialNumber, hwid.HWDiskSerial, hwid.processorID, hwid.macAddr); + //} } } From 034e5c154eea45004b36c355e27e7d0e028c9390 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Sep 2019 05:20:55 +0700 Subject: [PATCH 7/7] [FEATURE] SimpleConfig --- .../gravit/launcher/config/SimpleConfig.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java new file mode 100644 index 00000000..764cab2b --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java @@ -0,0 +1,39 @@ +package pro.gravit.launcher.config; + +import java.lang.reflect.Type; +import java.nio.file.Path; + +public abstract class SimpleConfig implements JsonConfigurableInterface { + private transient final Class type; + protected transient final Path configPath; + + protected SimpleConfig(Class type, Path configPath) { + this.type = type; + this.configPath = configPath; + } + @SuppressWarnings("unchecked") + @Override + public T getConfig() { + return (T) this; + } + + @Override + public T getDefaultConfig() { + try { + return type.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + return null; + } + } + + @Override + public Path getPath() { + return configPath; + } + + @Override + public Type getType() { + return type; + } + +}