From 68540a1c4478c4bb86d9c3731069d309441deadd Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 12 Jan 2019 07:13:24 +0700 Subject: [PATCH] [FEATURE] ModulesConfigManager --- .../ru/gravit/launchserver/LaunchServer.java | 8 ++++ .../manangers/ModulesManager.java | 7 +++- .../modules/LaunchServerModuleContext.java | 11 ++++- .../launcher/client/ClientModuleContext.java | 6 +++ .../launcher/client/ClientModuleManager.java | 2 +- .../launcher/server/ModulesManager.java | 8 +++- .../launcher/server/ServerModuleContext.java | 11 ++++- .../managers/ModulesConfigManager.java | 40 +++++++++++++++++++ .../SimpleModuleManager.java | 5 ++- .../launcher/modules/ModuleContext.java | 1 + .../ModulesConfigManagerInterface.java | 8 ++++ 11 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java rename libLauncher/src/main/java/ru/gravit/launcher/{modules => managers}/SimpleModuleManager.java (96%) create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index f2421da7..edf26110 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -189,6 +189,14 @@ public void verify() { { throw new NullPointerException("TextureProvider must not be null"); } + if(permissionsHandler == null) + { + throw new NullPointerException("PermissionsHandler must not be null"); + } + if(env == null) + { + throw new NullPointerException("Env must not be null"); + } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java index 3364a488..f20d7d90 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -3,17 +3,20 @@ import java.net.URL; import java.util.ArrayList; -import ru.gravit.launcher.modules.SimpleModuleManager; +import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.modules.CoreModule; import ru.gravit.launchserver.modules.LaunchServerModuleContext; import ru.gravit.utils.PublicURLClassLoader; public class ModulesManager extends SimpleModuleManager { + public ModulesConfigManager configManager; public ModulesManager(LaunchServer lsrv) { modules = new ArrayList<>(1); + configManager = new ModulesConfigManager(lsrv.dir.resolve("config")); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); - context = new LaunchServerModuleContext(lsrv, classloader); + context = new LaunchServerModuleContext(lsrv, classloader, configManager); registerCoreModule(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java index 30279000..1e43c23e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java @@ -1,6 +1,8 @@ package ru.gravit.launchserver.modules; +import ru.gravit.launcher.managers.ModulesConfigManager; import ru.gravit.launcher.modules.ModuleContext; +import ru.gravit.launcher.modules.ModulesConfigManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.PublicURLClassLoader; @@ -8,10 +10,12 @@ public class LaunchServerModuleContext implements ModuleContext { public final LaunchServer launchServer; public final PublicURLClassLoader classloader; + public final ModulesConfigManager modulesConfigManager; - public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader) { + public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, ModulesConfigManager modulesConfigManager) { launchServer = server; this.classloader = classloader; + this.modulesConfigManager = modulesConfigManager; } @Override @@ -23,4 +27,9 @@ public Type getType() { public ModulesManagerInterface getModulesManager() { return launchServer.modulesManager; } + + @Override + public ModulesConfigManagerInterface getModulesConfigManager() { + return modulesConfigManager; + } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java index f27eb037..2328565c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java @@ -3,6 +3,7 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.modules.ModuleContext; +import ru.gravit.launcher.modules.ModulesConfigManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface; public class ClientModuleContext implements ModuleContext { @@ -21,4 +22,9 @@ public Type getType() { public ModulesManagerInterface getModulesManager() { return Launcher.modulesManager; } + + @Override + public ModulesConfigManagerInterface getModulesConfigManager() { + return null; // ClientModuleContext не поддерживает modulesConfigManager + } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java index 80d7450b..f41cda42 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java @@ -1,7 +1,7 @@ package ru.gravit.launcher.client; import ru.gravit.launcher.LauncherEngine; -import ru.gravit.launcher.modules.SimpleModuleManager; +import ru.gravit.launcher.managers.SimpleModuleManager; import java.net.URL; import java.util.ArrayList; diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java index 30f90c70..f8702148 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java @@ -1,15 +1,19 @@ package ru.gravit.launcher.server; -import ru.gravit.launcher.modules.SimpleModuleManager; +import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.utils.PublicURLClassLoader; import java.net.URL; +import java.nio.file.Paths; import java.util.ArrayList; public class ModulesManager extends SimpleModuleManager { + public ModulesConfigManager modulesConfigManager; public ModulesManager(ServerWrapper wrapper) { modules = new ArrayList<>(); + modulesConfigManager = new ModulesConfigManager(Paths.get("modules-config")); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); - context = new ServerModuleContext(wrapper, classloader); + context = new ServerModuleContext(wrapper, classloader, modulesConfigManager); } } diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java index a02d8856..93802a0d 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java @@ -1,17 +1,21 @@ package ru.gravit.launcher.server; import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.managers.ModulesConfigManager; import ru.gravit.launcher.modules.ModuleContext; +import ru.gravit.launcher.modules.ModulesConfigManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.utils.PublicURLClassLoader; public class ServerModuleContext implements ModuleContext { public final PublicURLClassLoader classLoader; public final ServerWrapper wrapper; + public final ModulesConfigManager modulesConfigManager; - public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader) { + public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, ModulesConfigManager modulesConfigManager) { this.classLoader = classLoader; this.wrapper = wrapper; + this.modulesConfigManager = modulesConfigManager; } @Override @@ -23,4 +27,9 @@ public Type getType() { public ModulesManagerInterface getModulesManager() { return Launcher.modulesManager; } + + @Override + public ModulesConfigManagerInterface getModulesConfigManager() { + return modulesConfigManager; + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java new file mode 100644 index 00000000..80d55ab0 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java @@ -0,0 +1,40 @@ +package ru.gravit.launcher.managers; + +import ru.gravit.launcher.modules.ModulesConfigManagerInterface; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class ModulesConfigManager implements ModulesConfigManagerInterface { + public Path configDir; + + public ModulesConfigManager(Path configDir) { + this.configDir = configDir; + } + + public Path getModuleConfig(String moduleName) + { + if(!IOHelper.isDir(configDir)) { + try { + Files.createDirectories(configDir); + } catch (IOException e) { + LogHelper.error(e); + } + } + return configDir.resolve(moduleName.concat("Config.json")); + } + public Path getModuleConfigDir(String moduleName) + { + if(!IOHelper.isDir(configDir)) { + try { + Files.createDirectories(configDir); + } catch (IOException e) { + LogHelper.error(e); + } + } + return configDir.resolve(moduleName); + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java similarity index 96% rename from libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java rename to libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java index 91771546..40898330 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java @@ -1,5 +1,8 @@ -package ru.gravit.launcher.modules; +package ru.gravit.launcher.managers; +import ru.gravit.launcher.modules.Module; +import ru.gravit.launcher.modules.ModuleContext; +import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java index e35762f0..a79601bb 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java @@ -8,4 +8,5 @@ enum Type { Type getType(); ModulesManagerInterface getModulesManager(); + ModulesConfigManagerInterface getModulesConfigManager(); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java new file mode 100644 index 00000000..052857ac --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java @@ -0,0 +1,8 @@ +package ru.gravit.launcher.modules; + +import java.nio.file.Path; + +public interface ModulesConfigManagerInterface { + Path getModuleConfig(String moduleName); + Path getModuleConfigDir(String moduleName); +}