From b32e5da4c597a7e1e42fa33fe3eff40555164e8e Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 30 Apr 2016 09:30:52 +0200 Subject: [PATCH] #611 Admin unregister forces player to register even for optional registration - Make /authme unregister behave the same way as /unregister for optional registration: user is informed but can continue playing; no teleportation to spawn --- .../authme/UnregisterAdminCommand.java | 59 ++++++++++++------- .../unregister/AsynchronousUnregister.java | 1 - .../fr/xephi/authme/settings/Settings.java | 5 +- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java index 58ccdf0f6..5c8196ddf 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java @@ -7,31 +7,29 @@ import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.output.MessageKey; -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.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.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; import java.util.List; +import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; + /** * Admin command to unregister a player. */ public class UnregisterAdminCommand implements ExecutableCommand { - @Override public void executeCommand(final CommandSender sender, List arguments, CommandService commandService) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - // Get the player name String playerName = arguments.get(0); String playerNameLowerCase = playerName.toLowerCase(); @@ -53,27 +51,44 @@ public class UnregisterAdminCommand implements ExecutableCommand { PlayerCache.getInstance().removePlayer(playerNameLowerCase); Utils.setGroup(target, Utils.GroupType.UNREGISTERED); if (target != null && target.isOnline()) { - Utils.teleportToSpawn(target); - LimboCache.getInstance().addLimboPlayer(target); - int timeOut = Settings.getRegistrationTimeout * 20; - int interval = Settings.getWarnMessageInterval; - BukkitScheduler scheduler = sender.getServer().getScheduler(); - if (timeOut != 0) { - BukkitTask id = scheduler.runTaskLater(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), timeOut); - LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTask(id); - } - LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTask( - scheduler.runTask(plugin, new MessageTask(commandService.getBukkitService(), plugin.getMessages(), - playerNameLowerCase, MessageKey.REGISTER_MESSAGE, interval))); - - if (commandService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { - target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2)); + if (commandService.getProperty(RegistrationSettings.FORCE)) { + applyUnregisteredEffectsAndTasks(target, commandService); } commandService.send(target, MessageKey.UNREGISTERED_SUCCESS); } // Show a status message commandService.send(sender, MessageKey.UNREGISTERED_SUCCESS); - ConsoleLogger.info(playerName + " unregistered"); + ConsoleLogger.info(sender.getName() + " unregistered " + playerName); + } + + /** + * When registration is forced, applies the configured "unregistered effects" to the player as he + * would encounter when joining the server before logging on - reminder task to log in, + * timeout kick, blindness. + * + * @param target the player that was unregistered + * @param service the command service + */ + private void applyUnregisteredEffectsAndTasks(Player target, CommandService service) { + final AuthMe plugin = service.getAuthMe(); + final BukkitService bukkitService = service.getBukkitService(); + final String playerNameLowerCase = target.getName().toLowerCase(); + + Utils.teleportToSpawn(target); + LimboCache.getInstance().addLimboPlayer(target); + 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, playerNameLowerCase, target), timeOut); + LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTask(id); + } + LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTask( + bukkitService.runTask(new MessageTask(service.getBukkitService(), plugin.getMessages(), + playerNameLowerCase, MessageKey.REGISTER_MESSAGE, interval))); + + if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { + target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2)); + } } } diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index 7b2c2a7f5..cd3f41a21 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -97,7 +97,6 @@ public class AsynchronousUnregister implements Process { } service.send(player, MessageKey.UNREGISTERED_SUCCESS); ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); - Utils.teleportToSpawn(player); } else { service.send(player, MessageKey.WRONG_PASSWORD); } diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 129f35b3d..944f675d9 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -39,8 +39,7 @@ public final class Settings { public static String getNickRegex, getUnloggedinGroup, unRegisteredGroup, backupWindowsPath, getRegisteredGroup, rakamakUsers, rakamakUsersIp, defaultWorld, crazyloginFileName; - public static int getWarnMessageInterval, getSessionTimeout, - getRegistrationTimeout, getMaxNickLength, getMinNickLength, + public static int getSessionTimeout, getMaxNickLength, getMinNickLength, getNonActivatedGroup, maxLoginTry, captchaLength, getMaxLoginPerIp; protected static FileConfiguration configFile; @@ -58,10 +57,8 @@ public final class Settings { isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK); isForcedRegistrationEnabled = load(RegistrationSettings.FORCE); isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN); - getWarnMessageInterval = load(RegistrationSettings.MESSAGE_INTERVAL); isSessionsEnabled = load(PluginSettings.SESSIONS_ENABLED); getSessionTimeout = configFile.getInt("settings.sessions.timeout", 10); - getRegistrationTimeout = load(RestrictionSettings.TIMEOUT); getMaxNickLength = configFile.getInt("settings.restrictions.maxNicknameLength", 20); getMinNickLength = configFile.getInt("settings.restrictions.minNicknameLength", 3); getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*");