diff --git a/Server/src/main/java/net/simon987/server/ServerConfiguration.java b/Server/src/main/java/net/simon987/server/ServerConfiguration.java index 8cff8b6..bb8966d 100644 --- a/Server/src/main/java/net/simon987/server/ServerConfiguration.java +++ b/Server/src/main/java/net/simon987/server/ServerConfiguration.java @@ -3,25 +3,24 @@ package net.simon987.server; import net.simon987.server.logging.LogManager; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Properties; /** - * Wrapper for Java Property + * Wrapper for Java Properties class */ public class ServerConfiguration { - /** - * Properties - */ private Properties properties; + private String fileName; + + public ServerConfiguration(String fileName) { + + this.fileName = fileName; - public ServerConfiguration(String file) { try { properties = new Properties(); - InputStream is = new FileInputStream("config.properties"); + InputStream is = new FileInputStream(this.fileName); properties.load(is); } catch (IOException e) { @@ -29,6 +28,17 @@ public class ServerConfiguration { } } + private void saveConfig() { + + try { + OutputStream os = new FileOutputStream(this.fileName); + properties.store(os, ""); + + } catch (IOException e) { + LogManager.LOGGER.severe("Problem saving server configuration: " + e.getMessage()); + } + } + public int getInt(String key) { return Integer.valueOf((String) properties.get(key)); @@ -39,4 +49,14 @@ public class ServerConfiguration { return (String) properties.get(key); } + public void setInt(String key, int value) { + properties.setProperty(key, String.valueOf(value)); + saveConfig(); + } + + public void setString(String key, String value) { + properties.setProperty(key, value); + saveConfig(); + } + }