mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 02:35:11 +01:00
#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:
parent
6db778387d
commit
22ccf582b8
@ -1,9 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
@ -39,7 +39,7 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
||||
private ValidationService validationService;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
@ -83,7 +83,8 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
limboCache.restoreData(player);
|
||||
// TODO #1113: Is it necessary to restore here or is this covered by the quit process?
|
||||
limboService.restoreData(player);
|
||||
player.kickPlayer(commonService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER));
|
||||
}
|
||||
});
|
||||
|
@ -3,9 +3,9 @@ package fr.xephi.authme.command.executable.captcha;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.data.CaptchaManager;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -23,7 +23,7 @@ public class CaptchaCommand extends PlayerCommand {
|
||||
private CommonService commonService;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
@ -43,7 +43,7 @@ public class CaptchaCommand extends PlayerCommand {
|
||||
if (isCorrectCode) {
|
||||
commonService.send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||
commonService.send(player, MessageKey.LOGIN_MESSAGE);
|
||||
limboCache.getPlayerData(player.getName()).getMessageTask().setMuted(false);
|
||||
limboPlayerTaskManager.unmuteMessageTask(player);
|
||||
} else {
|
||||
String newCode = captchaManager.generateCode(player.getName());
|
||||
commonService.send(player, MessageKey.CAPTCHA_WRONG_ERROR, newCode);
|
||||
|
@ -15,7 +15,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
/**
|
||||
* Manages all {@link LimboPlayer} instances.
|
||||
*/
|
||||
public class LimboCache {
|
||||
class LimboCache {
|
||||
|
||||
private final Map<String, LimboPlayer> cache = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -29,7 +29,7 @@ import java.nio.charset.StandardCharsets;
|
||||
/**
|
||||
* Class used to store player's data (OP, flying, speed, position) to disk.
|
||||
*/
|
||||
public class LimboPlayerStorage {
|
||||
class LimboPlayerStorage {
|
||||
|
||||
private final Gson gson;
|
||||
private final File cacheDir;
|
||||
|
60
src/main/java/fr/xephi/authme/data/limbo/LimboService.java
Normal file
60
src/main/java/fr/xephi/authme/data/limbo/LimboService.java
Normal file
@ -0,0 +1,60 @@
|
||||
package fr.xephi.authme.data.limbo;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Service for managing players that are in "limbo," a temporary state players are
|
||||
* put in which have joined but not yet logged in yet.
|
||||
*/
|
||||
public class LimboService {
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
LimboService() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restores the limbo data and subsequently deletes the entry.
|
||||
*
|
||||
* @param player the player whose data should be restored
|
||||
*/
|
||||
public void restoreData(Player player) {
|
||||
// TODO #1113: Think about architecture for various "restore" strategies
|
||||
limboCache.restoreData(player);
|
||||
limboCache.deletePlayerData(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the limbo player for the given name, or null otherwise.
|
||||
*
|
||||
* @param name the name to retrieve the data for
|
||||
* @return the associated limbo player, or null if none available
|
||||
*/
|
||||
public LimboPlayer getLimboPlayer(String name) {
|
||||
return limboCache.getPlayerData(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether there is a limbo player for the given name.
|
||||
*
|
||||
* @param name the name to check
|
||||
* @return true if present, false otherwise
|
||||
*/
|
||||
public boolean hasLimboPlayer(String name) {
|
||||
return limboCache.hasPlayerData(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a LimboPlayer for the given player.
|
||||
*
|
||||
* @param player the player to process
|
||||
*/
|
||||
public void createLimboPlayer(Player player) {
|
||||
// TODO #1113: We should remove the player's data in here as well
|
||||
limboCache.addPlayerData(player);
|
||||
}
|
||||
}
|
@ -2,15 +2,14 @@ package fr.xephi.authme.initialization;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
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.datasource.DataSource;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -28,17 +27,15 @@ public class OnShutdownPlayerSaver {
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
@Inject
|
||||
private LimboPlayerStorage limboPlayerStorage;
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
@Inject
|
||||
private PluginHookService pluginHookService;
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
@Inject
|
||||
private LimboService limboService;
|
||||
|
||||
OnShutdownPlayerSaver() {
|
||||
}
|
||||
@ -57,9 +54,8 @@ public class OnShutdownPlayerSaver {
|
||||
if (pluginHookService.isNpc(player) || validationService.isUnrestricted(name)) {
|
||||
return;
|
||||
}
|
||||
if (limboCache.hasPlayerData(name)) {
|
||||
limboCache.restoreData(player);
|
||||
limboCache.removeFromCache(player);
|
||||
if (limboService.hasLimboPlayer(name)) {
|
||||
limboService.restoreData(player);
|
||||
} else {
|
||||
saveLoggedinPlayer(player);
|
||||
}
|
||||
@ -75,9 +71,5 @@ public class OnShutdownPlayerSaver {
|
||||
.location(loc).build();
|
||||
dataSource.updateQuitLoc(auth);
|
||||
}
|
||||
if (settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)
|
||||
&& !settings.getProperty(RestrictionSettings.NO_TELEPORT) && !limboPlayerStorage.hasData(player)) {
|
||||
limboPlayerStorage.saveData(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package fr.xephi.authme.permission;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
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.initialization.Reloadable;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
@ -33,7 +33,7 @@ public class AuthGroupHandler implements Reloadable {
|
||||
private Settings settings;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
private String unregisteredGroup;
|
||||
private String registeredGroup;
|
||||
@ -53,7 +53,7 @@ public class AuthGroupHandler implements Reloadable {
|
||||
}
|
||||
|
||||
String primaryGroup = Optional
|
||||
.ofNullable(limboCache.getPlayerData(player.getName()))
|
||||
.ofNullable(limboService.getLimboPlayer(player.getName()))
|
||||
.map(LimboPlayer::getGroup)
|
||||
.orElse("");
|
||||
|
||||
|
@ -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);
|
||||
|
@ -99,19 +99,19 @@ public class TeleportationService implements Reloadable {
|
||||
*
|
||||
* @param player the player
|
||||
* @param auth corresponding PlayerAuth object
|
||||
* @param limbo corresponding PlayerData object
|
||||
* @param limbo corresponding LimboPlayer object
|
||||
*/
|
||||
public void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer limbo) {
|
||||
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// #856: If PlayerData comes from a persisted file, the Location might be null
|
||||
// #856: If LimboPlayer comes from a persisted file, the Location might be null
|
||||
String worldName = (limbo != null && limbo.getLocation() != null)
|
||||
? limbo.getLocation().getWorld().getName()
|
||||
: null;
|
||||
|
||||
// The world in PlayerData is from where the player comes, before any teleportation by AuthMe
|
||||
// The world in LimboPlayer is from where the player comes, before any teleportation by AuthMe
|
||||
if (mustForceSpawnAfterLogin(worldName)) {
|
||||
teleportToSpawn(player, true);
|
||||
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
||||
@ -148,7 +148,7 @@ public class TeleportationService implements Reloadable {
|
||||
|
||||
/**
|
||||
* Emits the teleportation event and performs teleportation according to it (potentially modified
|
||||
* by external listeners). Note that not teleportation is performed if the event's location is empty.
|
||||
* by external listeners). Note that no teleportation is performed if the event's location is empty.
|
||||
*
|
||||
* @param player the player to teleport
|
||||
* @param event the event to emit and according to which to teleport
|
||||
|
@ -2,8 +2,8 @@ package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
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.data.limbo.LimboService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
@ -33,7 +33,7 @@ public class LimboPlayerTaskManager {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
@ -53,7 +53,7 @@ public class LimboPlayerTaskManager {
|
||||
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
final MessageKey key = getMessageKey(isRegistered);
|
||||
if (interval > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getPlayerData(name);
|
||||
final LimboPlayer limboPlayer = limboService.getLimboPlayer(name);
|
||||
if (limboPlayer == null) {
|
||||
ConsoleLogger.info("PlayerData for '" + name + "' is not available");
|
||||
} else {
|
||||
@ -73,7 +73,7 @@ public class LimboPlayerTaskManager {
|
||||
public void registerTimeoutTask(Player player) {
|
||||
final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
if (timeout > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getPlayerData(player.getName());
|
||||
final LimboPlayer limboPlayer = limboService.getLimboPlayer(player.getName());
|
||||
if (limboPlayer == null) {
|
||||
ConsoleLogger.info("PlayerData for '" + player.getName() + "' is not available");
|
||||
} else {
|
||||
@ -85,6 +85,27 @@ public class LimboPlayerTaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void muteMessageTask(Player player) {
|
||||
LimboPlayer limbo = limboService.getLimboPlayer(player.getName());
|
||||
if (limbo != null) {
|
||||
setMuted(limbo.getMessageTask(), true);
|
||||
}
|
||||
}
|
||||
|
||||
public void unmuteMessageTask(Player player) {
|
||||
LimboPlayer limbo = limboService.getLimboPlayer(player.getName());
|
||||
if (limbo != null) {
|
||||
setMuted(limbo.getMessageTask(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearTasks(Player player) {
|
||||
LimboPlayer limbo = limboService.getLimboPlayer(player.getName());
|
||||
if (limbo != null) {
|
||||
limbo.clearTasks();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate message key according to the registration status and settings.
|
||||
*
|
||||
@ -120,4 +141,16 @@ public class LimboPlayerTaskManager {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe method to set the muted flag on a message task.
|
||||
*
|
||||
* @param task the task to modify (or null)
|
||||
* @param isMuted the value to set if task is not null
|
||||
*/
|
||||
private static void setMuted(MessageTask task, boolean isMuted) {
|
||||
if (task != null) {
|
||||
task.setMuted(isMuted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
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.security.PasswordSecurity;
|
||||
@ -57,7 +57,7 @@ public class RegisterAdminCommandTest {
|
||||
private ValidationService validationService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
|
@ -2,11 +2,9 @@ package fr.xephi.authme.command.executable.captcha;
|
||||
|
||||
import fr.xephi.authme.data.CaptchaManager;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -40,7 +38,7 @@ public class CaptchaCommandTest {
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
@Test
|
||||
public void shouldDetectIfPlayerIsLoggedIn() {
|
||||
@ -82,10 +80,6 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.isCaptchaRequired(name)).willReturn(true);
|
||||
String captchaCode = "3991";
|
||||
given(captchaManager.checkCode(name, captchaCode)).willReturn(true);
|
||||
MessageTask messageTask = mock(MessageTask.class);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboPlayer.getMessageTask()).willReturn(messageTask);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode));
|
||||
@ -96,7 +90,7 @@ public class CaptchaCommandTest {
|
||||
verifyNoMoreInteractions(captchaManager);
|
||||
verify(commandService).send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||
verify(commandService).send(player, MessageKey.LOGIN_MESSAGE);
|
||||
verify(messageTask).setMuted(false);
|
||||
verify(limboPlayerTaskManager).unmuteMessageTask(player);
|
||||
verifyNoMoreInteractions(commandService);
|
||||
}
|
||||
|
||||
|
@ -3,15 +3,15 @@ package fr.xephi.authme.process.unregister;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
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.service.CommonService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
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;
|
||||
@ -53,7 +53,7 @@ public class AsynchronousUnregisterTest {
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
@Mock
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
@Mock
|
||||
@ -85,7 +85,7 @@ public class AsynchronousUnregisterTest {
|
||||
// then
|
||||
verify(service).send(player, MessageKey.WRONG_PASSWORD);
|
||||
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
||||
verifyZeroInteractions(dataSource, limboPlayerTaskManager, limboCache, authGroupHandler, teleportationService);
|
||||
verifyZeroInteractions(dataSource, limboPlayerTaskManager, limboService, authGroupHandler, teleportationService);
|
||||
verify(player, only()).getName();
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
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.data.limbo.LimboService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
@ -47,7 +47,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
@ -62,7 +62,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
// given
|
||||
String name = "bobby";
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
MessageKey key = MessageKey.REGISTER_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||
int interval = 12;
|
||||
@ -82,14 +82,14 @@ public class LimboPlayerTaskManagerTest {
|
||||
public void shouldNotScheduleTaskForMissingLimboPlayer() {
|
||||
// given
|
||||
String name = "ghost";
|
||||
given(limboCache.getPlayerData(name)).willReturn(null);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(null);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||
|
||||
// then
|
||||
verify(limboCache).getPlayerData(name);
|
||||
verify(limboService).getLimboPlayer(name);
|
||||
verifyZeroInteractions(bukkitService);
|
||||
verifyZeroInteractions(messages);
|
||||
}
|
||||
@ -117,7 +117,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
given(limboPlayer.getMessageTask()).willReturn(existingMessageTask);
|
||||
|
||||
String name = "bobby";
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||
|
||||
// when
|
||||
@ -136,7 +136,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30);
|
||||
BukkitTask bukkitTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
||||
@ -156,7 +156,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
String name = "Phantom_";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
given(limboCache.getPlayerData(name)).willReturn(null);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(null);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27);
|
||||
|
||||
// when
|
||||
@ -189,7 +189,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
BukkitTask existingTask = mock(BukkitTask.class);
|
||||
given(limboPlayer.getTimeoutTask()).willReturn(existingTask);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
|
||||
BukkitTask bukkitTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
||||
|
Loading…
Reference in New Issue
Block a user