#762 - Move all sessions stuff to new SessionManager class

This commit is contained in:
Gnat008
2016-06-27 13:50:16 -04:00
parent 0c96a3113b
commit 1326606f37
7 changed files with 209 additions and 36 deletions
@@ -2,6 +2,7 @@ package fr.xephi.authme.process.join;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.SessionManager;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
@@ -55,6 +56,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
@Inject
private LimboCache limboCache;
@Inject
private SessionManager sessionManager;
@Inject
private PluginHooks pluginHooks;
@@ -135,9 +139,8 @@ public class AsynchronousJoin implements AsynchronousProcess {
// Session logic
if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (playerCache.isAuthenticated(name) || database.isLogged(name))) {
if (plugin.getSessions().containsKey(name)) {
plugin.getSessions().get(name).cancel();
plugin.getSessions().remove(name);
if (sessionManager.hasSession(name)) {
sessionManager.cancelSession(name);
}
PlayerAuth auth = database.getAuth(name);
database.setUnlogged(name);
@@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.SessionManager;
import fr.xephi.authme.events.LogoutEvent;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.ProcessService;
@@ -36,6 +37,9 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
@Inject
private LimboPlayerTaskManager limboPlayerTaskManager;
@Inject
private SessionManager sessionManager;
ProcessSynchronousPlayerLogout() { }
@@ -58,9 +62,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
public void processSyncLogout(Player player) {
final String name = player.getName().toLowerCase();
if (plugin.getSessions().containsKey(name)) {
plugin.getSessions().get(name).cancel();
plugin.getSessions().remove(name);
if (sessionManager.hasSession(name)) {
sessionManager.cancelSession(name);
}
if (service.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN)) {
plugin.getInventoryProtector().sendBlankInventoryPacket(player);
@@ -1,6 +1,7 @@
package fr.xephi.authme.process.quit;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.SessionManager;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
@@ -42,6 +43,9 @@ public class AsynchronousQuit implements AsynchronousProcess {
@Inject
private SyncProcessManager syncProcessManager;
@Inject
private SessionManager sessionManager;
AsynchronousQuit() { }
@@ -82,23 +86,21 @@ public class AsynchronousQuit implements AsynchronousProcess {
isOp = limbo.isOperator();
limboCache.deleteLimboPlayer(name);
}
if (Settings.isSessionsEnabled && !isKick) {
if (Settings.getSessionTimeout != 0) {
if (plugin.isEnabled()) {
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
if (!isKick) {
if (plugin.isEnabled()) {
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
postLogout(name);
}
@Override
public void run() {
postLogout(name);
}
}, Settings.getSessionTimeout * TICKS_PER_MINUTE);
}, Settings.getSessionTimeout * TICKS_PER_MINUTE);
plugin.getSessions().put(name, task);
} else {
//plugin is disabled; we cannot schedule more tasks so run it directly here
postLogout(name);
}
sessionManager.addSession(name, task);
} else {
//plugin is disabled; we cannot schedule more tasks so run it directly here
postLogout(name);
}
} else {
playerCache.removePlayer(name);
@@ -117,6 +119,6 @@ public class AsynchronousQuit implements AsynchronousProcess {
private void postLogout(String name) {
PlayerCache.getInstance().removePlayer(name);
database.setUnlogged(name);
plugin.getSessions().remove(name);
sessionManager.removeSession(name);
}
}