Skip to content

Commit

Permalink
Update 0.6.6 - Small fix for the Config file, if you let the config f…
Browse files Browse the repository at this point in the history
…ile empty it would throw null errors while trying to read the config.
  • Loading branch information
FrostedCA committed Apr 3, 2023
1 parent 0e667e9 commit 0a80936
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main/java/ca/tristan/easycommands/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void makeConfig() throws IOException {
return;
}
PrintWriter bufferedWriter = new PrintWriter(new FileWriter(this.file));
bufferedWriter.println("# IF YOU DON'T WANT TO USE MYSQL JUST LEAVE THE CONFIG LINES **EMPTY OR REMOVE** THEM AND THEY WILL GET IGNORED.");
bufferedWriter.println(ConfigSettings.TOKEN.label);
bufferedWriter.println("# Database Settings");
bufferedWriter.println(ConfigSettings.USE_MYSQL.label);
Expand All @@ -48,14 +49,14 @@ public void loadConfig() throws IOException {
String[] settings = line.split("=");
switch (settings[0]) {
case "token" -> token = settings[1];
case "use_mysql" -> mysql = Boolean.parseBoolean(settings[1]);
case "db_host" -> dbHost = settings[1];
case "db_port" -> dbPort = Integer.parseInt(settings[1]);
case "db_name" -> dbName = settings[1];
case "db_user" -> dbUser = settings[1];
case "db_password" -> dbPassword = settings[1];
case "use_music_bot" -> musicBot = Boolean.parseBoolean(settings[1]);
case "use_prefixcommands" -> prefixCommands = Boolean.parseBoolean(settings[1]);
case "use_mysql" -> mysql = settings.length == 2 && Boolean.parseBoolean(settings[1]);
case "db_host" -> dbHost = settings.length == 2 ? settings[1] : "";
case "db_port" -> dbPort = settings.length == 2 ? Integer.parseInt(settings[1]) : 0;
case "db_name" -> dbName = settings.length == 2 ? settings[1] : "";
case "db_user" -> dbUser = settings.length == 2 ? settings[1] : "";
case "db_password" -> dbPassword = settings.length == 2 ? settings[1] : "";
case "use_music_bot" -> musicBot = settings.length == 2 && Boolean.parseBoolean(settings[1]);
case "use_prefixcommands" -> prefixCommands = settings.length == 2 && Boolean.parseBoolean(settings[1]);
}
}
Logger.log(LogType.OK, "Config loaded.");
Expand Down

0 comments on commit 0a80936

Please sign in to comment.