#1113 Create LimboService (work in progress)

- Introduce new LimboService with a higher level abstraction for outside classes to trigger LimboPlayer actions
- Add methods to LimboPlayerTaskManager for muting the MessagesTask safely
This commit is contained in:
ljacqu
2017-03-05 19:25:35 +01:00
parent 6db778387d
commit 22ccf582b8
21 changed files with 171 additions and 115 deletions
@@ -4,7 +4,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.SessionManager;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.message.MessageKey;
@@ -51,7 +51,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
private PlayerCache playerCache;
@Inject
private LimboCache limboCache;
private LimboService limboService;
@Inject
private SessionManager sessionManager;
@@ -111,7 +111,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
final boolean isAuthAvailable = database.isAuthAvailable(name);
if (isAuthAvailable) {
limboCache.addPlayerData(player);
limboService.createLimboPlayer(player);
service.setGroup(player, AuthGroupType.REGISTERED_UNAUTHENTICATED);
// Protect inventory
@@ -141,9 +141,10 @@ public class AsynchronousJoin implements AsynchronousProcess {
}
}
} else {
// TODO #1113: Why delete and add LimboPlayer again?
// Not Registered. Delete old data, load default one.
limboCache.deletePlayerData(player);
limboCache.addPlayerData(player);
// limboCache.deletePlayerData(player);
// limboCache.addPlayerData(player);
// Groups logic
service.setGroup(player, AuthGroupType.UNREGISTERED);
@@ -6,8 +6,6 @@ import fr.xephi.authme.data.CaptchaManager;
import fr.xephi.authme.data.TempbanManager;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.data.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
import fr.xephi.authme.message.MessageKey;
@@ -16,16 +14,16 @@ import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.LimboPlayerTaskManager;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.util.PlayerUtils;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
@@ -52,9 +50,6 @@ public class AsynchronousLogin implements AsynchronousProcess {
@Inject
private PlayerCache playerCache;
@Inject
private LimboCache limboCache;
@Inject
private SyncProcessManager syncProcessManager;
@@ -195,7 +190,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
// If the authentication fails check if Captcha is required and send a message to the player
if (captchaManager.isCaptchaRequired(player.getName())) {
limboCache.getPlayerData(player.getName()).getMessageTask().setMuted(true);
limboPlayerTaskManager.muteMessageTask(player);
service.send(player, MessageKey.USAGE_CAPTCHA,
captchaManager.getCaptchaCodeOrGenerateNew(player.getName()));
}
@@ -246,10 +241,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
// task, we schedule it in the end
// so that we can be sure, and have not to care if it might be
// processed in other order.
LimboPlayer limboPlayer = limboCache.getPlayerData(name);
if (limboPlayer != null) {
limboPlayer.clearTasks();
}
limboPlayerTaskManager.clearTasks(player);
syncProcessManager.processSyncPlayerLogin(player);
} else {
ConsoleLogger.warning("Player '" + player.getName() + "' wasn't online during login process, aborted...");
@@ -260,7 +252,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
int threshold = service.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD_THRESHOLD);
String command = service.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD);
if(threshold < 2 || command.isEmpty()) {
if (threshold < 2 || command.isEmpty()) {
return;
}
@@ -1,8 +1,8 @@
package fr.xephi.authme.process.login;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.data.limbo.LimboPlayer;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
@@ -31,7 +31,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
private BungeeService bungeeService;
@Inject
private LimboCache limboCache;
private LimboService limboService;
@Inject
private BukkitService bukkitService;
@@ -65,14 +65,14 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
public void processPlayerLogin(Player player) {
final String name = player.getName().toLowerCase();
final LimboPlayer limbo = limboCache.getPlayerData(name);
final LimboPlayer limbo = limboService.getLimboPlayer(name);
// Limbo contains the State of the Player before /login
if (limbo != null) {
limboCache.restoreData(player);
limboCache.deletePlayerData(player);
limboService.restoreData(player);
// do we really need to use location from database for now?
// because LimboCache#restoreData teleport player to last location.
}
// TODO #1113: Need to set group before deleting limboPlayer??
commonService.setGroup(player, AuthGroupType.LOGGED_IN);
if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
@@ -2,7 +2,7 @@ package fr.xephi.authme.process.logout;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.AsynchronousProcess;
@@ -25,7 +25,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
private PlayerCache playerCache;
@Inject
private LimboCache limboCache;
private LimboService limboService;
@Inject
private SyncProcessManager syncProcessManager;
@@ -47,7 +47,8 @@ public class AsynchronousLogout implements AsynchronousProcess {
database.updateQuitLoc(auth);
}
limboCache.addPlayerData(player);
// TODO #1113: Would we not have to RESTORE the limbo player here?
limboService.createLimboPlayer(player);
playerCache.removePlayer(name);
database.setUnlogged(name);
syncProcessManager.processSyncPlayerLogout(player);
@@ -71,8 +71,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
teleportationService.teleportOnJoin(player);
// Apply Blindness effect
final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
}
@@ -1,7 +1,6 @@
package fr.xephi.authme.process.quit;
import fr.xephi.authme.data.limbo.LimboPlayerStorage;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.process.SynchronousProcess;
import org.bukkit.entity.Player;
@@ -11,22 +10,10 @@ import javax.inject.Inject;
public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
@Inject
private LimboPlayerStorage limboPlayerStorage;
@Inject
private LimboCache limboCache;
private LimboService limboService;
public void processSyncQuit(Player player) {
if (limboCache.hasPlayerData(player.getName())) { // it mean player is not authenticated
limboCache.restoreData(player);
limboCache.removeFromCache(player);
} else {
// Save player's data, so we could retrieve it later on player next join
if (!limboPlayerStorage.hasData(player)) {
limboPlayerStorage.saveData(player);
}
}
limboService.restoreData(player);
player.leaveVehicle();
}
}
@@ -1,7 +1,6 @@
package fr.xephi.authme.process.register;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.SynchronousProcess;
@@ -26,9 +25,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
@Inject
private CommonService service;
@Inject
private LimboCache limboCache;
@Inject
private LimboPlayerTaskManager limboPlayerTaskManager;
@@ -45,7 +41,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
*/
private void requestLogin(Player player) {
final String name = player.getName().toLowerCase();
limboCache.updatePlayerData(player);
limboPlayerTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, true);
@@ -3,19 +3,19 @@ package fr.xephi.authme.process.unregister;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.AuthGroupHandler;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.TeleportationService;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.LimboPlayerTaskManager;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.TeleportationService;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
@@ -43,7 +43,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
private BukkitService bukkitService;
@Inject
private LimboCache limboCache;
private LimboService limboService;
@Inject
private LimboPlayerTaskManager limboPlayerTaskManager;
@@ -111,8 +111,8 @@ public class AsynchronousUnregister implements AsynchronousProcess {
teleportationService.teleportOnJoin(player);
player.saveData();
limboCache.deletePlayerData(player);
limboCache.addPlayerData(player);
// TODO #1113: Why delete? limboCache.deletePlayerData(player);
limboService.createLimboPlayer(player);
limboPlayerTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, false);