Launcher/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java

36 lines
855 B
Java
Raw Normal View History

package pro.gravit.launcher.config;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.nio.file.Path;
public class SimpleConfigurable<T> extends JsonConfigurable<T> {
private final Class<T> tClass;
2020-04-05 10:27:04 +03:00
public T config;
public SimpleConfigurable(Class<T> type, Path configPath) {
super(type, configPath);
tClass = type;
}
@Override
public T getConfig() {
return config;
}
2020-04-05 10:27:04 +03:00
@Override
public void setConfig(T config) {
this.config = config;
}
@SuppressWarnings("unchecked")
2020-04-05 10:27:04 +03:00
@Override
public T getDefaultConfig() {
try {
return (T) MethodHandles.publicLookup().findConstructor(tClass, MethodType.methodType(void.class)).invokeWithArguments();
} catch (Throwable e) {
return null;
}
}
}