Moved config value checking

Previously the value for "autoLoginFloodgate" and "autoRegisterFloodgate" was checked every time a player joined.
Now they are checked at startup.
This commit is contained in:
Smart123s
2021-04-11 11:47:56 +02:00
parent a078bb8214
commit 0d598ad390
2 changed files with 31 additions and 18 deletions

View File

@ -59,6 +59,13 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
setEnabled(false);
return;
}
// Check Floodgate config values
if (!isValidFloodgateConfigString("autoLoginFloodgate")
|| !isValidFloodgateConfigString("allowFloodgateNameConflict")) {
setEnabled(false);
return;
}
bungeeManager = new BungeeManager(this);
bungeeManager.initialize();
@ -206,4 +213,28 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
public void sendMessage(CommandSender receiver, String message) {
receiver.sendMessage(message);
}
/**
* Checks if a config entry (related to Floodgate) is valid. <br>
* Writes to Log if the value is invalid.
* <p>
* This should be used for:
* <ul>
* <li>allowFloodgateNameConflict
* <li>autoLoginFloodgate
* </ul>
* </p>
*
* @param key the key of the entry in config.yml
* @return <b>true</b> if the entry's value is "true", "false", or "linked"
*/
private boolean isValidFloodgateConfigString(String key) {
String value = core.getConfig().getString(key);
if (!value.equalsIgnoreCase("true") && !value.equalsIgnoreCase("linked") && !value.equalsIgnoreCase("false")) {
logger.error("Invalid value detected for {} in FastLogin/config.yml.", key);
return false;
}
return true;
}
}

View File

@ -44,12 +44,6 @@ public class FloodgateAuthTask implements Runnable {
return;
}
if (!isValidConfigValue(allowNameConflict)) {
plugin.getLog().error(
"Invalid value detected for 'allowFloodgateNameConflict' in FasttLogin/config.yml. Aborting login of Player {}",
player.getName());
return;
}
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
@ -88,17 +82,5 @@ public class FloodgateAuthTask implements Runnable {
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);
}
/**
* Check if a string is a valid configuration option for
* 'allowFloodgateNameConflict' or 'autoLoginFloodgate'
*
* @param value The value of 'allowFloodgateNameConflict' or
* 'autoLoginFloodgate' from config.yml
* @return true if value is "true", "false", or "linked"
*/
boolean isValidConfigValue(String value) {
return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("linked") || value.equalsIgnoreCase("false");
}
}