mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-21 08:07:38 +01:00
Minor - rename LimboPlayer methods + code householding
- Rename *taskId methods to *task to reflect what they handle - Remove usages of Wrapper where applicable - Replace some uses of legacy Settings with NewSetting calls
This commit is contained in:
parent
3f4681c5ed
commit
654cebd5a7
@ -815,8 +815,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Utils.addNormal(player, limbo.getGroup());
|
Utils.addNormal(player, limbo.getGroup());
|
||||||
player.setOp(limbo.getOperator());
|
player.setOp(limbo.isOperator());
|
||||||
limbo.getTimeoutTaskId().cancel();
|
limbo.getTimeoutTask().cancel();
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
if (this.playerBackup.doesCacheExist(player)) {
|
if (this.playerBackup.doesCacheExist(player)) {
|
||||||
this.playerBackup.removeCache(player);
|
this.playerBackup.removeCache(player);
|
||||||
|
@ -16,8 +16,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
public class LimboCache {
|
public class LimboCache {
|
||||||
|
|
||||||
private volatile static LimboCache singleton;
|
private volatile static LimboCache singleton;
|
||||||
public final ConcurrentHashMap<String, LimboPlayer> cache;
|
private final ConcurrentHashMap<String, LimboPlayer> cache;
|
||||||
public final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final JsonCache jsonCache;
|
private final JsonCache jsonCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,7 +84,7 @@ public class LimboCache {
|
|||||||
checkNotNull(name);
|
checkNotNull(name);
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
if (cache.containsKey(name)) {
|
if (cache.containsKey(name)) {
|
||||||
cache.get(name).clearTask();
|
cache.get(name).clearTasks();
|
||||||
cache.remove(name);
|
cache.remove(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,16 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Represents a player which is not logged in and keeps track of certain states (like OP status, flying)
|
||||||
|
* which may be revoked from the player until he has logged in or registered.
|
||||||
*/
|
*/
|
||||||
public class LimboPlayer {
|
public class LimboPlayer {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final boolean fly;
|
private final boolean fly;
|
||||||
private Location loc = null;
|
private Location loc = null;
|
||||||
private BukkitTask timeoutTaskId = null;
|
private BukkitTask timeoutTask = null;
|
||||||
private BukkitTask messageTaskId = null;
|
private BukkitTask messageTask = null;
|
||||||
private boolean operator = false;
|
private boolean operator = false;
|
||||||
private String group;
|
private String group;
|
||||||
|
|
||||||
@ -25,36 +27,36 @@ public class LimboPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getName.
|
* Return the name of the player.
|
||||||
*
|
*
|
||||||
* @return String
|
* @return The player's name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLoc.
|
* Return the player's original location.
|
||||||
*
|
*
|
||||||
* @return Location
|
* @return The player's location
|
||||||
*/
|
*/
|
||||||
public Location getLoc() {
|
public Location getLoc() {
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getOperator.
|
* Return whether the player is an operator or not (i.e. whether he is an OP).
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return True if the player has OP status, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean getOperator() {
|
public boolean isOperator() {
|
||||||
return operator;
|
return operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getGroup.
|
* Return the player's permissions group.
|
||||||
*
|
*
|
||||||
* @return String
|
* @return The permissions group the player belongs to
|
||||||
*/
|
*/
|
||||||
public String getGroup() {
|
public String getGroup() {
|
||||||
return group;
|
return group;
|
||||||
@ -64,54 +66,61 @@ public class LimboPlayer {
|
|||||||
return fly;
|
return fly;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitTask getTimeoutTaskId() {
|
|
||||||
return timeoutTaskId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method setTimeoutTaskId.
|
* Return the timeout task, which kicks the player if he hasn't registered or logged in
|
||||||
|
* after a configurable amount of time.
|
||||||
*
|
*
|
||||||
* @param i BukkitTask
|
* @return The timeout task associated to the player
|
||||||
*/
|
*/
|
||||||
public void setTimeoutTaskId(BukkitTask i) {
|
public BukkitTask getTimeoutTask() {
|
||||||
if (this.timeoutTaskId != null) {
|
return timeoutTask;
|
||||||
this.timeoutTaskId.cancel();
|
|
||||||
}
|
|
||||||
this.timeoutTaskId = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getMessageTaskId.
|
* Set the timeout task of the player. The timeout task kicks the player after a configurable
|
||||||
|
* amount of time if he hasn't logged in or registered.
|
||||||
*
|
*
|
||||||
* @return BukkitTask
|
* @param timeoutTask The task to set
|
||||||
*/
|
*/
|
||||||
public BukkitTask getMessageTaskId() {
|
public void setTimeoutTask(BukkitTask timeoutTask) {
|
||||||
return messageTaskId;
|
if (this.timeoutTask != null) {
|
||||||
|
this.timeoutTask.cancel();
|
||||||
|
}
|
||||||
|
this.timeoutTask = timeoutTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method setMessageTaskId.
|
* Return the message task reminding the player to log in or register.
|
||||||
*
|
*
|
||||||
* @param messageTaskId BukkitTask
|
* @return The task responsible for sending the message regularly
|
||||||
*/
|
*/
|
||||||
public void setMessageTaskId(BukkitTask messageTaskId) {
|
public BukkitTask getMessageTask() {
|
||||||
if (this.messageTaskId != null) {
|
return messageTask;
|
||||||
this.messageTaskId.cancel();
|
|
||||||
}
|
|
||||||
this.messageTaskId = messageTaskId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method clearTask.
|
* Set the messages task responsible for telling the player to log in or register.
|
||||||
|
*
|
||||||
|
* @param messageTask The message task to set
|
||||||
*/
|
*/
|
||||||
public void clearTask() {
|
public void setMessageTask(BukkitTask messageTask) {
|
||||||
if (messageTaskId != null) {
|
if (this.messageTask != null) {
|
||||||
messageTaskId.cancel();
|
this.messageTask.cancel();
|
||||||
}
|
}
|
||||||
messageTaskId = null;
|
this.messageTask = messageTask;
|
||||||
if (timeoutTaskId != null) {
|
|
||||||
timeoutTaskId.cancel();
|
|
||||||
}
|
}
|
||||||
timeoutTaskId = null;
|
|
||||||
|
/**
|
||||||
|
* Clears all tasks associated to the player.
|
||||||
|
*/
|
||||||
|
public void clearTasks() {
|
||||||
|
if (messageTask != null) {
|
||||||
|
messageTask.cancel();
|
||||||
|
}
|
||||||
|
messageTask = null;
|
||||||
|
if (timeoutTask != null) {
|
||||||
|
timeoutTask.cancel();
|
||||||
|
}
|
||||||
|
timeoutTask = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.command.help.HelpProvider;
|
import fr.xephi.authme.command.help.HelpProvider;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.cache.IpAddressManager;
|
import fr.xephi.authme.cache.IpAddressManager;
|
||||||
@ -190,4 +191,8 @@ public class CommandService {
|
|||||||
return ipAddressManager;
|
return ipAddressManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerCache getPlayerCache() {
|
||||||
|
return PlayerCache.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
|||||||
BukkitScheduler scheduler = sender.getServer().getScheduler();
|
BukkitScheduler scheduler = sender.getServer().getScheduler();
|
||||||
if (timeOut != 0) {
|
if (timeOut != 0) {
|
||||||
BukkitTask id = scheduler.runTaskLater(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), timeOut);
|
BukkitTask id = scheduler.runTaskLater(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), timeOut);
|
||||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
|
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTask(id);
|
||||||
}
|
}
|
||||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
|
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTask(
|
||||||
scheduler.runTask(
|
scheduler.runTask(
|
||||||
plugin, new MessageTask(plugin, playerNameLowerCase, MessageKey.REGISTER_MESSAGE, interval)
|
plugin, new MessageTask(plugin, playerNameLowerCase, MessageKey.REGISTER_MESSAGE, interval)
|
||||||
)
|
)
|
||||||
|
@ -7,7 +7,6 @@ import fr.xephi.authme.command.PlayerCommand;
|
|||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.Wrapper;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,9 +17,8 @@ public class CaptchaCommand extends PlayerCommand {
|
|||||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||||
final String captcha = arguments.get(0);
|
final String captcha = arguments.get(0);
|
||||||
Wrapper wrapper = Wrapper.getInstance();
|
final AuthMe plugin = commandService.getAuthMe();
|
||||||
final AuthMe plugin = wrapper.getAuthMe();
|
PlayerCache playerCache = PlayerCache.getInstance();
|
||||||
PlayerCache playerCache = wrapper.getPlayerCache();
|
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
if (playerCache.isAuthenticated(playerNameLowerCase)) {
|
if (playerCache.isAuthenticated(playerNameLowerCase)) {
|
||||||
|
@ -8,7 +8,6 @@ import fr.xephi.authme.output.MessageKey;
|
|||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.task.ChangePasswordTask;
|
import fr.xephi.authme.task.ChangePasswordTask;
|
||||||
import fr.xephi.authme.util.Wrapper;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -24,8 +23,7 @@ public class ChangePasswordCommand extends PlayerCommand {
|
|||||||
String newPassword = arguments.get(1);
|
String newPassword = arguments.get(1);
|
||||||
|
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
Wrapper wrapper = Wrapper.getInstance();
|
final PlayerCache playerCache = commandService.getPlayerCache();
|
||||||
final PlayerCache playerCache = wrapper.getPlayerCache();
|
|
||||||
if (!playerCache.isAuthenticated(name)) {
|
if (!playerCache.isAuthenticated(name)) {
|
||||||
commandService.send(player, MessageKey.NOT_LOGGED_IN);
|
commandService.send(player, MessageKey.NOT_LOGGED_IN);
|
||||||
return;
|
return;
|
||||||
|
@ -64,8 +64,6 @@ public class AsynchronousJoin implements Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String ip = service.getIpAddressManager().getPlayerIp(player);
|
final String ip = service.getIpAddressManager().getPlayerIp(player);
|
||||||
|
|
||||||
|
|
||||||
if (isNameRestricted(name, ip, player.getAddress().getHostName(), service.getSettings())) {
|
if (isNameRestricted(name, ip, player.getAddress().getHostName(), service.getSettings())) {
|
||||||
service.scheduleSyncDelayedTask(new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -196,7 +194,7 @@ public class AsynchronousJoin implements Process {
|
|||||||
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||||
if (registrationTimeout > 0) {
|
if (registrationTimeout > 0) {
|
||||||
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout);
|
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout);
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTask(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageKey msg;
|
MessageKey msg;
|
||||||
@ -209,7 +207,7 @@ public class AsynchronousJoin implements Process {
|
|||||||
}
|
}
|
||||||
if (msgInterval > 0 && LimboCache.getInstance().getLimboPlayer(name) != null) {
|
if (msgInterval > 0 && LimboCache.getInstance().getLimboPlayer(name) != null) {
|
||||||
BukkitTask msgTask = service.runTask(new MessageTask(plugin, name, msg, msgInterval));
|
BukkitTask msgTask = service.runTask(new MessageTask(plugin, name, msg, msgInterval));
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask);
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTask(msgTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import fr.xephi.authme.security.RandomString;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
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.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.task.MessageTask;
|
import fr.xephi.authme.task.MessageTask;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
@ -88,13 +89,13 @@ public class AsynchronousLogin implements Process {
|
|||||||
if (pAuth == null) {
|
if (pAuth == null) {
|
||||||
service.send(player, MessageKey.USER_NOT_REGISTERED);
|
service.send(player, MessageKey.USER_NOT_REGISTERED);
|
||||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||||
LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId().cancel();
|
LimboCache.getInstance().getLimboPlayer(name).getMessageTask().cancel();
|
||||||
String[] msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
String[] msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||||
? service.retrieveMessage(MessageKey.REGISTER_EMAIL_MESSAGE)
|
? service.retrieveMessage(MessageKey.REGISTER_EMAIL_MESSAGE)
|
||||||
: service.retrieveMessage(MessageKey.REGISTER_MESSAGE);
|
: service.retrieveMessage(MessageKey.REGISTER_MESSAGE);
|
||||||
BukkitTask messageTask = service.runTask(
|
BukkitTask messageTask = service.runTask(
|
||||||
new MessageTask(plugin, name, msg, service.getProperty(RegistrationSettings.MESSAGE_INTERVAL)));
|
new MessageTask(plugin, name, msg, service.getProperty(RegistrationSettings.MESSAGE_INTERVAL)));
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(messageTask);
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTask(messageTask);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -128,7 +129,7 @@ public class AsynchronousLogin implements Process {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pAuth.getIp().equals("127.0.0.1") && !pAuth.getIp().equals(ip)) {
|
if ("127.0.0.1".equals(pAuth.getIp()) && !pAuth.getIp().equals(ip)) {
|
||||||
pAuth.setIp(ip);
|
pAuth.setIp(ip);
|
||||||
database.updateIp(pAuth.getNickname(), ip);
|
database.updateIp(pAuth.getNickname(), ip);
|
||||||
}
|
}
|
||||||
@ -181,19 +182,20 @@ public class AsynchronousLogin implements Process {
|
|||||||
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(
|
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(
|
||||||
player, plugin, database, service.getSettings());
|
player, plugin, database, service.getSettings());
|
||||||
if (syncPlayerLogin.getLimbo() != null) {
|
if (syncPlayerLogin.getLimbo() != null) {
|
||||||
if (syncPlayerLogin.getLimbo().getTimeoutTaskId() != null) {
|
if (syncPlayerLogin.getLimbo().getTimeoutTask() != null) {
|
||||||
syncPlayerLogin.getLimbo().getTimeoutTaskId().cancel();
|
syncPlayerLogin.getLimbo().getTimeoutTask().cancel();
|
||||||
}
|
}
|
||||||
if (syncPlayerLogin.getLimbo().getMessageTaskId() != null) {
|
if (syncPlayerLogin.getLimbo().getMessageTask() != null) {
|
||||||
syncPlayerLogin.getLimbo().getMessageTaskId().cancel();
|
syncPlayerLogin.getLimbo().getMessageTask().cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncPlayerLogin);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncPlayerLogin);
|
||||||
} else if (player.isOnline()) {
|
} else if (player.isOnline()) {
|
||||||
if (!Settings.noConsoleSpam)
|
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
||||||
ConsoleLogger.info(realName + " used the wrong password");
|
ConsoleLogger.info(realName + " used the wrong password");
|
||||||
if (Settings.isKickOnWrongPasswordEnabled) {
|
}
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
if (service.getProperty(RestrictionSettings.KICK_ON_WRONG_PASSWORD)) {
|
||||||
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.kickPlayer(service.retrieveSingleMessage(MessageKey.WRONG_PASSWORD));
|
player.kickPlayer(service.retrieveSingleMessage(MessageKey.WRONG_PASSWORD));
|
||||||
|
@ -67,7 +67,7 @@ public class ProcessSyncPlayerLogin implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void restoreOpState() {
|
private void restoreOpState() {
|
||||||
player.setOp(limbo.getOperator());
|
player.setOp(limbo.isOperator());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void packQuitLocation() {
|
private void packQuitLocation() {
|
||||||
|
@ -72,10 +72,10 @@ public class ProcessSynchronousPlayerLogout implements Process {
|
|||||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||||
if (timeOut != 0) {
|
if (timeOut != 0) {
|
||||||
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTask(id);
|
||||||
}
|
}
|
||||||
BukkitTask msgT = service.runTask(new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
BukkitTask msgT = service.runTask(new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTask(msgT);
|
||||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||||
player.getVehicle().eject();
|
player.getVehicle().eject();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class AsynchronousQuit implements Process {
|
|||||||
Utils.addNormal(player, limbo.getGroup());
|
Utils.addNormal(player, limbo.getGroup());
|
||||||
}
|
}
|
||||||
needToChange = true;
|
needToChange = true;
|
||||||
isOp = limbo.getOperator();
|
isOp = limbo.isOperator();
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
}
|
}
|
||||||
if (Settings.isSessionsEnabled && !isKick) {
|
if (Settings.isSessionsEnabled && !isKick) {
|
||||||
|
@ -49,11 +49,11 @@ public class ProcessSyncEmailRegister implements Process {
|
|||||||
if (limbo != null) {
|
if (limbo != null) {
|
||||||
if (time != 0) {
|
if (time != 0) {
|
||||||
BukkitTask id = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), time);
|
BukkitTask id = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), time);
|
||||||
limbo.setTimeoutTaskId(id);
|
limbo.setTimeoutTask(id);
|
||||||
}
|
}
|
||||||
BukkitTask messageTask = service.runTask(new MessageTask(
|
BukkitTask messageTask = service.runTask(new MessageTask(
|
||||||
service.getAuthMe(), name, service.retrieveMessage(MessageKey.LOGIN_MESSAGE), msgInterval));
|
service.getAuthMe(), name, service.retrieveMessage(MessageKey.LOGIN_MESSAGE), msgInterval));
|
||||||
limbo.setMessageTaskId(messageTask);
|
limbo.setMessageTask(messageTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.saveData();
|
player.saveData();
|
||||||
|
@ -67,10 +67,10 @@ public class ProcessSyncPasswordRegister implements Process {
|
|||||||
BukkitTask task;
|
BukkitTask task;
|
||||||
if (delay != 0) {
|
if (delay != 0) {
|
||||||
task = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), delay);
|
task = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), delay);
|
||||||
cache.getLimboPlayer(name).setTimeoutTaskId(task);
|
cache.getLimboPlayer(name).setTimeoutTask(task);
|
||||||
}
|
}
|
||||||
task = service.runTask(new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
task = service.runTask(new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
||||||
cache.getLimboPlayer(name).setMessageTaskId(task);
|
cache.getLimboPlayer(name).setMessageTask(task);
|
||||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||||
player.getVehicle().eject();
|
player.getVehicle().eject();
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,9 @@ public class AsynchronousUnregister implements Process {
|
|||||||
BukkitScheduler scheduler = plugin.getServer().getScheduler();
|
BukkitScheduler scheduler = plugin.getServer().getScheduler();
|
||||||
if (timeOut != 0) {
|
if (timeOut != 0) {
|
||||||
BukkitTask id = scheduler.runTaskLater(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
BukkitTask id = scheduler.runTaskLater(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
||||||
limboPlayer.setTimeoutTaskId(id);
|
limboPlayer.setTimeoutTask(id);
|
||||||
}
|
}
|
||||||
limboPlayer.setMessageTaskId(scheduler.runTask(plugin,
|
limboPlayer.setMessageTask(scheduler.runTask(plugin,
|
||||||
new MessageTask(plugin, name, MessageKey.REGISTER_MESSAGE, interval)));
|
new MessageTask(plugin, name, MessageKey.REGISTER_MESSAGE, interval)));
|
||||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||||
|
@ -49,7 +49,7 @@ public class MessageTask implements Runnable {
|
|||||||
}
|
}
|
||||||
BukkitTask nextTask = plugin.getServer().getScheduler().runTaskLater(plugin, this, interval * 20);
|
BukkitTask nextTask = plugin.getServer().getScheduler().runTaskLater(plugin, this, interval * 20);
|
||||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(nextTask);
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTask(nextTask);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import org.bukkit.Server;
|
|||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the retrieval of common singletons used throughout the application.
|
* Wrapper for the retrieval of common singletons used throughout the application.
|
||||||
@ -48,10 +47,6 @@ public class Wrapper {
|
|||||||
return getAuthMe().getServer();
|
return getAuthMe().getServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Logger getLogger() {
|
|
||||||
return getAuthMe().getLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Messages getMessages() {
|
public Messages getMessages() {
|
||||||
return getAuthMe().getMessages();
|
return getAuthMe().getMessages();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.manager;
|
package fr.xephi.authme.cache;
|
||||||
|
|
||||||
import fr.xephi.authme.cache.CaptchaManager;
|
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.manager;
|
package fr.xephi.authme.cache;
|
||||||
|
|
||||||
import fr.xephi.authme.cache.IpAddressManager;
|
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -7,8 +7,6 @@ import fr.xephi.authme.output.MessageKey;
|
|||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.task.ChangePasswordTask;
|
import fr.xephi.authme.task.ChangePasswordTask;
|
||||||
import fr.xephi.authme.util.WrapperMock;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.command.BlockCommandSender;
|
import org.bukkit.command.BlockCommandSender;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -21,6 +19,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
@ -35,14 +34,10 @@ import static org.mockito.Mockito.when;
|
|||||||
*/
|
*/
|
||||||
public class ChangePasswordCommandTest {
|
public class ChangePasswordCommandTest {
|
||||||
|
|
||||||
private WrapperMock wrapperMock;
|
|
||||||
private PlayerCache cacheMock;
|
|
||||||
private CommandService commandService;
|
private CommandService commandService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpMocks() {
|
public void setUpMocks() {
|
||||||
wrapperMock = WrapperMock.createInstance();
|
|
||||||
cacheMock = wrapperMock.getPlayerCache();
|
|
||||||
commandService = mock(CommandService.class);
|
commandService = mock(CommandService.class);
|
||||||
|
|
||||||
when(commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)).thenReturn(2);
|
when(commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)).thenReturn(2);
|
||||||
@ -62,7 +57,9 @@ public class ChangePasswordCommandTest {
|
|||||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
verify(sender).sendMessage(captor.capture());
|
||||||
|
assertThat(captor.getValue(), containsString("only for players"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -76,7 +73,6 @@ public class ChangePasswordCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(sender, MessageKey.NOT_LOGGED_IN);
|
verify(commandService).send(sender, MessageKey.NOT_LOGGED_IN);
|
||||||
assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -90,7 +86,6 @@ public class ChangePasswordCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
verify(commandService).send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||||
assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -105,7 +100,6 @@ public class ChangePasswordCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
verify(commandService).send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||||
assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -120,7 +114,6 @@ public class ChangePasswordCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
verify(commandService).send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||||
assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -135,7 +128,6 @@ public class ChangePasswordCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
verify(commandService).send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||||
assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -151,7 +143,6 @@ public class ChangePasswordCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
verify(commandService).send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||||
assertThat(wrapperMock.wasMockCalled(Server.class), equalTo(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -175,7 +166,9 @@ public class ChangePasswordCommandTest {
|
|||||||
private Player initPlayerWithName(String name, boolean loggedIn) {
|
private Player initPlayerWithName(String name, boolean loggedIn) {
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
when(player.getName()).thenReturn(name);
|
when(player.getName()).thenReturn(name);
|
||||||
when(cacheMock.isAuthenticated(name)).thenReturn(loggedIn);
|
PlayerCache playerCache = mock(PlayerCache.class);
|
||||||
|
when(playerCache.isAuthenticated(name)).thenReturn(loggedIn);
|
||||||
|
when(commandService.getPlayerCache()).thenReturn(playerCache);
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import org.mockito.Mockito;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class returning mocks for all calls in {@link Wrapper}.
|
* Class returning mocks for all calls in {@link Wrapper}.
|
||||||
@ -36,11 +35,6 @@ public class WrapperMock extends Wrapper {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Logger getLogger() {
|
|
||||||
return getMock(Logger.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Server getServer() {
|
public Server getServer() {
|
||||||
return getMock(Server.class);
|
return getMock(Server.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user