#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:
+16
-19
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user