Skip to content

Commit

Permalink
[FIX] Now properly handles invalid/missing config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuvlyy committed Feb 11, 2024
1 parent 2e5b800 commit 2357fb8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/fr/hashtek/tekore/bukkit/Tekore.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,26 @@ private void setupConfig()
/**
* Creates an instance of HashLogger.
* This HashLogger instance will be used server-wide, in every plugin that uses Tekore.
* This function doesn't use HashLogger because it is called before the
* initialization of HashLogger. System.err.println is used instead.
*/
private void setupHashLogger()
{
YamlFile config = this.hashConfig.getYaml();
LogLevel logLevel = LogLevel.valueOf(config.getString("logger-level"));
String loggerLevel = config.getString("logger-level");
LogLevel logLevel;

try {
logLevel = LogLevel.valueOf(loggerLevel);
} catch (IllegalArgumentException | NullPointerException exception) {
System.err.println(exception instanceof NullPointerException ?
"Field \"logger-level\" not found." :
"\"" + loggerLevel + "\" is not a valid log level."
);
System.err.println("Can't initialize HashLogger. Stopping.");
this.getServer().shutdown();
return;
}

this.logger = new HashLogger(this, logLevel);
}
Expand Down
19 changes: 17 additions & 2 deletions src/fr/hashtek/tekore/bungee/Tekord.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,27 @@ private void setupConfig()
/**
* Creates an instance of HashLogger.
* This HashLogger instance will be used server-wide, in every plugin that uses Tekord.
* This function doesn't use HashLogger because it is called before the
* initialization of HashLogger. System.err.println is used instead.
*/
private void setupHashLogger()
{
YamlFile config = this.hashConfig.getYaml();
LogLevel logLevel = LogLevel.valueOf(config.getString("logger-level"));

String loggerLevel = config.getString("logger-level");
LogLevel logLevel;

try {
logLevel = LogLevel.valueOf(loggerLevel);
} catch (IllegalArgumentException | NullPointerException exception) {
System.err.println(exception instanceof NullPointerException ?
"Field \"logger-level\" not found." :
"\"" + loggerLevel + "\" is not a valid log level."
);
System.err.println("Can't initialize HashLogger. Stopping.");
this.getProxy().stop();
return;
}

this.logger = new HashLogger(this, logLevel);
}

Expand Down

0 comments on commit 2357fb8

Please sign in to comment.