Merge pull request '#1-settings_properties' (#7) from #1-settings_properties into master

Reviewed-on: #7
This commit is contained in:
Hiajen Hiajen 2021-06-25 23:09:05 +02:00
commit df3f64bcf3
5 changed files with 62 additions and 6 deletions

View file

@ -1,4 +1,12 @@
EAA_MOD
===============
EAA
## Settings
Mod needs a file in modfolder called settings.properties containing following values:
```
url=mysql://<DATABASE_URL>/
user=<DATABASE USER>
password=<DATABASE USER PASSWORD>
db_name=<DATABASE NAME>
```

View file

@ -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

View file

@ -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() {

View file

@ -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");

View file

@ -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;
}
}