#707 Convert sync processes into services

This commit is contained in:
ljacqu
2016-05-20 19:42:30 +02:00
parent f5c89e897f
commit 3f039d641a
20 changed files with 303 additions and 278 deletions
@@ -6,15 +6,16 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.NewProcess;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.bukkit.entity.Player;
import javax.inject.Inject;
public class AsynchronousLogout implements NewProcess {
public class AsynchronousLogout implements AsynchronousProcess {
@Inject
private AuthMe plugin;
@@ -31,21 +32,23 @@ public class AsynchronousLogout implements NewProcess {
@Inject
private LimboCache limboCache;
@Inject
private SyncProcessManager syncProcessManager;
AsynchronousLogout() { }
public void logout(Player player) {
public void logout(final Player player) {
final String name = player.getName().toLowerCase();
if (!playerCache.isAuthenticated(name)) {
service.send(player, MessageKey.NOT_LOGGED_IN);
return;
}
final Player p = player;
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
PlayerAuth auth = playerCache.getAuth(name);
database.updateSession(auth);
auth.setQuitLocX(p.getLocation().getX());
auth.setQuitLocY(p.getLocation().getY());
auth.setQuitLocZ(p.getLocation().getZ());
auth.setWorld(p.getWorld().getName());
auth.setQuitLocX(player.getLocation().getX());
auth.setQuitLocY(player.getLocation().getY());
auth.setQuitLocZ(player.getLocation().getZ());
auth.setWorld(player.getWorld().getName());
database.updateQuitLoc(auth);
playerCache.removePlayer(name);
@@ -53,7 +56,7 @@ public class AsynchronousLogout implements NewProcess {
service.scheduleSyncDelayedTask(new Runnable() {
@Override
public void run() {
Utils.teleportToSpawn(p);
Utils.teleportToSpawn(player);
}
});
if (limboCache.hasLimboPlayer(name)) {
@@ -61,6 +64,6 @@ public class AsynchronousLogout implements NewProcess {
}
limboCache.addLimboPlayer(player);
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
service.scheduleSyncDelayedTask(new ProcessSynchronousPlayerLogout(p, plugin, service));
syncProcessManager.processSyncPlayerLogout(player);
}
}