Skip to content

Commit 4c3f3aa

Browse files
committed
Fix IllegalArgumentException with new enums
Signed-off-by: William <will27528@gmail.com>
1 parent df45b27 commit 4c3f3aa

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bukkit/src/main/java/me/william278/husktowns/config/Settings.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
public class Settings {
1616

17+
private static final HuskTowns plugin = HuskTowns.getInstance();
18+
1719
// Locale options
1820
public final String language;
1921

@@ -79,10 +81,10 @@ public class Settings {
7981
private final String serverID;
8082
private final int clusterID;
8183
private final boolean doBungee;
82-
private final MessengerType messengerType;
84+
private MessengerType messengerType;
8385

8486
// Data storage settings
85-
private final DatabaseType databaseType;
87+
private DatabaseType databaseType;
8688
private final String playerTable;
8789
private final String townsTable;
8890
private final String claimsTable;
@@ -182,13 +184,23 @@ public Settings(FileConfiguration config) {
182184
serverID = config.getString("bungee_options.server_id", "server");
183185
clusterID = config.getInt("bungee_options.cluster_id", 0);
184186
final String messengerTypeConfig = config.getString("bungee_options.messenger_type", "plugin_message");
185-
messengerType = messengerTypeConfig.equalsIgnoreCase("pluginmessage") ? MessengerType.PLUGIN_MESSAGE : MessengerType.valueOf(messengerTypeConfig.toUpperCase());
187+
try {
188+
messengerType = messengerTypeConfig.equalsIgnoreCase("pluginmessage") ? MessengerType.PLUGIN_MESSAGE : MessengerType.valueOf(messengerTypeConfig.toUpperCase());
189+
} catch (IllegalArgumentException e) {
190+
plugin.getLogger().warning("Invalid messenger type specified; defaulting to Plugin Message.");
191+
messengerType = MessengerType.PLUGIN_MESSAGE;
192+
}
186193

187194
redisHost = config.getString("bungee_options.redis_credentials.host", "localhost");
188195
redisPort = config.getInt("bungee_options.redis_credentials.port", 6379);
189196
redisPassword = config.getString("bungee_options.redis_credentials.password", "");
190197

191-
databaseType = DatabaseType.valueOf(config.getString("data_storage_options.storage_type", "SQLite"));
198+
try {
199+
databaseType = DatabaseType.valueOf(config.getString("data_storage_options.storage_type", "SQLite").toUpperCase());
200+
} catch (IllegalArgumentException e) {
201+
databaseType = DatabaseType.SQLITE;
202+
plugin.getLogger().warning("Invalid database type specified; defaulting to SQLite.");
203+
}
192204
playerTable = config.getString("data_storage_options.table_names.player_table", "husktowns_players");
193205
townsTable = config.getString("data_storage_options.table_names.towns_table", "husktowns_towns");
194206
claimsTable = config.getString("data_storage_options.table_names.claims_table", "husktowns_claims");

0 commit comments

Comments
 (0)