From 30cdf6b1e0c0d4751464581fa3339581ca60956f Mon Sep 17 00:00:00 2001 From: DNx5 Date: Fri, 27 Nov 2015 00:26:24 +0700 Subject: [PATCH] Run database check async * reduce lag if unlogged in player spamming the chat while cache is disabled --- .../authme/listener/AuthMePlayerListener.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 01222ae6d..c3e35e587 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -61,7 +61,7 @@ public class AuthMePlayerListener implements Listener { return; } - Player player = event.getPlayer(); + final Player player = event.getPlayer(); for (Player p : Utils.getOnlinePlayers()) { if (!PlayerCache.getInstance().isAuthenticated(p.getName())) { event.getRecipients().remove(p); // TODO: it should be configurable @@ -69,16 +69,20 @@ public class AuthMePlayerListener implements Listener { } event.setCancelled(true); - if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) { - m.send(player, MessageKey.LOGIN_MESSAGE); - } else { - if (Settings.emailRegistration) { - m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); - } else { - m.send(player, MessageKey.REGISTER_MESSAGE); + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() { + if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) { + m.send(player, MessageKey.LOGIN_MESSAGE); + } else { + if (Settings.emailRegistration) { + m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); + } else { + m.send(player, MessageKey.REGISTER_MESSAGE); + } + } } - } - + }); } /**