Skip to content

Commit

Permalink
Move loadEnvironmentVariables to CytosisSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
webhead1104 committed May 6, 2024
1 parent ffbbf8e commit adf5db7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ tasks {
}
mergeServiceFiles()
archiveFileName.set("cytosis.jar")
//destinationDirectory.set(file(providers.gradleProperty("server_dir").get()))
}
}
29 changes: 1 addition & 28 deletions src/main/java/net/cytonic/cytosis/Cytosis.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static void main(String[] args) {
Logger.error("An error occurred whilst initializing the file manager!", throwable);
} else {
Logger.info("File manager initialized!");
loadEnvironmentVariables();
CytosisSettings.loadEnvironmentVariables();
if (CytosisSettings.SERVER_PROXY_MODE) {
Logger.info("Enabling velocity!");
VelocityProxy.enable(CytosisSettings.SERVER_SECRET);
Expand Down Expand Up @@ -150,33 +150,6 @@ public static void mojangAuth() {
MojangAuth.init(); //VERY IMPORTANT! (This is online mode!)
}

public static void loadEnvironmentVariables() {
Logger.info("Loading environment variables!");
// logging
if (!(System.getenv("LOG_PLAYER_IPS") == null)) CytosisSettings.LOG_PLAYER_IPS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_IPS"));
if (!(System.getenv("LOG_PLAYER_JOINS") == null)) CytosisSettings.LOG_PLAYER_JOINS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_JOINS"));
if (!(System.getenv("LOG_PLAYER_QUITS") == null)) CytosisSettings.LOG_PLAYER_QUITS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_QUITS"));
if (!(System.getenv("LOG_PLAYER_COMMANDS") == null)) CytosisSettings.LOG_PLAYER_COMMANDS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_COMMANDS"));
if (!(System.getenv("LOG_PLAYER_CHAT") == null)) CytosisSettings.LOG_PLAYER_CHAT = Boolean.parseBoolean(System.getenv("LOG_PLAYER_CHAT"));
// database
if (!(System.getenv("DATABASE_USER") == null)) CytosisSettings.DATABASE_USER = System.getenv("DATABASE_USER");
if (!(System.getenv("DATABASE_PASSWORD") == null)) CytosisSettings.DATABASE_PASSWORD = System.getenv("DATABASE_PASSWORD");
if (!(System.getenv("DATABASE_HOST") == null)) CytosisSettings.DATABASE_HOST = System.getenv("DATABASE_HOST");
if (!(System.getenv("DATABASE_PORT") == null)) CytosisSettings.DATABASE_PORT = Integer.parseInt((System.getenv("DATABASE_PORT")));
if (!(System.getenv("DATABASE_NAME") == null)) CytosisSettings.DATABASE_NAME = System.getenv("DATABASE_NAME");
if (!(System.getenv("DATABASE_USE_SSL") == null)) CytosisSettings.DATABASE_USE_SSL = Boolean.parseBoolean(System.getenv("DATABASE_USE_SSL"));
//server
if (!(System.getenv("SERVER_PROXY_MODE") == null)) CytosisSettings.SERVER_PROXY_MODE = Boolean.parseBoolean(System.getenv("SERVER_PROXY_MODE"));
if (!(System.getenv("SERVER_SECRET") == null)) CytosisSettings.SERVER_SECRET = System.getenv("SERVER_SECRET");
if (!(System.getenv("SERVER_PORT") == null)) CytosisSettings.SERVER_PORT = Integer.parseInt(System.getenv("SERVER_PORT"));
// RabbitMQ
if (!(System.getenv("RABBITMQ_ENABLED") == null)) CytosisSettings.RABBITMQ_ENABLED = Boolean.parseBoolean(System.getenv("RABBITMQ_ENABLED"));
if (!(System.getenv("RABBITMQ_HOST") == null)) CytosisSettings.RABBITMQ_HOST = System.getenv("RABBITMQ_HOST");
if (!(System.getenv("RABBITMQ_PASSWORD") == null)) CytosisSettings.RABBITMQ_PASSWORD = System.getenv("RABBITMQ_PASSWORD");
if (!(System.getenv("RABBITMQ_USERNAME") == null)) CytosisSettings.RABBITMQ_USERNAME = System.getenv("RABBITMQ_USERNAME");
if (!(System.getenv("RABBITMQ_PORT") == null)) CytosisSettings.RABBITMQ_PORT = Integer.parseInt(System.getenv("RABBITMQ_PORT"));
}

public static void completeNonEssentialTasks(long start) {
// basic world generator
Logger.info("Generating basic world");
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/net/cytonic/cytosis/config/CytosisSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,31 @@ public static void inportConfig(Map<String, Object> config) {
private static int toInt(Object key) {
return Integer.parseInt(key.toString());
}

public static void loadEnvironmentVariables() {
Logger.info("Loading environment variables!");
// logging
if (!(System.getenv("LOG_PLAYER_IPS") == null)) CytosisSettings.LOG_PLAYER_IPS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_IPS"));
if (!(System.getenv("LOG_PLAYER_JOINS") == null)) CytosisSettings.LOG_PLAYER_JOINS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_JOINS"));
if (!(System.getenv("LOG_PLAYER_QUITS") == null)) CytosisSettings.LOG_PLAYER_QUITS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_QUITS"));
if (!(System.getenv("LOG_PLAYER_COMMANDS") == null)) CytosisSettings.LOG_PLAYER_COMMANDS = Boolean.parseBoolean(System.getenv("LOG_PLAYER_COMMANDS"));
if (!(System.getenv("LOG_PLAYER_CHAT") == null)) CytosisSettings.LOG_PLAYER_CHAT = Boolean.parseBoolean(System.getenv("LOG_PLAYER_CHAT"));
// database
if (!(System.getenv("DATABASE_USER") == null)) CytosisSettings.DATABASE_USER = System.getenv("DATABASE_USER");
if (!(System.getenv("DATABASE_PASSWORD") == null)) CytosisSettings.DATABASE_PASSWORD = System.getenv("DATABASE_PASSWORD");
if (!(System.getenv("DATABASE_HOST") == null)) CytosisSettings.DATABASE_HOST = System.getenv("DATABASE_HOST");
if (!(System.getenv("DATABASE_PORT") == null)) CytosisSettings.DATABASE_PORT = Integer.parseInt((System.getenv("DATABASE_PORT")));
if (!(System.getenv("DATABASE_NAME") == null)) CytosisSettings.DATABASE_NAME = System.getenv("DATABASE_NAME");
if (!(System.getenv("DATABASE_USE_SSL") == null)) CytosisSettings.DATABASE_USE_SSL = Boolean.parseBoolean(System.getenv("DATABASE_USE_SSL"));
//server
if (!(System.getenv("SERVER_PROXY_MODE") == null)) CytosisSettings.SERVER_PROXY_MODE = Boolean.parseBoolean(System.getenv("SERVER_PROXY_MODE"));
if (!(System.getenv("SERVER_SECRET") == null)) CytosisSettings.SERVER_SECRET = System.getenv("SERVER_SECRET");
if (!(System.getenv("SERVER_PORT") == null)) CytosisSettings.SERVER_PORT = Integer.parseInt(System.getenv("SERVER_PORT"));
// RabbitMQ
if (!(System.getenv("RABBITMQ_ENABLED") == null)) CytosisSettings.RABBITMQ_ENABLED = Boolean.parseBoolean(System.getenv("RABBITMQ_ENABLED"));
if (!(System.getenv("RABBITMQ_HOST") == null)) CytosisSettings.RABBITMQ_HOST = System.getenv("RABBITMQ_HOST");
if (!(System.getenv("RABBITMQ_PASSWORD") == null)) CytosisSettings.RABBITMQ_PASSWORD = System.getenv("RABBITMQ_PASSWORD");
if (!(System.getenv("RABBITMQ_USERNAME") == null)) CytosisSettings.RABBITMQ_USERNAME = System.getenv("RABBITMQ_USERNAME");
if (!(System.getenv("RABBITMQ_PORT") == null)) CytosisSettings.RABBITMQ_PORT = Integer.parseInt(System.getenv("RABBITMQ_PORT"));
}
}

0 comments on commit adf5db7

Please sign in to comment.