Move similar config checks to a common function

'autoRegisterFloodgate' and 'autoLoginFloodgate' have the same possible
options, and they are checked against the player in the exact same way.
For example, if either one of them is set to isLinked, linked status is
checked in the same way, regardless of wether it's checked for login or
for registering.
This commit is contained in:
Smart123s
2022-02-25 18:12:50 +01:00
parent 817eedd4ac
commit 7e9bd1639b
3 changed files with 13 additions and 20 deletions

View File

@ -49,7 +49,7 @@ public class FloodgateAuthTask extends FloodgateManagement<Player, CommandSender
BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered, profile);
// enable auto login based on the value of 'autoLoginFloodgate' in config.yml
session.setVerified(isAutoLoginAllowed());
session.setVerified(isAutoAuthAllowed(autoLoginFloodgate));
// run login task
Runnable forceLoginTask = new ForceLoginTask(core.getPlugin().getCore(), player, session);

View File

@ -57,7 +57,7 @@ public class FloodgateAuthTask
// run login task
Runnable forceLoginTask = new ForceLoginTask(core.getPlugin().getCore(), player, server, session,
isAutoLoginAllowed());
isAutoAuthAllowed(autoLoginFloodgate));
core.getPlugin().getScheduler().runAsync(forceLoginTask);
}

View File

@ -120,7 +120,7 @@ public abstract class FloodgateManagement<P extends C, C, L extends LoginSession
}
}
if (!isRegistered && !isAutoRegisterAllowed()) {
if (!isRegistered && !isAutoAuthAllowed(autoRegisterFloodgate)) {
return;
}
@ -135,25 +135,18 @@ public abstract class FloodgateManagement<P extends C, C, L extends LoginSession
}
/**
* Decude if the player can be auto registered.
* The config option 'non-conflicting' is ignored by this function.
* Decide if the player can be automatically registered or logged in.<br>
* The config option 'non-conflicting' is ignored by this function, as name
* conflicts are checked by a different part of the code.
*
* @param configValue the value of either 'autoLoginFloodgate' or
* 'autoRegisterFloodgate' from config.yml
* @return true if the Player can be registered automatically
*/
private boolean isAutoRegisterAllowed() {
return "true".equals(autoRegisterFloodgate)
|| "no-conflict".equals(autoRegisterFloodgate) // this was checked before
|| ("linked".equals(autoRegisterFloodgate) && isLinked);
}
/**
* Decide if the player can be auto logged in.
* The config option 'non-conflicting' is ignored by this function.
* @return true if the Player can be logged in automatically
*/
protected boolean isAutoLoginAllowed() {
return "true".equals(autoLoginFloodgate)
|| "no-conflict".equals(autoRegisterFloodgate) // this was checked before
|| ("linked".equals(autoLoginFloodgate) && isLinked);
protected boolean isAutoAuthAllowed(String configValue) {
return "true".equals(configValue)
|| "no-conflict".equals(configValue) // this was checked before
|| ("linked".equals(configValue) && isLinked);
}
/**