diff options
author | kekzdealer <kekzdealer@gmail.com> | 2019-10-12 00:51:41 +0200 |
---|---|---|
committer | kekzdealer <kekzdealer@gmail.com> | 2019-10-12 00:51:41 +0200 |
commit | 8dab80ff200998cdee40144c9855443cd17f366d (patch) | |
tree | df4194255c4c3fc4b757b9a4f0265d26253b7873 /src/main/java/config | |
parent | 95ae4bcb0146fbccb6eaf0f0b3477050b8dde533 (diff) | |
download | GT5-Unofficial-8dab80ff200998cdee40144c9855443cd17f366d.tar.gz GT5-Unofficial-8dab80ff200998cdee40144c9855443cd17f366d.tar.bz2 GT5-Unofficial-8dab80ff200998cdee40144c9855443cd17f366d.zip |
Made working UI base for nuclear reactor
Diffstat (limited to 'src/main/java/config')
-rw-r--r-- | src/main/java/config/ConfigIO.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/config/ConfigIO.java b/src/main/java/config/ConfigIO.java new file mode 100644 index 0000000000..4898c9b58d --- /dev/null +++ b/src/main/java/config/ConfigIO.java @@ -0,0 +1,49 @@ +package config; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +public class ConfigIO { + + private static final String CONFIG_PATH = "main/java/config/config.properties"; + private static final int CONFIG_SIZE = 0; + + private static Properties config; + + private ConfigIO() { + + } + + public static void load() { + config = new Properties(); + try { + config.load(new FileInputStream(CONFIG_PATH)); + } catch (IOException e) { + throw new IllegalStateException("Failed to load KekzTech config!"); + } + if(config.size() != CONFIG_SIZE) { + throw new IllegalStateException("KekzTech config is not expected size!"); + } + } + + @SuppressWarnings("unchecked") + public <T> T get(String key, T valueType) { + if(config.size() != CONFIG_SIZE) { + throw new IllegalStateException("Tried to access config without loading it first"); + } + return (T) config.get((Object) key); + } + + public static void saveConfig() { + try { + config = (config == null) ? new Properties() : config; + config.setProperty("key", "value"); + config.store(new FileOutputStream(CONFIG_PATH), "Welcome to KekzTech's config file :)"); + } catch (IOException e) { + System.err.println("Failed to save changes to KekzTech config. Settings may be lost."); + } + } + +} |