#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;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
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.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.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
@ -39,7 +39,7 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
|||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||||
@ -83,7 +83,8 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
|||||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(new Runnable() {
|
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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));
|
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.command.PlayerCommand;
|
||||||
import fr.xephi.authme.data.CaptchaManager;
|
import fr.xephi.authme.data.CaptchaManager;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.data.limbo.LimboCache;
|
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
|
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -23,7 +23,7 @@ public class CaptchaCommand extends PlayerCommand {
|
|||||||
private CommonService commonService;
|
private CommonService commonService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runCommand(Player player, List<String> arguments) {
|
public void runCommand(Player player, List<String> arguments) {
|
||||||
@ -43,7 +43,7 @@ public class CaptchaCommand extends PlayerCommand {
|
|||||||
if (isCorrectCode) {
|
if (isCorrectCode) {
|
||||||
commonService.send(player, MessageKey.CAPTCHA_SUCCESS);
|
commonService.send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||||
commonService.send(player, MessageKey.LOGIN_MESSAGE);
|
commonService.send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
limboCache.getPlayerData(player.getName()).getMessageTask().setMuted(false);
|
limboPlayerTaskManager.unmuteMessageTask(player);
|
||||||
} else {
|
} else {
|
||||||
String newCode = captchaManager.generateCode(player.getName());
|
String newCode = captchaManager.generateCode(player.getName());
|
||||||
commonService.send(player, MessageKey.CAPTCHA_WRONG_ERROR, newCode);
|
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.
|
* Manages all {@link LimboPlayer} instances.
|
||||||
*/
|
*/
|
||||||
public class LimboCache {
|
class LimboCache {
|
||||||
|
|
||||||
private final Map<String, LimboPlayer> cache = new ConcurrentHashMap<>();
|
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.
|
* Class used to store player's data (OP, flying, speed, position) to disk.
|
||||||
*/
|
*/
|
||||||
public class LimboPlayerStorage {
|
class LimboPlayerStorage {
|
||||||
|
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final File cacheDir;
|
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.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.data.limbo.LimboPlayerStorage;
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.data.limbo.LimboCache;
|
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.PluginHookService;
|
import fr.xephi.authme.service.PluginHookService;
|
||||||
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
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.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -28,17 +27,15 @@ public class OnShutdownPlayerSaver {
|
|||||||
@Inject
|
@Inject
|
||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
|
||||||
@Inject
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
@Inject
|
@Inject
|
||||||
private LimboPlayerStorage limboPlayerStorage;
|
|
||||||
@Inject
|
|
||||||
private SpawnLoader spawnLoader;
|
private SpawnLoader spawnLoader;
|
||||||
@Inject
|
@Inject
|
||||||
private PluginHookService pluginHookService;
|
private PluginHookService pluginHookService;
|
||||||
@Inject
|
@Inject
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
@Inject
|
||||||
|
private LimboService limboService;
|
||||||
|
|
||||||
OnShutdownPlayerSaver() {
|
OnShutdownPlayerSaver() {
|
||||||
}
|
}
|
||||||
@ -57,9 +54,8 @@ public class OnShutdownPlayerSaver {
|
|||||||
if (pluginHookService.isNpc(player) || validationService.isUnrestricted(name)) {
|
if (pluginHookService.isNpc(player) || validationService.isUnrestricted(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (limboCache.hasPlayerData(name)) {
|
if (limboService.hasLimboPlayer(name)) {
|
||||||
limboCache.restoreData(player);
|
limboService.restoreData(player);
|
||||||
limboCache.removeFromCache(player);
|
|
||||||
} else {
|
} else {
|
||||||
saveLoggedinPlayer(player);
|
saveLoggedinPlayer(player);
|
||||||
}
|
}
|
||||||
@ -75,9 +71,5 @@ public class OnShutdownPlayerSaver {
|
|||||||
.location(loc).build();
|
.location(loc).build();
|
||||||
dataSource.updateQuitLoc(auth);
|
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;
|
package fr.xephi.authme.permission;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
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.LimboPlayer;
|
||||||
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.initialization.Reloadable;
|
import fr.xephi.authme.initialization.Reloadable;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
@ -33,7 +33,7 @@ public class AuthGroupHandler implements Reloadable {
|
|||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
private String unregisteredGroup;
|
private String unregisteredGroup;
|
||||||
private String registeredGroup;
|
private String registeredGroup;
|
||||||
@ -53,7 +53,7 @@ public class AuthGroupHandler implements Reloadable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String primaryGroup = Optional
|
String primaryGroup = Optional
|
||||||
.ofNullable(limboCache.getPlayerData(player.getName()))
|
.ofNullable(limboService.getLimboPlayer(player.getName()))
|
||||||
.map(LimboPlayer::getGroup)
|
.map(LimboPlayer::getGroup)
|
||||||
.orElse("");
|
.orElse("");
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import fr.xephi.authme.ConsoleLogger;
|
|||||||
import fr.xephi.authme.data.SessionManager;
|
import fr.xephi.authme.data.SessionManager;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.datasource.DataSource;
|
||||||
import fr.xephi.authme.events.ProtectInventoryEvent;
|
import fr.xephi.authme.events.ProtectInventoryEvent;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
@ -51,7 +51,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SessionManager sessionManager;
|
private SessionManager sessionManager;
|
||||||
@ -111,7 +111,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
||||||
|
|
||||||
if (isAuthAvailable) {
|
if (isAuthAvailable) {
|
||||||
limboCache.addPlayerData(player);
|
limboService.createLimboPlayer(player);
|
||||||
service.setGroup(player, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
service.setGroup(player, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
||||||
|
|
||||||
// Protect inventory
|
// Protect inventory
|
||||||
@ -141,9 +141,10 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// TODO #1113: Why delete and add LimboPlayer again?
|
||||||
// Not Registered. Delete old data, load default one.
|
// Not Registered. Delete old data, load default one.
|
||||||
limboCache.deletePlayerData(player);
|
// limboCache.deletePlayerData(player);
|
||||||
limboCache.addPlayerData(player);
|
// limboCache.addPlayerData(player);
|
||||||
|
|
||||||
// Groups logic
|
// Groups logic
|
||||||
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
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.TempbanManager;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.datasource.DataSource;
|
||||||
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
|
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
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.PlayerPermission;
|
||||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.service.CommonService;
|
|
||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
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.DatabaseSettings;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
|
||||||
import fr.xephi.authme.util.PlayerUtils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -52,9 +50,6 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LimboCache limboCache;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SyncProcessManager syncProcessManager;
|
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 the authentication fails check if Captcha is required and send a message to the player
|
||||||
if (captchaManager.isCaptchaRequired(player.getName())) {
|
if (captchaManager.isCaptchaRequired(player.getName())) {
|
||||||
limboCache.getPlayerData(player.getName()).getMessageTask().setMuted(true);
|
limboPlayerTaskManager.muteMessageTask(player);
|
||||||
service.send(player, MessageKey.USAGE_CAPTCHA,
|
service.send(player, MessageKey.USAGE_CAPTCHA,
|
||||||
captchaManager.getCaptchaCodeOrGenerateNew(player.getName()));
|
captchaManager.getCaptchaCodeOrGenerateNew(player.getName()));
|
||||||
}
|
}
|
||||||
@ -246,10 +241,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
// task, we schedule it in the end
|
// task, we schedule it in the end
|
||||||
// so that we can be sure, and have not to care if it might be
|
// so that we can be sure, and have not to care if it might be
|
||||||
// processed in other order.
|
// processed in other order.
|
||||||
LimboPlayer limboPlayer = limboCache.getPlayerData(name);
|
limboPlayerTaskManager.clearTasks(player);
|
||||||
if (limboPlayer != null) {
|
|
||||||
limboPlayer.clearTasks();
|
|
||||||
}
|
|
||||||
syncProcessManager.processSyncPlayerLogin(player);
|
syncProcessManager.processSyncPlayerLogin(player);
|
||||||
} else {
|
} else {
|
||||||
ConsoleLogger.warning("Player '" + player.getName() + "' wasn't online during login process, aborted...");
|
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);
|
int threshold = service.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD_THRESHOLD);
|
||||||
String command = service.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD);
|
String command = service.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD);
|
||||||
|
|
||||||
if(threshold < 2 || command.isEmpty()) {
|
if (threshold < 2 || command.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package fr.xephi.authme.process.login;
|
package fr.xephi.authme.process.login;
|
||||||
|
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
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.LimboPlayer;
|
||||||
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.events.LoginEvent;
|
import fr.xephi.authme.events.LoginEvent;
|
||||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||||
@ -31,7 +31,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
private BungeeService bungeeService;
|
private BungeeService bungeeService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
@ -65,14 +65,14 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
public void processPlayerLogin(Player player) {
|
public void processPlayerLogin(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
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
|
// Limbo contains the State of the Player before /login
|
||||||
if (limbo != null) {
|
if (limbo != null) {
|
||||||
limboCache.restoreData(player);
|
limboService.restoreData(player);
|
||||||
limboCache.deletePlayerData(player);
|
|
||||||
// do we really need to use location from database for now?
|
// do we really need to use location from database for now?
|
||||||
// because LimboCache#restoreData teleport player to last location.
|
// because LimboCache#restoreData teleport player to last location.
|
||||||
}
|
}
|
||||||
|
// TODO #1113: Need to set group before deleting limboPlayer??
|
||||||
commonService.setGroup(player, AuthGroupType.LOGGED_IN);
|
commonService.setGroup(player, AuthGroupType.LOGGED_IN);
|
||||||
|
|
||||||
if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
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.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
@ -25,7 +25,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
|||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SyncProcessManager syncProcessManager;
|
private SyncProcessManager syncProcessManager;
|
||||||
@ -47,7 +47,8 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
|||||||
database.updateQuitLoc(auth);
|
database.updateQuitLoc(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
limboCache.addPlayerData(player);
|
// TODO #1113: Would we not have to RESTORE the limbo player here?
|
||||||
|
limboService.createLimboPlayer(player);
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
syncProcessManager.processSyncPlayerLogout(player);
|
syncProcessManager.processSyncPlayerLogout(player);
|
||||||
|
|||||||
@ -71,8 +71,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
|||||||
teleportationService.teleportOnJoin(player);
|
teleportationService.teleportOnJoin(player);
|
||||||
|
|
||||||
// Apply Blindness effect
|
// Apply Blindness effect
|
||||||
final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
|
||||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||||
|
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package fr.xephi.authme.process.quit;
|
package fr.xephi.authme.process.quit;
|
||||||
|
|
||||||
import fr.xephi.authme.data.limbo.LimboPlayerStorage;
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.data.limbo.LimboCache;
|
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -11,22 +10,10 @@ import javax.inject.Inject;
|
|||||||
public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
|
public class ProcessSyncronousPlayerQuit implements SynchronousProcess {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboPlayerStorage limboPlayerStorage;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LimboCache limboCache;
|
|
||||||
|
|
||||||
public void processSyncQuit(Player player) {
|
public void processSyncQuit(Player player) {
|
||||||
if (limboCache.hasPlayerData(player.getName())) { // it mean player is not authenticated
|
limboService.restoreData(player);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.leaveVehicle();
|
player.leaveVehicle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package fr.xephi.authme.process.register;
|
package fr.xephi.authme.process.register;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.limbo.LimboCache;
|
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
import fr.xephi.authme.permission.AuthGroupType;
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
@ -26,9 +25,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private CommonService service;
|
private CommonService service;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LimboCache limboCache;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||||
|
|
||||||
@ -45,7 +41,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
*/
|
*/
|
||||||
private void requestLogin(Player player) {
|
private void requestLogin(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
limboCache.updatePlayerData(player);
|
|
||||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||||
|
|
||||||
|
|||||||
@ -3,19 +3,19 @@ package fr.xephi.authme.process.unregister;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
import fr.xephi.authme.permission.AuthGroupType;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.service.CommonService;
|
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
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.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
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.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
@ -43,7 +43,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||||
@ -111,8 +111,8 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
teleportationService.teleportOnJoin(player);
|
teleportationService.teleportOnJoin(player);
|
||||||
player.saveData();
|
player.saveData();
|
||||||
|
|
||||||
limboCache.deletePlayerData(player);
|
// TODO #1113: Why delete? limboCache.deletePlayerData(player);
|
||||||
limboCache.addPlayerData(player);
|
limboService.createLimboPlayer(player);
|
||||||
|
|
||||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||||
limboPlayerTaskManager.registerMessageTask(name, false);
|
limboPlayerTaskManager.registerMessageTask(name, false);
|
||||||
|
|||||||
@ -99,19 +99,19 @@ public class TeleportationService implements Reloadable {
|
|||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
* @param auth corresponding PlayerAuth object
|
* @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) {
|
public void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer limbo) {
|
||||||
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
|
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
|
||||||
return;
|
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)
|
String worldName = (limbo != null && limbo.getLocation() != null)
|
||||||
? limbo.getLocation().getWorld().getName()
|
? limbo.getLocation().getWorld().getName()
|
||||||
: null;
|
: 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)) {
|
if (mustForceSpawnAfterLogin(worldName)) {
|
||||||
teleportToSpawn(player, true);
|
teleportToSpawn(player, true);
|
||||||
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
} 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
|
* 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 player the player to teleport
|
||||||
* @param event the event to emit and according to which 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.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.LimboPlayer;
|
||||||
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.message.Messages;
|
import fr.xephi.authme.message.Messages;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
@ -33,7 +33,7 @@ public class LimboPlayerTaskManager {
|
|||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
@ -53,7 +53,7 @@ public class LimboPlayerTaskManager {
|
|||||||
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||||
final MessageKey key = getMessageKey(isRegistered);
|
final MessageKey key = getMessageKey(isRegistered);
|
||||||
if (interval > 0) {
|
if (interval > 0) {
|
||||||
final LimboPlayer limboPlayer = limboCache.getPlayerData(name);
|
final LimboPlayer limboPlayer = limboService.getLimboPlayer(name);
|
||||||
if (limboPlayer == null) {
|
if (limboPlayer == null) {
|
||||||
ConsoleLogger.info("PlayerData for '" + name + "' is not available");
|
ConsoleLogger.info("PlayerData for '" + name + "' is not available");
|
||||||
} else {
|
} else {
|
||||||
@ -73,7 +73,7 @@ public class LimboPlayerTaskManager {
|
|||||||
public void registerTimeoutTask(Player player) {
|
public void registerTimeoutTask(Player player) {
|
||||||
final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
final LimboPlayer limboPlayer = limboCache.getPlayerData(player.getName());
|
final LimboPlayer limboPlayer = limboService.getLimboPlayer(player.getName());
|
||||||
if (limboPlayer == null) {
|
if (limboPlayer == null) {
|
||||||
ConsoleLogger.info("PlayerData for '" + player.getName() + "' is not available");
|
ConsoleLogger.info("PlayerData for '" + player.getName() + "' is not available");
|
||||||
} else {
|
} 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.
|
* Returns the appropriate message key according to the registration status and settings.
|
||||||
*
|
*
|
||||||
@ -120,4 +141,16 @@ public class LimboPlayerTaskManager {
|
|||||||
task.cancel();
|
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.TestHelper;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
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.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
@ -57,7 +57,7 @@ public class RegisterAdminCommandTest {
|
|||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpLogger() {
|
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.CaptchaManager;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.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.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -40,7 +38,7 @@ public class CaptchaCommandTest {
|
|||||||
private CommonService commandService;
|
private CommonService commandService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private LimboCache limboCache;
|
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDetectIfPlayerIsLoggedIn() {
|
public void shouldDetectIfPlayerIsLoggedIn() {
|
||||||
@ -82,10 +80,6 @@ public class CaptchaCommandTest {
|
|||||||
given(captchaManager.isCaptchaRequired(name)).willReturn(true);
|
given(captchaManager.isCaptchaRequired(name)).willReturn(true);
|
||||||
String captchaCode = "3991";
|
String captchaCode = "3991";
|
||||||
given(captchaManager.checkCode(name, captchaCode)).willReturn(true);
|
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
|
// when
|
||||||
command.executeCommand(player, Collections.singletonList(captchaCode));
|
command.executeCommand(player, Collections.singletonList(captchaCode));
|
||||||
@ -96,7 +90,7 @@ public class CaptchaCommandTest {
|
|||||||
verifyNoMoreInteractions(captchaManager);
|
verifyNoMoreInteractions(captchaManager);
|
||||||
verify(commandService).send(player, MessageKey.CAPTCHA_SUCCESS);
|
verify(commandService).send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||||
verify(commandService).send(player, MessageKey.LOGIN_MESSAGE);
|
verify(commandService).send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
verify(messageTask).setMuted(false);
|
verify(limboPlayerTaskManager).unmuteMessageTask(player);
|
||||||
verifyNoMoreInteractions(commandService);
|
verifyNoMoreInteractions(commandService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,15 +3,15 @@ package fr.xephi.authme.process.unregister;
|
|||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
import fr.xephi.authme.permission.AuthGroupType;
|
||||||
import fr.xephi.authme.service.CommonService;
|
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
@ -53,7 +53,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
@Mock
|
@Mock
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
@Mock
|
@Mock
|
||||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||||
@Mock
|
@Mock
|
||||||
@ -85,7 +85,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
// then
|
// then
|
||||||
verify(service).send(player, MessageKey.WRONG_PASSWORD);
|
verify(service).send(player, MessageKey.WRONG_PASSWORD);
|
||||||
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
||||||
verifyZeroInteractions(dataSource, limboPlayerTaskManager, limboCache, authGroupHandler, teleportationService);
|
verifyZeroInteractions(dataSource, limboPlayerTaskManager, limboService, authGroupHandler, teleportationService);
|
||||||
verify(player, only()).getName();
|
verify(player, only()).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,8 @@ package fr.xephi.authme.task;
|
|||||||
|
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
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.LimboPlayer;
|
||||||
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.message.Messages;
|
import fr.xephi.authme.message.Messages;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
@ -47,7 +47,7 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private LimboCache limboCache;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
@ -62,7 +62,7 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
// given
|
// given
|
||||||
String name = "bobby";
|
String name = "bobby";
|
||||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||||
MessageKey key = MessageKey.REGISTER_MESSAGE;
|
MessageKey key = MessageKey.REGISTER_MESSAGE;
|
||||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||||
int interval = 12;
|
int interval = 12;
|
||||||
@ -82,14 +82,14 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
public void shouldNotScheduleTaskForMissingLimboPlayer() {
|
public void shouldNotScheduleTaskForMissingLimboPlayer() {
|
||||||
// given
|
// given
|
||||||
String name = "ghost";
|
String name = "ghost";
|
||||||
given(limboCache.getPlayerData(name)).willReturn(null);
|
given(limboService.getLimboPlayer(name)).willReturn(null);
|
||||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5);
|
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(limboCache).getPlayerData(name);
|
verify(limboService).getLimboPlayer(name);
|
||||||
verifyZeroInteractions(bukkitService);
|
verifyZeroInteractions(bukkitService);
|
||||||
verifyZeroInteractions(messages);
|
verifyZeroInteractions(messages);
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
given(limboPlayer.getMessageTask()).willReturn(existingMessageTask);
|
given(limboPlayer.getMessageTask()).willReturn(existingMessageTask);
|
||||||
|
|
||||||
String name = "bobby";
|
String name = "bobby";
|
||||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -136,7 +136,7 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
given(player.getName()).willReturn(name);
|
given(player.getName()).willReturn(name);
|
||||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30);
|
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30);
|
||||||
BukkitTask bukkitTask = mock(BukkitTask.class);
|
BukkitTask bukkitTask = mock(BukkitTask.class);
|
||||||
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
||||||
@ -156,7 +156,7 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
String name = "Phantom_";
|
String name = "Phantom_";
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
given(player.getName()).willReturn(name);
|
given(player.getName()).willReturn(name);
|
||||||
given(limboCache.getPlayerData(name)).willReturn(null);
|
given(limboService.getLimboPlayer(name)).willReturn(null);
|
||||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27);
|
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -189,7 +189,7 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||||
BukkitTask existingTask = mock(BukkitTask.class);
|
BukkitTask existingTask = mock(BukkitTask.class);
|
||||||
given(limboPlayer.getTimeoutTask()).willReturn(existingTask);
|
given(limboPlayer.getTimeoutTask()).willReturn(existingTask);
|
||||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
|
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
|
||||||
BukkitTask bukkitTask = mock(BukkitTask.class);
|
BukkitTask bukkitTask = mock(BukkitTask.class);
|
||||||
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user