From 1d69f7d2a4f0981934afd38513cc19dd481e64d1 Mon Sep 17 00:00:00 2001 From: "Ansgar [Hiajen]" Date: Fri, 25 Jun 2021 23:03:00 +0200 Subject: [PATCH 1/2] implement settings as Properties --- src/main/java/net/saltymc/eaa/EaaMod.java | 15 ++++++++++- .../saltymc/eaa/util/database/Postgre.java | 15 ++++++++--- .../saltymc/eaa/util/io/PropertieLoader.java | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/saltymc/eaa/util/io/PropertieLoader.java diff --git a/src/main/java/net/saltymc/eaa/EaaMod.java b/src/main/java/net/saltymc/eaa/EaaMod.java index 2c50258..d90d58b 100644 --- a/src/main/java/net/saltymc/eaa/EaaMod.java +++ b/src/main/java/net/saltymc/eaa/EaaMod.java @@ -2,6 +2,7 @@ package net.saltymc.eaa; import net.saltymc.eaa.commands.*; +import net.saltymc.eaa.util.io.PropertieLoader; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -9,15 +10,27 @@ import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import java.util.Properties; + @Environment(EnvType.CLIENT) public final class EaaMod implements ClientModInitializer { - public static final Logger LOGGER = LogManager.getLogger("EAA-MOD"); + private static final String SETTINGS_FILE_NAME = "settings.properties"; + + public static final Logger LOGGER = LogManager.getLogger("EAA-MOD"); + private static Properties settings; public static Logger getLogger() { return LOGGER; } + public static Properties getSettings(){ + if (settings == null) + settings = PropertieLoader.loadProperties(SETTINGS_FILE_NAME); + + return settings; + } + @Override public void onInitializeClient() { diff --git a/src/main/java/net/saltymc/eaa/util/database/Postgre.java b/src/main/java/net/saltymc/eaa/util/database/Postgre.java index cdea712..107c25c 100644 --- a/src/main/java/net/saltymc/eaa/util/database/Postgre.java +++ b/src/main/java/net/saltymc/eaa/util/database/Postgre.java @@ -7,15 +7,24 @@ import com.mysql.cj.jdbc.Driver; public class Postgre { - private final String url = "jdbc:postgresql://localhost/myDB"; - private final String user = "postgres"; - private final String password = "root"; + private String url; + private String user; + private String password; + private String db_name; + + private final String driverName = "com.mysql.cj.jdbc.Driver"; + private static Postgre postgre; private Connection connection; public Postgre() { + this.url = EaaMod.getSettings().getProperty("url"); + this.user = EaaMod.getSettings().getProperty("user"); + this.password = EaaMod.getSettings().getProperty("password"); + this.db_name = EaaMod.getSettings().getProperty("db_name"); + try { //load driver / config driver EaaMod.LOGGER.debug("Lade DB Treiber"); diff --git a/src/main/java/net/saltymc/eaa/util/io/PropertieLoader.java b/src/main/java/net/saltymc/eaa/util/io/PropertieLoader.java new file mode 100644 index 0000000..0ac7266 --- /dev/null +++ b/src/main/java/net/saltymc/eaa/util/io/PropertieLoader.java @@ -0,0 +1,26 @@ +package net.saltymc.eaa.util.io; + +import net.saltymc.eaa.EaaMod; + +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Properties; + +public class PropertieLoader { + + public static Properties loadProperties(String fileName){ + Properties p = new Properties(); + + try (FileReader reader = new FileReader(System.getProperty("user.dir") + "/mods/" + fileName)){ + p.load(reader); + } catch (Exception e){ + try (FileWriter writer = new FileWriter(System.getProperty("user.dir") + "/mods/" + fileName)) { + p.store(writer, "init config file"); + } catch (Exception ex){ + EaaMod.getLogger().error("Cant save Properties" + fileName, e); + } + return loadProperties(fileName); + } + return p; + } +} \ No newline at end of file -- 2.30.2 From 8e829e3a01654db412b53760d01320a7c4fec3cd Mon Sep 17 00:00:00 2001 From: "Ansgar [Hiajen]" Date: Fri, 25 Jun 2021 23:07:31 +0200 Subject: [PATCH 2/2] version Up, edit readme --- README.md | 10 +++++++++- gradle.properties | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa5ab2f..3cea151 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ EAA_MOD =============== -EAA \ No newline at end of file +## Settings +Mod needs a file in modfolder called settings.properties containing following values: + +``` +url=mysql:/// +user= +password= +db_name= +``` \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 3f6f809..9654a03 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.11.3 # Mod Properties - mod_version = 1.0.2 + mod_version = 1.1.0 maven_group = net.saltymc.eaa archives_base_name = EAA_MOD -- 2.30.2