Run database check async

* reduce lag if unlogged in player spamming the chat while cache is disabled
This commit is contained in:
DNx5 2015-11-27 00:26:24 +07:00
parent e80c098e3d
commit 30cdf6b1e0

View File

@ -61,7 +61,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
Player player = event.getPlayer(); final Player player = event.getPlayer();
for (Player p : Utils.getOnlinePlayers()) { for (Player p : Utils.getOnlinePlayers()) {
if (!PlayerCache.getInstance().isAuthenticated(p.getName())) { if (!PlayerCache.getInstance().isAuthenticated(p.getName())) {
event.getRecipients().remove(p); // TODO: it should be configurable event.getRecipients().remove(p); // TODO: it should be configurable
@ -69,16 +69,20 @@ public class AuthMePlayerListener implements Listener {
} }
event.setCancelled(true); event.setCancelled(true);
if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
m.send(player, MessageKey.LOGIN_MESSAGE); @Override
} else { public void run() {
if (Settings.emailRegistration) { if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) {
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); m.send(player, MessageKey.LOGIN_MESSAGE);
} else { } else {
m.send(player, MessageKey.REGISTER_MESSAGE); if (Settings.emailRegistration) {
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
} else {
m.send(player, MessageKey.REGISTER_MESSAGE);
}
}
} }
} });
} }
/** /**