#1-settings_properties #7
5 changed files with 62 additions and 6 deletions
10
README.md
10
README.md
|
@ -1,4 +1,12 @@
|
||||||
EAA_MOD
|
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>
|
||||||
|
```
|
|
@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||||
loader_version=0.11.3
|
loader_version=0.11.3
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.2
|
mod_version = 1.1.0
|
||||||
maven_group = net.saltymc.eaa
|
maven_group = net.saltymc.eaa
|
||||||
archives_base_name = EAA_MOD
|
archives_base_name = EAA_MOD
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.saltymc.eaa;
|
||||||
|
|
||||||
import net.saltymc.eaa.commands.*;
|
import net.saltymc.eaa.commands.*;
|
||||||
|
|
||||||
|
import net.saltymc.eaa.util.io.PropertieLoader;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -9,15 +10,27 @@ import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public final class EaaMod implements ClientModInitializer {
|
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() {
|
public static Logger getLogger() {
|
||||||
return LOGGER;
|
return LOGGER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Properties getSettings(){
|
||||||
|
if (settings == null)
|
||||||
|
settings = PropertieLoader.loadProperties(SETTINGS_FILE_NAME);
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,24 @@ import com.mysql.cj.jdbc.Driver;
|
||||||
|
|
||||||
public class Postgre {
|
public class Postgre {
|
||||||
|
|
||||||
private final String url = "jdbc:postgresql://localhost/myDB";
|
private String url;
|
||||||
private final String user = "postgres";
|
private String user;
|
||||||
private final String password = "root";
|
private String password;
|
||||||
|
private String db_name;
|
||||||
|
|
||||||
|
private final String driverName = "com.mysql.cj.jdbc.Driver";
|
||||||
|
|
||||||
|
|
||||||
private static Postgre postgre;
|
private static Postgre postgre;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
public Postgre() {
|
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 {
|
try {
|
||||||
//load driver / config driver
|
//load driver / config driver
|
||||||
EaaMod.LOGGER.debug("Lade DB Treiber");
|
EaaMod.LOGGER.debug("Lade DB Treiber");
|
||||||
|
|
26
src/main/java/net/saltymc/eaa/util/io/PropertieLoader.java
Normal file
26
src/main/java/net/saltymc/eaa/util/io/PropertieLoader.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue