Launcher/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java

36 lines
1.2 KiB
Java
Raw Normal View History

package ru.gravit.launchserver.manangers;
import ru.gravit.launchserver.Reconfigurable;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper;
2019-01-15 06:35:39 +03:00
import java.util.HashMap;
import java.util.Objects;
public class ReconfigurableManager {
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
2019-01-15 06:35:39 +03:00
public void registerReconfigurable(String name, Reconfigurable reconfigurable) {
VerifyHelper.putIfAbsent(RECONFIGURABLE, name.toLowerCase(), Objects.requireNonNull(reconfigurable, "adapter"),
String.format("Reloadable has been already registered: '%s'", name));
}
public Reconfigurable unregisterReconfigurable(String name)
{
return RECONFIGURABLE.remove(name);
}
2019-01-15 06:35:39 +03:00
public void printHelp(String name) {
RECONFIGURABLE.get(name.toLowerCase()).printConfigHelp();
}
2019-01-15 06:35:39 +03:00
2019-01-15 06:32:46 +03:00
public void call(String name, String action, String[] args) {
RECONFIGURABLE.get(name.toLowerCase()).reconfig(action.toLowerCase(), args);
}
2019-01-15 06:35:39 +03:00
public void printReconfigurables() {
LogHelper.info("Print reconfigurables");
RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k));
LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size());
}
}