From 034e5c154eea45004b36c355e27e7d0e028c9390 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Sep 2019 05:20:55 +0700 Subject: [PATCH] [FEATURE] SimpleConfig --- .../gravit/launcher/config/SimpleConfig.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java new file mode 100644 index 00000000..764cab2b --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java @@ -0,0 +1,39 @@ +package pro.gravit.launcher.config; + +import java.lang.reflect.Type; +import java.nio.file.Path; + +public abstract class SimpleConfig implements JsonConfigurableInterface { + private transient final Class type; + protected transient final Path configPath; + + protected SimpleConfig(Class type, Path configPath) { + this.type = type; + this.configPath = configPath; + } + @SuppressWarnings("unchecked") + @Override + public T getConfig() { + return (T) this; + } + + @Override + public T getDefaultConfig() { + try { + return type.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + return null; + } + } + + @Override + public Path getPath() { + return configPath; + } + + @Override + public Type getType() { + return type; + } + +}