From 3674ac087ce487ae8880f64fcdeef3ac164cc78b Mon Sep 17 00:00:00 2001 From: ljacqu Date: Fri, 15 Apr 2016 15:17:58 +0200 Subject: [PATCH] Code householding + settings migration - Migrate and remove unused properties in legacy Settings - Add forgotten space in Register command - Fix javadoc errors shown on Jenkins --- .../java/fr/xephi/authme/DataManager.java | 7 +- .../executable/register/RegisterCommand.java | 2 +- .../process/login/AsynchronousLogin.java | 3 +- .../process/login/ProcessSyncPlayerLogin.java | 68 +++++++++---------- .../register/ProcessSyncPasswordRegister.java | 27 +++++--- .../fr/xephi/authme/settings/Settings.java | 30 ++------ src/main/java/fr/xephi/authme/util/Utils.java | 4 ++ 7 files changed, 60 insertions(+), 81 deletions(-) diff --git a/src/main/java/fr/xephi/authme/DataManager.java b/src/main/java/fr/xephi/authme/DataManager.java index a3470ba36..061683fa0 100644 --- a/src/main/java/fr/xephi/authme/DataManager.java +++ b/src/main/java/fr/xephi/authme/DataManager.java @@ -20,11 +20,8 @@ public class DataManager { private final PluginHooks pluginHooks; private final BukkitService bukkitService; - /** - * Constructor for DataManager. - * - * @param plugin The plugin instance - * @param pluginHooks Plugin hooks instance + /* + * Constructor. */ public DataManager(AuthMe plugin, PluginHooks pluginHooks, BukkitService bukkitService) { this.plugin = plugin; diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index efc688b09..d060c56bd 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -58,7 +58,7 @@ public class RegisterCommand extends PlayerCommand { if (commandService.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) { player.sendMessage("Cannot register: no email address is set for the server. " + "Please contact an administrator"); - ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email is set" + ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email is set " + "to send emails from. Please add one in your config at " + EmailSettings.MAIL_ACCOUNT.getPath()); return; } diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 507a67eb7..4368fd836 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -182,8 +182,7 @@ public class AsynchronousLogin implements Process { // task, we schedule it in the end // so that we can be sure, and have not to care if it might be // processed in other order. - ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin( - player, plugin, database, service.getSettings()); + ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(player, plugin, database, service); if (syncPlayerLogin.getLimbo() != null) { if (syncPlayerLogin.getLimbo().getTimeoutTask() != null) { syncPlayerLogin.getLimbo().getTimeoutTask().cancel(); diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index 96429870b..7f037d26e 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -1,22 +1,7 @@ package fr.xephi.authme.process.login; -import fr.xephi.authme.settings.NewSetting; -import fr.xephi.authme.settings.properties.HooksSettings; -import fr.xephi.authme.settings.properties.RegistrationSettings; -import fr.xephi.authme.settings.properties.RestrictionSettings; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; -import org.bukkit.potion.PotionEffectType; - import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; - -import org.apache.commons.lang.reflect.MethodUtils; - import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.backup.JsonCache; @@ -28,14 +13,26 @@ import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RestoreInventoryEvent; import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.process.Process; +import fr.xephi.authme.process.ProcessService; 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.util.Utils; import fr.xephi.authme.util.Utils.GroupType; +import org.apache.commons.lang.reflect.MethodUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.potion.PotionEffectType; -import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; import static fr.xephi.authme.settings.properties.PluginSettings.KEEP_COLLISIONS_DISABLED; +import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; -public class ProcessSyncPlayerLogin implements Runnable { +public class ProcessSyncPlayerLogin implements Process { private final LimboPlayer limbo; private final Player player; @@ -44,7 +41,7 @@ public class ProcessSyncPlayerLogin implements Runnable { private final AuthMe plugin; private final PluginManager pm; private final JsonCache playerCache; - private final NewSetting settings; + private final ProcessService service; private final boolean restoreCollisions = MethodUtils .getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null; @@ -55,10 +52,9 @@ public class ProcessSyncPlayerLogin implements Runnable { * @param player Player * @param plugin AuthMe * @param database DataSource - * @param settings The plugin settings + * @param service The process service */ - public ProcessSyncPlayerLogin(Player player, AuthMe plugin, - DataSource database, NewSetting settings) { + public ProcessSyncPlayerLogin(Player player, AuthMe plugin, DataSource database, ProcessService service) { this.plugin = plugin; this.pm = plugin.getServer().getPluginManager(); this.player = player; @@ -66,7 +62,7 @@ public class ProcessSyncPlayerLogin implements Runnable { this.limbo = LimboCache.getInstance().getLimboPlayer(name); this.auth = database.getAuth(name); this.playerCache = new JsonCache(); - this.settings = settings; + this.service = service; } public LimboPlayer getLimbo() { @@ -99,7 +95,7 @@ public class ProcessSyncPlayerLogin implements Runnable { } private void restoreSpeedEffects() { - if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) && settings.getProperty(RestrictionSettings.REMOVE_SPEED)) { + if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) && service.getProperty(RestrictionSettings.REMOVE_SPEED)) { player.setWalkSpeed(0.2F); player.setFlySpeed(0.1F); } @@ -114,10 +110,10 @@ public class ProcessSyncPlayerLogin implements Runnable { } private void forceCommands() { - for (String command : Settings.forceCommands) { + for (String command : service.getProperty(RegistrationSettings.FORCE_COMMANDS)) { player.performCommand(command.replace("%p", player.getName())); } - for (String command : Settings.forceCommandsAsConsole) { + for (String command : service.getProperty(RegistrationSettings.FORCE_COMMANDS_AS_CONSOLE)) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName())); } } @@ -155,15 +151,15 @@ public class ProcessSyncPlayerLogin implements Runnable { } } - if (restoreCollisions && !settings.getProperty(KEEP_COLLISIONS_DISABLED)) { + if (restoreCollisions && !service.getProperty(KEEP_COLLISIONS_DISABLED)) { player.setCollidable(true); } - if (settings.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) { + if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) { restoreInventory(); } - if (settings.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) { + if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) { plugin.tablistHider.sendTablist(player); } @@ -188,24 +184,24 @@ public class ProcessSyncPlayerLogin implements Runnable { } restoreSpeedEffects(); - if (settings.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { + if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { player.removePotionEffect(PotionEffectType.BLINDNESS); } // The Login event now fires (as intended) after everything is processed Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player)); player.saveData(); - if (settings.getProperty(HooksSettings.BUNGEECORD)) { + if (service.getProperty(HooksSettings.BUNGEECORD)) { sendBungeeMessage(); } // Login is done, display welcome message - if (settings.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) { - if (settings.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) { - for (String s : settings.getWelcomeMessage()) { + if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) { + if (service.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) { + for (String s : service.getSettings().getWelcomeMessage()) { Bukkit.getServer().broadcastMessage(plugin.replaceAllInfo(s, player)); } } else { - for (String s : settings.getWelcomeMessage()) { + for (String s : service.getSettings().getWelcomeMessage()) { player.sendMessage(plugin.replaceAllInfo(s, player)); } } @@ -218,10 +214,10 @@ public class ProcessSyncPlayerLogin implements Runnable { } private void sendTo() { - if (!settings.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) { + if (!service.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); - out.writeUTF(settings.getProperty(HooksSettings.BUNGEECORD_SERVER)); + out.writeUTF(service.getProperty(HooksSettings.BUNGEECORD_SERVER)); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); } } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index 8e839dda9..cf018d18a 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -12,9 +12,11 @@ import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.process.Process; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.EmailSettings; 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.util.Utils; @@ -23,6 +25,9 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitTask; +import static fr.xephi.authme.settings.properties.RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN; +import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; + /** */ public class ProcessSyncPasswordRegister implements Process { @@ -49,10 +54,10 @@ public class ProcessSyncPasswordRegister implements Process { } private void forceCommands() { - for (String command : Settings.forceRegisterCommands) { + for (String command : service.getProperty(RegistrationSettings.FORCE_REGISTER_COMMANDS)) { player.performCommand(command.replace("%p", player.getName())); } - for (String command : Settings.forceRegisterCommandsAsConsole) { + for (String command : service.getProperty(RegistrationSettings.FORCE_REGISTER_COMMANDS_AS_CONSOLE)) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName())); } @@ -62,7 +67,7 @@ public class ProcessSyncPasswordRegister implements Process { Utils.teleportToSpawn(player); LimboCache cache = LimboCache.getInstance(); cache.updateLimboPlayer(player); - int delay = service.getProperty(RestrictionSettings.TIMEOUT) * 20; + int delay = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL); BukkitTask task; if (delay != 0) { @@ -80,15 +85,15 @@ public class ProcessSyncPasswordRegister implements Process { public void run() { LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); if (limbo != null) { - if (Settings.hideTablistBeforeLogin && plugin.tablistHider != null) { + if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) { plugin.tablistHider.sendTablist(player); } Utils.teleportToSpawn(player); - if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) { + if (service.getProperty(HIDE_TABLIST_BEFORE_LOGIN) && plugin.inventoryProtector != null) { RestoreInventoryEvent event = new RestoreInventoryEvent(player); - Bukkit.getPluginManager().callEvent(event); + service.callEvent(event); if (!event.isCancelled()) { plugin.inventoryProtector.sendInventoryPacket(player); } @@ -103,7 +108,7 @@ public class ProcessSyncPasswordRegister implements Process { service.send(player, MessageKey.REGISTER_SUCCESS); - if (!Settings.getmailAccount.isEmpty()) { + if (!service.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) { service.send(player, MessageKey.ADD_EMAIL_MESSAGE); } @@ -115,12 +120,12 @@ public class ProcessSyncPasswordRegister implements Process { plugin.getServer().getPluginManager().callEvent(new LoginEvent(player)); player.saveData(); - if (!Settings.noConsoleSpam) { + if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) { ConsoleLogger.info(player.getName() + " registered " + Utils.getPlayerIp(player)); } // Kick Player after Registration is enabled, kick the player - if (Settings.forceRegKick) { + if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) { player.kickPlayer(service.retrieveSingleMessage(MessageKey.REGISTER_SUCCESS)); return; } @@ -139,12 +144,12 @@ public class ProcessSyncPasswordRegister implements Process { } // Request Login after Registration - if (Settings.forceRegLogin) { + if (service.getProperty(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER)) { forceLogin(player); return; } - if (Settings.bungee) { + if (service.getProperty(HooksSettings.BUNGEECORD)) { sendBungeeMessage(); } diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index ca5ddc3be..2a24628f8 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -3,7 +3,6 @@ package fr.xephi.authme.settings; import fr.xephi.authme.AuthMe; import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.settings.domain.Property; -import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; @@ -26,14 +25,10 @@ public final class Settings { public static final File PLUGIN_FOLDER = Wrapper.getInstance().getDataFolder(); public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache"); public static List allowCommands; - public static List getJoinPermissions; public static List getUnrestrictedName; - public static List getRestrictedIp; public static List getForcedWorlds; public static List countries; public static List countriesBlacklist; - public static List forceCommands; - public static List forceCommandsAsConsole; public static List forceRegisterCommands; public static List forceRegisterCommandsAsConsole; public static HashAlgorithm getPasswordHash; @@ -44,7 +39,6 @@ public final class Settings { isMovementAllowed, isKickNonRegisteredEnabled, isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled, isSaveQuitLocationEnabled, isForceSurvivalModeEnabled, - isKickOnWrongPasswordEnabled, enablePasswordConfirmation, protectInventoryBeforeLogInEnabled, isStopEnabled, reloadSupport, rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, emailRegistration, multiverse, bungee, @@ -52,13 +46,12 @@ public final class Settings { enableProtection, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, removeJoinMessage, removeLeaveMessage, delayJoinMessage, - noTeleport, hideTablistBeforeLogin, denyTabcompleteBeforeLogin, - kickPlayersBeforeStopping, allowAllCommandsIfRegIsOptional, - customAttributes, isRemoveSpeedEnabled, preventOtherCase, keepCollisionsDisabled; + noTeleport, allowAllCommandsIfRegIsOptional, + isRemoveSpeedEnabled, preventOtherCase; public static String getNickRegex, getUnloggedinGroup, unRegisteredGroup, backupWindowsPath, getRegisteredGroup, - rakamakUsers, rakamakUsersIp, getmailAccount, defaultWorld, - spawnPriority, crazyloginFileName, sendPlayerTo; + rakamakUsers, rakamakUsersIp, defaultWorld, + spawnPriority, crazyloginFileName; public static int getWarnMessageInterval, getSessionTimeout, getRegistrationTimeout, getMaxNickLength, getMinNickLength, getMovementRadius, getNonActivatedGroup, @@ -90,12 +83,9 @@ public final class Settings { getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*"); nickPattern = Pattern.compile(getNickRegex); isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS); - getRestrictedIp = load(RestrictionSettings.ALLOWED_RESTRICTED_USERS); isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false); isRemoveSpeedEnabled = configFile.getBoolean("settings.restrictions.removeSpeed", true); getMovementRadius = configFile.getInt("settings.restrictions.allowedMovementRadius", 100); - getJoinPermissions = configFile.getStringList("GroupOptions.Permissions.PermissionsOnJoin"); - isKickOnWrongPasswordEnabled = configFile.getBoolean("settings.restrictions.kickOnWrongPassword", false); isKickNonRegisteredEnabled = configFile.getBoolean("settings.restrictions.kickNonRegistered", false); isForceSingleSessionEnabled = configFile.getBoolean("settings.restrictions.ForceSingleSession", true); isForceSpawnLocOnJoinEnabled = configFile.getBoolean("settings.restrictions.ForceSpawnLocOnJoinEnabled", false); @@ -112,12 +102,7 @@ public final class Settings { } getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", ""); - enablePasswordConfirmation = load(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION); - protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN); - denyTabcompleteBeforeLogin = load(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN); - hideTablistBeforeLogin = load(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN); - backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\"); isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true); reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true); @@ -137,7 +122,6 @@ public final class Settings { rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false); noConsoleSpam = load(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE); removePassword = configFile.getBoolean("Security.console.removePassword", true); - getmailAccount = load(EmailSettings.MAIL_ACCOUNT); displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true); maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5); captchaLength = configFile.getInt("Security.captcha.captchaLength", 5); @@ -153,8 +137,6 @@ public final class Settings { defaultWorld = configFile.getString("Purge.defaultWorld", "world"); enableProtection = configFile.getBoolean("Protection.enableProtection", false); countries = configFile.getStringList("Protection.countries"); - forceCommands = configFile.getStringList("settings.forceCommands"); - forceCommandsAsConsole = configFile.getStringList("settings.forceCommandsAsConsole"); recallEmail = configFile.getBoolean("Email.recallPlayers", false); useWelcomeMessage = load(RegistrationSettings.USE_WELCOME_MESSAGE); countriesBlacklist = configFile.getStringList("Protection.countriesBlacklist"); @@ -171,11 +153,7 @@ public final class Settings { crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db"); forceRegisterCommands = configFile.getStringList("settings.forceRegisterCommands"); forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole"); - customAttributes = configFile.getBoolean("Hooks.customAttributes"); preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false); - kickPlayersBeforeStopping = configFile.getBoolean("Security.stop.kickPlayersBeforeStopping", true); - sendPlayerTo = configFile.getString("Hooks.sendPlayerTo", ""); - keepCollisionsDisabled = load(PluginSettings.KEEP_COLLISIONS_DISABLED); } /** diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 32913707a..905dd7ec4 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -264,6 +264,10 @@ public final class Utils { /** * Returns the IP of the given player. + * + * @param p The player to return the IP address for + * + * @return The player's IP address */ public static String getPlayerIp(Player p) { return p.getAddress().getAddress().getHostAddress();