2019-09-20 00:55:57 +03:00
|
|
|
package pro.gravit.launcher.config;
|
|
|
|
|
2019-12-17 08:56:37 +03:00
|
|
|
import java.lang.invoke.MethodHandles;
|
|
|
|
import java.lang.invoke.MethodType;
|
2019-09-20 00:55:57 +03:00
|
|
|
import java.nio.file.Path;
|
|
|
|
|
|
|
|
public class SimpleConfigurable<T> extends JsonConfigurable<T> {
|
|
|
|
public T config;
|
|
|
|
private final Class<T> tClass;
|
|
|
|
|
|
|
|
public SimpleConfigurable(Class<T> type, Path configPath) {
|
|
|
|
super(type, configPath);
|
|
|
|
tClass = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public T getConfig() {
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2019-12-17 08:56:37 +03:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
2019-09-20 00:55:57 +03:00
|
|
|
public T getDefaultConfig() {
|
|
|
|
try {
|
2019-12-17 08:56:37 +03:00
|
|
|
return (T) MethodHandles.publicLookup().findConstructor(tClass, MethodType.methodType(void.class)).invokeWithArguments();
|
|
|
|
} catch (Throwable e) {
|
2019-09-20 00:55:57 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setConfig(T config) {
|
|
|
|
this.config = config;
|
|
|
|
}
|
|
|
|
}
|