mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 00:59:44 +03:00
Reconfigurable и команды config/configHelp/configList
This commit is contained in:
parent
bac2ac9d50
commit
73dfdd1494
8 changed files with 129 additions and 5 deletions
|
@ -263,6 +263,8 @@ public static void main(String... args) throws Throwable {
|
|||
|
||||
public final ReloadManager reloadManager;
|
||||
|
||||
public final ReconfigurableManager reconfigurableManager;
|
||||
|
||||
|
||||
public final BuildHookManager buildHookManager;
|
||||
|
||||
|
@ -367,6 +369,8 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException {
|
|||
sessionManager = new SessionManager();
|
||||
mirrorManager = new MirrorManager();
|
||||
reloadManager = new ReloadManager();
|
||||
reconfigurableManager = new ReconfigurableManager();
|
||||
|
||||
GarbageManager.registerNeedGC(sessionManager);
|
||||
GarbageManager.registerNeedGC(limiter);
|
||||
if(config.permissionsHandler instanceof Reloadable)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package ru.gravit.launchserver;
|
||||
|
||||
public interface Reconfigurable {
|
||||
void reconfig(String action,String[] args);
|
||||
void printConfigHelp();
|
||||
}
|
|
@ -10,9 +10,7 @@
|
|||
import ru.gravit.launchserver.command.hash.*;
|
||||
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
|
||||
import ru.gravit.launchserver.command.modules.ModulesCommand;
|
||||
import ru.gravit.launchserver.command.service.ReloadAllCommand;
|
||||
import ru.gravit.launchserver.command.service.ReloadCommand;
|
||||
import ru.gravit.launchserver.command.service.ReloadInfoCommand;
|
||||
import ru.gravit.launchserver.command.service.*;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
|
@ -116,6 +114,9 @@ protected CommandHandler(LaunchServer server) {
|
|||
registerCommand("reload",new ReloadCommand(server));
|
||||
registerCommand("reloadAll",new ReloadAllCommand(server));
|
||||
registerCommand("reloadInfo",new ReloadInfoCommand(server));
|
||||
registerCommand("config", new ConfigCommand(server));
|
||||
registerCommand("configHelp", new ConfigHelpCommand(server));
|
||||
registerCommand("configList", new ConfigListCommand(server));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package ru.gravit.launchserver.command.service;
|
||||
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.command.Command;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class ConfigCommand extends Command {
|
||||
public ConfigCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[name] [action] [more args]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "call reconfigurable action";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args,2);
|
||||
LogHelper.info("Call %s module % action",args[0],args[1]);
|
||||
String[] new_args = new String[args.length - 2];
|
||||
System.arraycopy(args, 2, new_args, 0, args.length - 2);
|
||||
server.reconfigurableManager.call(args[0],args[1],new_args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package ru.gravit.launchserver.command.service;
|
||||
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.command.Command;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class ConfigHelpCommand extends Command {
|
||||
public ConfigHelpCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[name]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "print help for config command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args,1);
|
||||
LogHelper.info("Help %s module",args[0]);
|
||||
server.reconfigurableManager.printHelp(args[0]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package ru.gravit.launchserver.command.service;
|
||||
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.command.Command;
|
||||
|
||||
public class ConfigListCommand extends Command {
|
||||
public ConfigListCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[name]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "print help for config command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
server.reconfigurableManager.printReconfigurables();
|
||||
}
|
||||
}
|
|
@ -21,8 +21,6 @@ public String getUsageDescription() {
|
|||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args,1);
|
||||
LogHelper.info("Reload %s config",args[0]);
|
||||
server.reloadManager.printReloadables();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package ru.gravit.launchserver.manangers;
|
||||
|
||||
import ru.gravit.launchserver.Reconfigurable;
|
||||
import ru.gravit.launchserver.Reloadable;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ReconfigurableManager {
|
||||
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
|
||||
public void registerReconfigurable(String name, Reconfigurable reconfigurable)
|
||||
{
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"),
|
||||
String.format("Reloadable has been already registered: '%s'", name));
|
||||
}
|
||||
public void printHelp(String name)
|
||||
{
|
||||
RECONFIGURABLE.get(name).printConfigHelp();
|
||||
}
|
||||
public void call(String name, String action, String[] args) throws Exception {
|
||||
RECONFIGURABLE.get(name).reconfig(action,args);
|
||||
}
|
||||
public void printReconfigurables()
|
||||
{
|
||||
LogHelper.info("Print reconfigurables");
|
||||
RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k));
|
||||
LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue