6 Commits

Author SHA1 Message Date
d8cf0acf41 Fixed a typo in ConfigContainer
varient -> variant
2023-12-16 01:50:32 +01:00
25d858890a added structure samples to the ConfigContainer helper methods 2023-12-16 01:33:23 +01:00
c9b1c55982 added more documentation for the ConfigContainer helper methods 2023-12-16 01:30:21 +01:00
3a49892fa3 Fixed typo in ConfigContainer for an environment variable 2023-12-16 00:37:27 +01:00
5c385476cb Use Java 17 for running GC in Docker 2023-12-16 00:36:23 +01:00
7d79fed076 Fixed ConfigContainer database connection
Before the parameters for connecting to the MongoDB weren't read
from the environment variables.
2023-12-16 00:35:08 +01:00
2 changed files with 118 additions and 7 deletions

View File

@ -15,7 +15,7 @@ WORKDIR /app
RUN git clone --branch ${DATA_BRANCH} --depth 1 ${DATA_REPOSITORY}
FROM bitnami/java:21.0.1-12
FROM bitnami/java:17.0.9-11
RUN apt-get update && apt-get install unzip

View File

@ -111,6 +111,14 @@ public class ConfigContainer {
* Retrieves the given from the environment variables and tries to parse it as a Set<String>.
* <p>
* If the environment variable is not present or the parsing fails then the default value will be returned.
* <p>
* It expects the following structure:
* <p>
* hello,world
* <p>
* | |- second entry
* <p>
* |- first entry
*
* @param key The name of the environment variable to parse
* @param defaultValue The default value when the environment variable does not exist or is not a valid set
@ -130,9 +138,17 @@ public class ConfigContainer {
}
/**
* Retrieves the given key from the environment variables and tries to parse it as a string array.
* Retrieves the given key from the environment variables and tries to parse it as a Set<int>.
* <p>
* If the environment variable is not present or the parsing fails then the default value will be returned.
* <p>
* It expects the following structure:
* <p>
* 42,1337
* <p>
* | |- second entry
* <p>
* |- first entry
*
* @param key The name of the environment variable
* @param defaultValue The default value when the environment variable does not exist
@ -175,6 +191,14 @@ public class ConfigContainer {
* Retrieves the given key from the environment variables and tries to parse it as string array.
* <p>
* If the environment variable is not present or the parsing fails then the default value will be returned.
* <p>
* It expects the following structure:
* <p>
* hello,world
* <p>
* | |- second entry
* <p>
* |- first entry
*
* @param key The name of the environment variable to parse
* @param defaultValue The default value when the environment variable does not exist
@ -191,6 +215,24 @@ public class ConfigContainer {
return currentValue.split(separator);
}
/**
* Retrieves the given key from the environment variables and tries to parse it as an int array.
* <p>
* If the environment variable is not present or the parsing fails then the default value will be returned.
* <p>
* It expects the following structure:
* <p>
* 1,2
* <p>
* | |- second entry
* <p>
* |- first entry
*
* @param key The name of the environment variable to parse
* @param defaultValue The default value when the environment variable does not exist
* @param separator The separator which will be used for splitting up the string
* @return The parsed int array or the default value
*/
static int[] getIntArrayFromEnv(String key, int[] defaultValue, String separator) {
var currentValue = System.getenv(key);
@ -201,6 +243,27 @@ public class ConfigContainer {
return Arrays.stream(currentValue.split(separator)).mapToInt(Integer::parseInt).toArray();
}
/**
* Retrieves the given key from the environment variables and tries to parse it as a MailItem array.
* <p>
* If the environment variable is not present or the parsing fails then the default value will be returned.
* <p>
* It expects the following structure:
* <p>
* 1,1,1|2,1,1
* <p>
* | | |- Item level
* <p>
* | |- Item count
* <p>
* |- Item ID
*
* @param key The name of the environment variable to parse
* @param defaultValue The default value when the environment variable does not exist
* @param partsSeparator The separator which will be used for splitting up the string into parts
* @param valuesSeparator The separator which will be used for splitting up the parts into values
* @return The parsed MailItem array or the default value
*/
static emu.grasscutter.game.mail.Mail.MailItem[] getMailItemsFromEnv(String key, emu.grasscutter.game.mail.Mail.MailItem[] defaultValue, String partsSeparator, String valuesSeparator) {
var currentValue = System.getenv(key);
@ -219,6 +282,26 @@ public class ConfigContainer {
}).toArray();
}
/**
* Retrieves the given key from the environment variables and tries to parse it as a MailItem array.
* <p>
* If the environment variable is not present or the parsing fails then the default value will be returned.
* <p>
* It expects the following structure:
* VISION_LEVEL_NORMAL,80,20|VISION_LEVEL_LITTLE_REMOTE,16,40
* <p>
* | | |- Grid width
* <p>
* | |- Vision range
* <p>
* |- Name
*
* @param key The name of the environment variable to parse
* @param defaultValue The default value when the environment variable does not exist
* @param partsSeparator The separator which will be used for splitting up the string into parts
* @param valuesSeparator The separator which will be used for splitting up the parts into values
* @return The parsed VisionOptions or the default value
*/
static VisionOptions[] getVisionOptionsFromEnv(String key, VisionOptions[] defaultValue, String partsSeparator, String valuesSeparator) {
var currentValue = System.getenv(key);
@ -236,6 +319,29 @@ public class ConfigContainer {
}).toArray();
}
/**
* Retrieves the given key from the environment variables and tries to parse it as a Region array.
* <p>
* If the environment variable is not present or the parsing fails then the default value will be returned.
* <p>
* It expects the following structure:
* <p>
* my region,my title,127.0.0.1,1337|my second region, my second title,127.0.0.1,42
* <p>
* | | | |- port
* <p>
* | | |- address
* <p>
* | |- title
* <p>
* |- name
*
* @param key The name of the environment variable to parse
* @param defaultValue The default value when the environment variable does not exist
* @param partsSeparator The separator which will be used for splitting up the string into parts
* @param valuesSeparator The separator which will be used for splitting up the parts into values
* @return The parsed Region list or the default value
*/
static List<Region> getRegionsFromEnv(String key, List<Region> defaultValue, String partsSeparator, String valuesSeparator) {
var currentValue = System.getenv(key);
@ -263,12 +369,17 @@ public class ConfigContainer {
/* Option containers. */
public static class Database {
public DataStore server = new DataStore();
public DataStore game = new DataStore();
public DataStore server = new DataStore("SERVER");
public DataStore game = new DataStore("GAME");
public static class DataStore {
public String connectionUri = "mongodb://localhost:27017";
public String collection = "grasscutter";
public String connectionUri;
public String collection;
public DataStore(String key) {
this.connectionUri = getStringFromEnv("DATABASE_INFO_" + key + "_CONNECTION_URI", "mongodb://localhost:27017");
this.collection = getStringFromEnv("DATABASE_INFO_" + key + "_COLLECTION", "grasscutter");
}
}
}
@ -292,7 +403,7 @@ public class ConfigContainer {
public boolean logCommands = getBoolFromEnv("SERVER_LOG_COMMANDS", false);
/**
* If enabled, the 'require' Lua function will load the script's compiled varient into the context. (faster; doesn't work as well)
* If enabled, the 'require' Lua function will load the script's compiled variant into the context. (faster; doesn't work as well)
* If disabled, all 'require' calls will be replaced with the referenced script's source. (slower; works better)
*/
public boolean fastRequire = getBoolFromEnv("SERVER_FAST_REQUIRE", true);