Add option to cancel failed logins on BungeeCord variant

This commit is contained in:
Luck 2017-10-23 16:59:07 +01:00
parent b299301b69
commit c573c755d2
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 46 additions and 9 deletions

View File

@ -77,8 +77,14 @@ public class BungeeListener implements Listener {
the proxy will just fallback to using the config file perms. */
if (!plugin.getStorage().isAcceptingLogins()) {
// log that the user tried to login, but was denied at this stage.
plugin.getLog().warn("Permissions storage is not loaded. No permissions data will be loaded for: " + c.getUniqueId() + " - " + c.getName());
if (plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// cancel the login attempt
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
e.setCancelled(true);
} else {
// log that the user tried to login, but was denied at this stage.
plugin.getLog().warn("Permissions storage is not loaded. No permissions data will be loaded for: " + c.getUniqueId() + " - " + c.getName());
}
e.completeIntent(plugin);
return;
@ -104,7 +110,14 @@ public class BungeeListener implements Listener {
ex.printStackTrace();
// there was some error loading
plugin.getLog().warn("Error loading data. No permissions data will be loaded for: " + c.getUniqueId() + " - " + c.getName());
if (plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// cancel the login attempt
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
e.setCancelled(true);
} else {
plugin.getLog().warn("Error loading data. No permissions data will be loaded for: " + c.getUniqueId() + " - " + c.getName());
}
}
// finally, complete our intent to modify state, so the proxy can continue handling the connection.
@ -126,13 +139,20 @@ public class BungeeListener implements Listener {
}
if (user == null) {
plugin.getProxy().getScheduler().schedule(plugin, () -> {
if (!player.isConnected()) {
return;
}
if (plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// disconnect the user
plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded - cancelling login.");
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
} else {
// just send a message
plugin.getProxy().getScheduler().schedule(plugin, () -> {
if (!player.isConnected()) {
return;
}
player.sendMessage(new TextComponent(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
}, 3, TimeUnit.SECONDS);
player.sendMessage(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
}, 1, TimeUnit.SECONDS);
}
}
}

View File

@ -83,6 +83,18 @@ allow-invalid-usernames: false
# Useful if you're having issues with UUID forwarding or data not being loaded.
debug-logins: false
# If LuckPerms should ensure all players have permission data when they connect to the server.
#
# When set to true, LuckPerms will cancel login attempts if it is unable to load permissions data
# for a user, of if the storage provider is unavailable.
#
# When set to false, LuckPerms will allow a player to connect regardless of whether their
# permissions data could be loaded.
#
# This option does not exist on other platforms, and effectively defaults to true - however,
# the option is provided on BungeeCord, as it is less likely to be so dependant on permissions.
cancel-failed-logins: false
# If the plugin should send log notifications to users whenever permissions are modified.
log-notify: true

View File

@ -132,6 +132,11 @@ public class ConfigKeys {
*/
public static final ConfigKey<Boolean> DEBUG_LOGINS = BooleanKey.of("debug-logins", false);
/**
* If LP should cancel login attempts for players whose permission data could not be loaded.
*/
public static final ConfigKey<Boolean> CANCEL_FAILED_LOGINS = BooleanKey.of("cancel-failed-logins", false);
/**
* Controls how temporary add commands should behave
*/