File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
src/main/java/dev/loat/config Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -35,21 +35,26 @@ public Config(
3535 configFileClass
3636 );
3737
38+ this .createIfNotExist ();
39+ this .load ();
40+ }
41+
42+ /**
43+ * Creates the config file if it does not exist and loads the config.
44+ * If an error occurs while serializing the config file, it will be logged.
45+ */
46+ private void createIfNotExist () {
3847 try {
3948 File file = path .toFile ();
4049
41- // Check if the config file exists, if not create it
4250 if (!file .exists ()) {
4351 this .serializer .serialize (configFileClass .getDeclaredConstructor ().newInstance ());
4452 }
45-
46- this .load ();
4753 } catch (Exception serializeException ) {
4854 Logger .error ("Error while serializing the config file (%s):\n %s" .formatted (this .path .toString (), serializeException ));
4955 }
5056 }
5157
52-
5358 /**
5459 * Returns the config file class associated with this config.
5560 *
@@ -59,7 +64,6 @@ Class<ConfigFile> getConfigFileClass() {
5964 return this .configFileClass ;
6065 }
6166
62-
6367 /**
6468 * Loads the configuration from the file.
6569 *
@@ -72,6 +76,8 @@ Class<ConfigFile> getConfigFileClass() {
7276 */
7377 @ SuppressWarnings ("null" )
7478 public void load () {
79+ this .createIfNotExist ();
80+
7581 try {
7682 this .config = this .serializer .parse ();
7783 } catch (Exception parseException ) {
You can’t perform that action at this time.
0 commit comments