Cleanup login handling & reduce the amount of unnecessary logging output on startup

This commit is contained in:
Luck
2017-05-18 22:30:01 +01:00
Unverified
parent cc907b6530
commit 139dd5302b
8 changed files with 66 additions and 65 deletions
@@ -74,7 +74,6 @@ public class BukkitListener implements Listener {
/* the player was denied entry to the server before this priority.
log this, so we can handle appropriately later. */
if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
plugin.getLog().warn("Connection from " + e.getUniqueId() + " was already denied. No permissions data will be loaded.");
deniedAsyncLogin.add(e.getUniqueId());
return;
}
@@ -89,7 +88,7 @@ public class BukkitListener implements Listener {
deniedAsyncLogin.add(e.getUniqueId());
// actually deny the connection.
plugin.getLog().warn("Permissions storage is not loaded yet. Denying connection from: " + e.getUniqueId() + " - " + e.getName());
plugin.getLog().warn("Permissions storage is not loaded. Denying connection from: " + e.getUniqueId() + " - " + e.getName());
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(plugin.getLocaleManager()));
return;
}
@@ -121,6 +120,7 @@ public class BukkitListener implements Listener {
// Check to see if this connection was denied at LOW.
if (deniedAsyncLogin.remove(e.getUniqueId())) {
// their data was never loaded at LOW priority, now check to see if they have been magically allowed since then.
// This is a problem, as they were denied at low priority, but are now being allowed.
if (e.getLoginResult() == AsyncPlayerPreLoginEvent.Result.ALLOWED) {
@@ -131,7 +131,7 @@ public class BukkitListener implements Listener {
return;
}
// Login event was cancelled by another plugin
// Login event was cancelled by another plugin, but it wasn't cancelled when we handled it at LOW
if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
// Schedule cleanup of this user.
plugin.getUserManager().scheduleUnload(e.getUniqueId());
@@ -147,7 +147,6 @@ public class BukkitListener implements Listener {
/* the player was denied entry to the server before this priority.
log this, so we can handle appropriately later. */
if (e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
plugin.getLog().warn("Login from " + e.getPlayer().getUniqueId() + " was denied before an attachment could be injected.");
deniedLogin.add(e.getPlayer().getUniqueId());
return;
}
@@ -190,20 +189,20 @@ public class BukkitListener implements Listener {
/* Listen to see if the event was cancelled after we initially handled the login
If the connection was cancelled here, we need to do something to clean up the data that was loaded. */
// Check to see if this connection was denied at LOW.
// Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present.
boolean denied = false;
if (deniedLogin.remove(e.getPlayer().getUniqueId())) {
denied = true;
// This is a problem, as they were denied at low priority, but are now being allowed.
if (e.getResult() == PlayerLoginEvent.Result.ALLOWED) {
plugin.getLog().severe("Player connection was re-allowed for " + e.getPlayer().getUniqueId());
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "");
}
return;
}
// Login event was cancelled by another plugin
if (e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
// Login event was cancelled by another plugin since we first loaded their data
if (denied || e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
// Schedule cleanup of this user.
plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId());
return;
@@ -236,8 +235,7 @@ public class BukkitListener implements Listener {
return;
}
String s = e.getMessage().toLowerCase()
.replace("/", "")
String s = e.getMessage().substring(1).toLowerCase()
.replace("bukkit:", "")
.replace("spigot:", "")
.replace("minecraft:", "");
@@ -192,9 +192,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
}, 1L);
// register events
PluginManager pm = getServer().getPluginManager();
listener = new BukkitListener(this);
pm.registerEvents(listener, this);
getServer().getPluginManager().registerEvents(listener, this);
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
fileWatcher = new FileWatcher(this);
@@ -209,14 +208,16 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
if (messagingType.equals("none") && getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
messagingType = "redis";
}
if (!messagingType.equals("none")) {
getLog().info("Loading messaging service... [" + messagingType.toUpperCase() + "]");
}
if (messagingType.equals("redis")) {
getLog().info("Loading redis...");
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
RedisMessaging redis = new RedisMessaging(this);
try {
redis.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
getLog().info("Loaded redis successfully...");
messagingService = redis;
} catch (Exception e) {
getLog().warn("Couldn't load redis...");
@@ -226,12 +227,10 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
getLog().warn("Messaging Service was set to redis, but redis is not enabled!");
}
} else if (messagingType.equals("bungee")) {
getLog().info("Loading bungee messaging service...");
BungeeMessagingService bungeeMessaging = new BungeeMessagingService(this);
bungeeMessaging.init();
messagingService = bungeeMessaging;
} else if (messagingType.equals("lilypad")) {
getLog().info("Loading LilyPad messaging service...");
if (getServer().getPluginManager().getPlugin("LilyPad-Connect") == null) {
getLog().warn("LilyPad-Connect plugin not present.");
} else {
@@ -260,7 +259,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
localeManager = new SimpleLocaleManager();
File locale = new File(getDataFolder(), "lang.yml");
if (locale.exists()) {
getLog().info("Found locale file. Attempting to load from it.");
getLog().info("Found lang.yml - loading messages...");
try {
localeManager.loadFromFile(locale);
} catch (Exception e) {
@@ -269,7 +268,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
}
// register commands
getLog().info("Registering commands...");
commandManager = new BukkitCommand(this);
PluginCommand main = getServer().getPluginCommand("luckperms");
main.setExecutor(commandManager);
@@ -298,7 +296,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
tryVaultHook(false);
// register with the LP API
getLog().info("Registering API...");
apiProvider = new ApiProvider(this);
ApiHandler.registerProvider(apiProvider);
getServer().getServicesManager().register(LuckPermsApi.class, apiProvider, this, ServicePriority.Normal);
@@ -313,6 +310,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
scheduler.asyncLater(() -> updateTaskBuffer.request(), 40L);
// run an update instantly.
getLog().info("Performing initial data load...");
updateTaskBuffer.requestDirectly();
// register tasks
@@ -351,7 +349,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
});
}
getLog().info("Successfully loaded.");
getLog().info("Successfully enabled.");
}
@Override
@@ -378,7 +376,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
}
}
getLog().info("Closing datastore...");
getLog().info("Closing storage...");
storage.shutdown();
if (fileWatcher != null) {
@@ -390,7 +388,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
messagingService.close();
}
getLog().info("Unregistering API...");
ApiHandler.unregisterProvider();
getServer().getServicesManager().unregisterAll(this);
@@ -398,6 +395,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
vaultHook.unhook(this);
}
getLog().info("Shutting down internal scheduler...");
scheduler.shutdown();
// Bukkit will do this again when #onDisable completes, but we do it early to prevent NPEs elsewhere.
@@ -436,9 +434,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
return; // already hooked
}
if (force) {
getLog().info("Attempting to hook with Vault...");
}
try {
if (force || getServer().getPluginManager().isPluginEnabled("Vault")) {
vaultHook = new VaultHook();