#723 Create provider for TimeoutTask and MessageTask, remove LimboCache#getInstance
- Create class to handle the creation of "LimboPlayer tasks" (adds encapsulation, reduces duplication) - Move group setting into its own class because (mutual dependency between LimboCache and PermissionsManager otherwise)
This commit is contained in:
parent
67c72dc46d
commit
89bbfc48ee
@ -17,9 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class LimboCache {
|
||||
|
||||
@Deprecated // TODO ljacqu 20160612: Remove this field
|
||||
private volatile static LimboCache singleton;
|
||||
|
||||
private final ConcurrentHashMap<String, LimboPlayer> cache = new ConcurrentHashMap<>();
|
||||
private final JsonCache jsonCache = new JsonCache();
|
||||
|
||||
@ -32,17 +29,6 @@ public class LimboCache {
|
||||
LimboCache(PermissionsManager permissionsManager, SpawnLoader spawnLoader) {
|
||||
this.permissionsManager = permissionsManager;
|
||||
this.spawnLoader = spawnLoader;
|
||||
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LimboCache instance
|
||||
* @deprecated Inject the instance properly instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static LimboCache getInstance() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -8,19 +8,17 @@ import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
@ -51,7 +49,11 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
@Inject
|
||||
private AuthGroupHandler authGroupHandler;
|
||||
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
@ -74,7 +76,7 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
// Unregister the player
|
||||
Player target = bukkitService.getPlayerExact(playerNameLowerCase);
|
||||
playerCache.removePlayer(playerNameLowerCase);
|
||||
permissionsManager.setGroup(target, AuthGroupType.UNREGISTERED);
|
||||
authGroupHandler.setGroup(target, AuthGroupType.UNREGISTERED);
|
||||
if (target != null && target.isOnline()) {
|
||||
if (commandService.getProperty(RegistrationSettings.FORCE)) {
|
||||
applyUnregisteredEffectsAndTasks(target);
|
||||
@ -95,22 +97,17 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
* @param target the player that was unregistered
|
||||
*/
|
||||
private void applyUnregisteredEffectsAndTasks(Player target) {
|
||||
final String playerNameLowerCase = target.getName().toLowerCase();
|
||||
|
||||
// TODO ljacqu 20160612: Remove use of Utils method and behave according to settings
|
||||
Utils.teleportToSpawn(target);
|
||||
limboCache.addLimboPlayer(target);
|
||||
int timeOut = commandService.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
int interval = commandService.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(authMe, playerNameLowerCase, target), timeOut);
|
||||
limboCache.getLimboPlayer(playerNameLowerCase).setTimeoutTask(id);
|
||||
}
|
||||
limboCache.getLimboPlayer(playerNameLowerCase).setMessageTask(
|
||||
bukkitService.runTask(new MessageTask(bukkitService, authMe.getMessages(),
|
||||
playerNameLowerCase, MessageKey.REGISTER_MESSAGE, interval)));
|
||||
|
||||
limboCache.addLimboPlayer(target);
|
||||
limboPlayerTaskManager.registerTimeoutTask(target);
|
||||
limboPlayerTaskManager.registerMessageTask(target.getName(),
|
||||
MessageKey.REGISTER_MESSAGE);
|
||||
|
||||
final int timeout = commandService.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
if (commandService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2));
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
package fr.xephi.authme.permission;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Changes the permission group according to the auth status of the player and the configuration.
|
||||
*/
|
||||
public class AuthGroupHandler {
|
||||
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Inject
|
||||
private NewSetting settings;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
AuthGroupHandler() { }
|
||||
|
||||
/**
|
||||
* Set the group of a player, by its AuthMe group type.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param group The group type.
|
||||
*
|
||||
* @return True if succeeded, false otherwise. False is also returned if groups aren't supported
|
||||
* with the current permissions system.
|
||||
*/
|
||||
public boolean setGroup(Player player, AuthGroupType group) {
|
||||
// Check whether the permissions check is enabled
|
||||
if (!settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure group support is available
|
||||
if (!permissionsManager.hasGroupSupport()) {
|
||||
ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (group) {
|
||||
case UNREGISTERED:
|
||||
// Remove the other group type groups, set the current group
|
||||
permissionsManager.removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return permissionsManager.addGroup(player, Settings.unRegisteredGroup);
|
||||
|
||||
case REGISTERED:
|
||||
// Remove the other group type groups, set the current group
|
||||
permissionsManager.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return permissionsManager.addGroup(player, Settings.getRegisteredGroup);
|
||||
|
||||
case NOT_LOGGED_IN:
|
||||
// Remove the other group type groups, set the current group
|
||||
permissionsManager.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup));
|
||||
return permissionsManager.addGroup(player, Settings.getUnloggedinGroup);
|
||||
|
||||
case LOGGED_IN:
|
||||
// Get the limbo player data
|
||||
LimboPlayer limbo = limboCache.getLimboPlayer(player.getName().toLowerCase());
|
||||
if (limbo == null)
|
||||
return false;
|
||||
|
||||
// Get the players group
|
||||
String realGroup = limbo.getGroup();
|
||||
|
||||
// Remove the other group types groups, set the real group
|
||||
permissionsManager.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return permissionsManager.addGroup(player, realGroup);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
package fr.xephi.authme.permission;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.permission.handlers.BPermissionsHandler;
|
||||
import fr.xephi.authme.permission.handlers.GroupManagerHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionHandler;
|
||||
@ -10,7 +8,7 @@ import fr.xephi.authme.permission.handlers.PermissionsBukkitHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionsExHandler;
|
||||
import fr.xephi.authme.permission.handlers.VaultHandler;
|
||||
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -26,7 +24,6 @@ import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -43,9 +40,6 @@ import java.util.List;
|
||||
*/
|
||||
public class PermissionsManager {
|
||||
|
||||
/**
|
||||
* Server instance.
|
||||
*/
|
||||
private final Server server;
|
||||
private final PluginManager pluginManager;
|
||||
|
||||
@ -317,7 +311,7 @@ public class PermissionsManager {
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
public boolean addGroup(Player player, String groupName) {
|
||||
if(groupName.isEmpty()) {
|
||||
if (StringUtils.isEmpty(groupName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -353,61 +347,6 @@ public class PermissionsManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the group of a player, by its AuthMe group type.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param group The group type.
|
||||
*
|
||||
* @return True if succeeded, false otherwise. False is also returned if groups aren't supported
|
||||
* with the current permissions system.
|
||||
*/
|
||||
public boolean setGroup(Player player, AuthGroupType group) {
|
||||
// Check whether the permissions check is enabled
|
||||
if (!isEnabled() || !Settings.isPermissionCheckEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure group support is available
|
||||
if (!handler.hasGroupSupport()) {
|
||||
ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (group) {
|
||||
case UNREGISTERED:
|
||||
// Remove the other group type groups, set the current group
|
||||
removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return addGroup(player, Settings.unRegisteredGroup);
|
||||
|
||||
case REGISTERED:
|
||||
// Remove the other group type groups, set the current group
|
||||
removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return addGroup(player, Settings.getRegisteredGroup);
|
||||
|
||||
case NOT_LOGGED_IN:
|
||||
// Remove the other group type groups, set the current group
|
||||
removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup));
|
||||
return addGroup(player, Settings.getUnloggedinGroup);
|
||||
|
||||
case LOGGED_IN:
|
||||
// Get the limbo player data
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
||||
if (limbo == null)
|
||||
return false;
|
||||
|
||||
// Get the players group
|
||||
String realGroup = limbo.getGroup();
|
||||
|
||||
// Remove the other group types groups, set the real group
|
||||
removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return addGroup(player, realGroup);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the permission group of a player, if supported.
|
||||
*
|
||||
|
||||
@ -2,6 +2,7 @@ package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
@ -30,6 +31,9 @@ public class ProcessService {
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Inject
|
||||
private AuthGroupHandler authGroupHandler;
|
||||
|
||||
/**
|
||||
* Retrieve a property's value.
|
||||
*
|
||||
@ -104,7 +108,7 @@ public class ProcessService {
|
||||
}
|
||||
|
||||
public boolean setGroup(Player player, AuthGroupType group) {
|
||||
return permissionsManager.setGroup(player, group);
|
||||
return authGroupHandler.setGroup(player, group);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.ProtectInventoryEvent;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
@ -19,8 +18,7 @@ import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
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.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.TeleportationService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
@ -30,7 +28,6 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -67,6 +64,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
AsynchronousJoin() { }
|
||||
|
||||
|
||||
@ -193,17 +193,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
|
||||
});
|
||||
|
||||
// Timeout task
|
||||
if (registrationTimeout > 0) {
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout);
|
||||
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer != null) {
|
||||
limboPlayer.setTimeoutTask(id);
|
||||
}
|
||||
}
|
||||
// Timeout and message task
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
|
||||
// Message task
|
||||
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
MessageKey msg;
|
||||
if (isAuthAvailable) {
|
||||
msg = MessageKey.LOGIN_MESSAGE;
|
||||
@ -212,14 +204,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
? MessageKey.REGISTER_EMAIL_MESSAGE
|
||||
: MessageKey.REGISTER_MESSAGE;
|
||||
}
|
||||
if (msgInterval > 0 && limboCache.getLimboPlayer(name) != null) {
|
||||
BukkitTask msgTask = bukkitService.runTaskLater(new MessageTask(bukkitService, plugin.getMessages(),
|
||||
name, msg, msgInterval), 20L);
|
||||
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer != null) {
|
||||
limboPlayer.setMessageTask(msgTask);
|
||||
}
|
||||
}
|
||||
limboPlayerTaskManager.registerMessageTask(name, msg);
|
||||
}
|
||||
|
||||
private boolean isPlayerUnrestricted(String name) {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.process.login;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.CaptchaManager;
|
||||
import fr.xephi.authme.cache.TempbanManager;
|
||||
@ -25,13 +24,12 @@ import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
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.task.MessageTask;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
@ -40,9 +38,6 @@ import java.util.List;
|
||||
*/
|
||||
public class AsynchronousLogin implements AsynchronousProcess {
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Inject
|
||||
private DataSource database;
|
||||
|
||||
@ -73,8 +68,12 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
@Inject
|
||||
private TempbanManager tempbanManager;
|
||||
|
||||
@Inject
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
AsynchronousLogin() { }
|
||||
|
||||
|
||||
/**
|
||||
* Queries the {@link fr.xephi.authme.cache.CaptchaManager} to
|
||||
* see if a captcha needs to be entered in order to log in.
|
||||
@ -118,16 +117,11 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
if (pAuth == null) {
|
||||
service.send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
|
||||
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer != null) {
|
||||
limboPlayer.getMessageTask().cancel();
|
||||
String[] msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? service.retrieveMessage(MessageKey.REGISTER_EMAIL_MESSAGE)
|
||||
: service.retrieveMessage(MessageKey.REGISTER_MESSAGE);
|
||||
BukkitTask messageTask = bukkitService.runTask(new MessageTask(bukkitService,
|
||||
name, msg, service.getProperty(RegistrationSettings.MESSAGE_INTERVAL)));
|
||||
limboPlayer.setMessageTask(messageTask);
|
||||
}
|
||||
// TODO ljacqu 20160612: Why is the message task being canceled and added again here?
|
||||
MessageKey key = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? MessageKey.REGISTER_EMAIL_MESSAGE
|
||||
: MessageKey.REGISTER_MESSAGE;
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -4,22 +4,18 @@ import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.events.LogoutEvent;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -34,14 +30,15 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
ProcessSynchronousPlayerLogout() { }
|
||||
|
||||
|
||||
private void sendBungeeMessage(Player player) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Forward");
|
||||
@ -64,23 +61,19 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
||||
plugin.sessions.get(name).cancel();
|
||||
plugin.sessions.remove(name);
|
||||
}
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
if (service.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||
plugin.inventoryProtector.sendBlankInventoryPacket(player);
|
||||
}
|
||||
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||
limboCache.getLimboPlayer(name).setTimeoutTask(id);
|
||||
}
|
||||
BukkitTask msgT = bukkitService.runTask(new MessageTask(bukkitService, plugin.getMessages(),
|
||||
name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
limboCache.getLimboPlayer(name).setMessageTask(msgT);
|
||||
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
|
||||
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
player.getVehicle().eject();
|
||||
}
|
||||
final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2));
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
|
||||
}
|
||||
player.setOp(false);
|
||||
restoreSpeedEffect(player);
|
||||
|
||||
@ -1,64 +1,43 @@
|
||||
package fr.xephi.authme.process.register;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
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.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
||||
|
||||
|
||||
public class ProcessSyncEmailRegister implements SynchronousProcess {
|
||||
|
||||
@Inject
|
||||
private ProcessService service;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private AuthMe authMe;
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
ProcessSyncEmailRegister() { }
|
||||
|
||||
|
||||
public void processEmailRegister(Player player) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
LimboPlayer limbo = limboCache.getLimboPlayer(name);
|
||||
if (!Settings.getRegisteredGroup.isEmpty()) {
|
||||
service.setGroup(player, AuthGroupType.REGISTERED);
|
||||
}
|
||||
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
int time = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
|
||||
if (limbo != null) {
|
||||
if (time != 0) {
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(authMe, name, player), time);
|
||||
limbo.setTimeoutTask(id);
|
||||
}
|
||||
BukkitTask messageTask = bukkitService.runTask(new MessageTask(
|
||||
bukkitService, name, service.retrieveMessage(MessageKey.LOGIN_MESSAGE), msgInterval));
|
||||
limbo.setMessageTask(messageTask);
|
||||
}
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
|
||||
|
||||
player.saveData();
|
||||
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
||||
|
||||
@ -18,19 +18,16 @@ import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
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.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN;
|
||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -48,8 +45,12 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
ProcessSyncPasswordRegister() { }
|
||||
|
||||
|
||||
private void sendBungeeMessage(Player player) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Forward");
|
||||
@ -77,17 +78,11 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
||||
private void requestLogin(Player player) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
Utils.teleportToSpawn(player);
|
||||
|
||||
limboCache.updateLimboPlayer(player);
|
||||
int delay = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
BukkitTask task;
|
||||
if (delay != 0) {
|
||||
task = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), delay);
|
||||
limboCache.getLimboPlayer(name).setTimeoutTask(task);
|
||||
}
|
||||
task = bukkitService.runTask(new MessageTask(bukkitService, plugin.getMessages(),
|
||||
name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
limboCache.getLimboPlayer(name).setMessageTask(task);
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
|
||||
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
player.getVehicle().eject();
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
@ -15,14 +14,12 @@ import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -51,8 +48,12 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
AsynchronousUnregister() { }
|
||||
|
||||
|
||||
public void unregister(Player player, String password, boolean force) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
PlayerAuth cachedAuth = playerCache.getAuth(name);
|
||||
@ -61,7 +62,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
service.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
|
||||
if (service.getProperty(RegistrationSettings.FORCE)) {
|
||||
Utils.teleportToSpawn(player);
|
||||
player.saveData();
|
||||
@ -70,17 +71,12 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
||||
}
|
||||
limboCache.addLimboPlayer(player);
|
||||
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), timeOut);
|
||||
limboPlayer.setTimeoutTask(id);
|
||||
}
|
||||
limboPlayer.setMessageTask(bukkitService.runTask(new MessageTask(bukkitService,
|
||||
plugin.getMessages(), name, MessageKey.REGISTER_MESSAGE, interval)));
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
limboPlayerTaskManager.registerMessageTask(name, MessageKey.REGISTER_MESSAGE);
|
||||
|
||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||
return;
|
||||
return; // TODO ljacqu 20160612: Why return here? No blind effect? Player not removed from PlayerCache?
|
||||
}
|
||||
if (!Settings.unRegisteredGroup.isEmpty()) {
|
||||
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
||||
@ -88,8 +84,9 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
playerCache.removePlayer(name);
|
||||
|
||||
// Apply blind effect
|
||||
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2));
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
|
||||
}
|
||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||
|
||||
@ -0,0 +1,94 @@
|
||||
package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
||||
|
||||
/**
|
||||
* Registers tasks associated with a LimboPlayer.
|
||||
*/
|
||||
public class LimboPlayerTaskManager {
|
||||
|
||||
@Inject
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
private NewSetting settings;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
LimboPlayerTaskManager() { }
|
||||
|
||||
|
||||
/**
|
||||
* Registers a {@link MessageTask} for the given player name.
|
||||
*
|
||||
* @param name the name of the player to schedule a repeating message task for
|
||||
* @param key the key of the message to display
|
||||
*/
|
||||
public void registerMessageTask(String name, MessageKey key) {
|
||||
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (interval > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer == null) {
|
||||
ConsoleLogger.info("LimboPlayer for '" + name + "' is not available");
|
||||
} else {
|
||||
cancelTask(limboPlayer.getMessageTask());
|
||||
BukkitTask messageTask = bukkitService.runTask(new MessageTask(name, messages.retrieve(key),
|
||||
interval, bukkitService, limboCache, playerCache));
|
||||
limboPlayer.setMessageTask(messageTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a {@link TimeoutTask} for the given player according to the configuration.
|
||||
*
|
||||
* @param player the player to register a timeout task for
|
||||
*/
|
||||
public void registerTimeoutTask(Player player) {
|
||||
final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
if (timeout > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(player.getName());
|
||||
if (limboPlayer == null) {
|
||||
ConsoleLogger.info("LimboPlayer for '" + player.getName() + "' is not available");
|
||||
} else {
|
||||
cancelTask(limboPlayer.getTimeoutTask());
|
||||
String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
|
||||
BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout);
|
||||
limboPlayer.setTimeoutTask(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe method to cancel a potentially existing task.
|
||||
*
|
||||
* @param task the task to cancel (or null)
|
||||
*/
|
||||
private static void cancelTask(BukkitTask task) {
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,53 +2,51 @@ package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
||||
|
||||
/**
|
||||
* Message shown to a player in a regular interval as long as he is not logged in.
|
||||
*/
|
||||
public class MessageTask implements Runnable {
|
||||
|
||||
private final BukkitService bukkitService;
|
||||
private final String name;
|
||||
private final String[] msg;
|
||||
private final String[] message;
|
||||
private final int interval;
|
||||
private final BukkitService bukkitService;
|
||||
private final LimboCache limboCache;
|
||||
private final PlayerCache playerCache;
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public MessageTask(BukkitService bukkitService, String name, String[] lines, int interval) {
|
||||
this.bukkitService = bukkitService;
|
||||
public MessageTask(String name, String[] lines, int interval, BukkitService bukkitService,
|
||||
LimboCache limboCache, PlayerCache playerCache) {
|
||||
this.name = name;
|
||||
this.msg = lines;
|
||||
this.message = lines;
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public MessageTask(BukkitService bukkitService, Messages messages, String name, MessageKey messageKey,
|
||||
int interval) {
|
||||
this(bukkitService, name, messages.retrieve(messageKey), interval);
|
||||
this.bukkitService = bukkitService;
|
||||
this.limboCache = limboCache;
|
||||
this.playerCache = playerCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
if (playerCache.isAuthenticated(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : bukkitService.getOnlinePlayers()) {
|
||||
if (player.getName().equalsIgnoreCase(name)) {
|
||||
for (String ms : msg) {
|
||||
for (String ms : message) {
|
||||
player.sendMessage(ms);
|
||||
}
|
||||
BukkitTask nextTask = bukkitService.runTaskLater(this, interval * 20);
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTask(nextTask);
|
||||
BukkitTask nextTask = bukkitService.runTaskLater(this, interval * TICKS_PER_SECOND);
|
||||
if (limboCache.hasLimboPlayer(name)) {
|
||||
limboCache.getLimboPlayer(name).setMessageTask(nextTask);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,34 +1,34 @@
|
||||
package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Kicks a player if he hasn't logged in (scheduled to run after a configured delay).
|
||||
*/
|
||||
public class TimeoutTask implements Runnable {
|
||||
|
||||
private final String name;
|
||||
private final Messages m;
|
||||
private final Player player;
|
||||
private final String message;
|
||||
private final PlayerCache playerCache;
|
||||
|
||||
/**
|
||||
* Constructor for TimeoutTask.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
* @param name String
|
||||
* @param player Player
|
||||
* @param player the player to check
|
||||
* @param message the kick message
|
||||
* @param playerCache player cache instance
|
||||
*/
|
||||
public TimeoutTask(AuthMe plugin, String name, Player player) {
|
||||
this.m = plugin.getMessages();
|
||||
this.name = name;
|
||||
public TimeoutTask(Player player, String message, PlayerCache playerCache) {
|
||||
this.message = message;
|
||||
this.player = player;
|
||||
this.playerCache = playerCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
player.kickPlayer(m.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR));
|
||||
if (!playerCache.isAuthenticated(player.getName())) {
|
||||
player.kickPlayer(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,219 @@
|
||||
package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
/**
|
||||
* Test for {@link LimboPlayerTaskManager}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LimboPlayerTaskManagerTest {
|
||||
|
||||
@InjectMocks
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
@Mock
|
||||
private Messages messages;
|
||||
|
||||
@Mock
|
||||
private NewSetting settings;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRegisterMessageTask() {
|
||||
// given
|
||||
String name = "bobby";
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||
BukkitTask bukkiTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(12);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
|
||||
// then
|
||||
verify(limboPlayer).setMessageTask(bukkiTask);
|
||||
verify(messages).retrieve(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotScheduleTaskForMissingLimboPlayer() {
|
||||
// given
|
||||
String name = "ghost";
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(null);
|
||||
MessageKey key = MessageKey.REGISTER_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
|
||||
// then
|
||||
verify(limboCache).getLimboPlayer(name);
|
||||
verifyZeroInteractions(bukkitService);
|
||||
verifyZeroInteractions(messages);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotScheduleTaskForZeroAsInterval() {
|
||||
// given
|
||||
String name = "Tester1";
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||
BukkitTask bukkiTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(0);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(limboPlayer, bukkitService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCancelExistingMessageTask() {
|
||||
// given
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
BukkitTask existingMessageTask = mock(BukkitTask.class);
|
||||
given(limboPlayer.getMessageTask()).willReturn(existingMessageTask);
|
||||
|
||||
String name = "bobby";
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
MessageKey key = MessageKey.REGISTER_EMAIL_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register", "Use /register"});
|
||||
|
||||
BukkitTask bukkiTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTask(any(MessageTask.class))).willReturn(bukkiTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, key);
|
||||
|
||||
// then
|
||||
verify(limboPlayer).setMessageTask(bukkiTask);
|
||||
verify(messages).retrieve(key);
|
||||
verify(existingMessageTask).cancel();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRegisterTimeoutTask() {
|
||||
// given
|
||||
String name = "l33tPlayer";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.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);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
|
||||
// then
|
||||
verify(limboPlayer).setTimeoutTask(bukkitTask);
|
||||
verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L)); // 30 * TICKS_PER_SECOND
|
||||
verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRegisterTimeoutTaskForMissingLimboPlayer() {
|
||||
// given
|
||||
String name = "Phantom_";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(null);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(bukkitService, messages);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRegisterTimeoutTaskForZeroTimeout() {
|
||||
// given
|
||||
String name = "snail";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(0);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(limboPlayer, bukkitService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCancelExistingTimeoutTask() {
|
||||
// given
|
||||
String name = "l33tPlayer";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
BukkitTask existingTask = mock(BukkitTask.class);
|
||||
given(limboPlayer.getTimeoutTask()).willReturn(existingTask);
|
||||
given(limboCache.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);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerTimeoutTask(player);
|
||||
|
||||
// then
|
||||
verify(existingTask).cancel();
|
||||
verify(limboPlayer).setTimeoutTask(bukkitTask);
|
||||
verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); // 18 * TICKS_PER_SECOND
|
||||
verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,6 +11,7 @@ import fr.xephi.authme.initialization.Injection;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
import fr.xephi.authme.security.crypts.EncryptionMethod;
|
||||
import org.bukkit.event.Listener;
|
||||
import tools.utils.ToolTask;
|
||||
import tools.utils.ToolsConstants;
|
||||
|
||||
@ -35,7 +36,7 @@ public class DrawDependency implements ToolTask {
|
||||
private static final String ROOT_PACKAGE = "fr.xephi.authme";
|
||||
|
||||
private static final List<Class<?>> SUPER_TYPES = ImmutableList.of(ExecutableCommand.class,
|
||||
SynchronousProcess.class, AsynchronousProcess.class, EncryptionMethod.class, Converter.class);
|
||||
SynchronousProcess.class, AsynchronousProcess.class, EncryptionMethod.class, Converter.class, Listener.class);
|
||||
|
||||
private boolean mapToSupertype;
|
||||
// Map with the graph's nodes: value is one of the key's dependencies
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user