diff --git a/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java b/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java index e47311bf9..75d6e4aeb 100644 --- a/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java +++ b/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java @@ -39,8 +39,8 @@ public class CommandArgumentDescription { /** * Get the argument label. * - - * @return Argument label. */ + * @return Argument label. + */ public String getLabel() { return this.label; } @@ -57,8 +57,8 @@ public class CommandArgumentDescription { /** * Get the argument description. * - - * @return Argument description. */ + * @return Argument description. + */ public String getDescription() { return description; } @@ -75,8 +75,8 @@ public class CommandArgumentDescription { /** * Check whether the argument is optional. * - - * @return True if the argument is optional, false otherwise. */ + * @return True if the argument is optional, false otherwise. + */ public boolean isOptional() { return optional; } diff --git a/src/main/java/fr/xephi/authme/command/ExecutableCommand.java b/src/main/java/fr/xephi/authme/command/ExecutableCommand.java index 6c3ffe458..e81c705a1 100644 --- a/src/main/java/fr/xephi/authme/command/ExecutableCommand.java +++ b/src/main/java/fr/xephi/authme/command/ExecutableCommand.java @@ -3,6 +3,7 @@ package fr.xephi.authme.command; import org.bukkit.command.CommandSender; /** + * Base class for AuthMe commands that can be executed. */ public abstract class ExecutableCommand { @@ -13,7 +14,7 @@ public abstract class ExecutableCommand { * @param commandReference The command reference. * @param commandArguments The command arguments. * - - * @return True if the command was executed successfully, false otherwise. */ + * @return True if the command was executed successfully, false otherwise. + */ public abstract boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments); } diff --git a/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java b/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java index 1d625d9c7..9fbcd1d9f 100644 --- a/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java @@ -10,31 +10,19 @@ import fr.xephi.authme.command.help.HelpProvider; */ public class HelpCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { // Check whether quick help should be shown boolean quickHelp = commandArguments.getCount() == 0; - // Set the proper command arguments for the quick help - if(quickHelp) + // Set the proper command arguments for the quick help and show it + if (quickHelp) { commandArguments = new CommandParts(commandReference.get(0)); - - // Show the new help - if(quickHelp) HelpProvider.showHelp(sender, commandReference, commandArguments, false, false, false, false, false, true); - else + } else { HelpProvider.showHelp(sender, commandReference, commandArguments); + } - // Return the result return true; } } diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java index a627c9343..0e036b0d4 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java @@ -16,15 +16,6 @@ import fr.xephi.authme.settings.Messages; */ public class AccountsCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { // AuthMe plugin instance diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AuthMeCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AuthMeCommand.java index 541154e70..da67fa82f 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/AuthMeCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/AuthMeCommand.java @@ -11,15 +11,6 @@ import fr.xephi.authme.command.ExecutableCommand; */ public class AuthMeCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { // Show some version info diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java index 170685c01..04b4a0199 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java @@ -19,20 +19,8 @@ import fr.xephi.authme.settings.Settings; */ public class ChangePasswordCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - // Messages instance final Messages m = Messages.getInstance(); @@ -62,6 +50,7 @@ public class ChangePasswordCommand extends ExecutableCommand { } // Set the password + final AuthMe plugin = AuthMe.getInstance(); final String playerNameLowerCase = playerName.toLowerCase(); Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java index 13555552d..a6401b0a3 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java @@ -12,15 +12,6 @@ import fr.xephi.authme.settings.Spawn; */ public class FirstSpawnCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { // Make sure the command executor is a player @@ -33,6 +24,7 @@ public class FirstSpawnCommand extends ExecutableCommand { sender.sendMessage("[AuthMe] Please use that command in game"); } } catch (NullPointerException ex) { + // TODO ljacqu 20151119: Catching NullPointerException is never a good idea. Find what can cause one instead ConsoleLogger.showError(ex.getMessage()); } return true; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java index 19e1e67ca..0a9fd9444 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java @@ -12,15 +12,6 @@ import fr.xephi.authme.command.ExecutableCommand; */ public class ForceLoginCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { // AuthMe plugin instance @@ -33,7 +24,6 @@ public class ForceLoginCommand extends ExecutableCommand { // Command logic try { - @SuppressWarnings("deprecation") Player player = Bukkit.getPlayer(playerName); if (player == null || !player.isOnline()) { sender.sendMessage("Player needs to be online!"); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java index 1ca2a8518..4ee1fe066 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java @@ -23,18 +23,14 @@ public class GetEmailCommand extends ExecutableCommand { * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - AuthMe plugin = AuthMe.getInstance(); - - // Messages instance - Messages m = Messages.getInstance(); - // Get the player name String playerName = sender.getName(); if(commandArguments.getCount() >= 1) playerName = commandArguments.get(0); // Get the authenticated user + AuthMe plugin = AuthMe.getInstance(); + Messages m = Messages.getInstance(); PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase()); if (auth == null) { m.send(sender, "unknown_user"); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java index f3b2700a4..343642c5a 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java @@ -12,15 +12,6 @@ import fr.xephi.authme.command.ExecutableCommand; */ public class GetIpCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { // AuthMe plugin instance @@ -31,7 +22,6 @@ public class GetIpCommand extends ExecutableCommand { if(commandArguments.getCount() >= 1) playerName = commandArguments.get(0); - @SuppressWarnings("deprecation") Player player = Bukkit.getPlayer(playerName); if (player == null) { sender.sendMessage("This player is not actually online"); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java index 58237ef80..b2c4c70f8 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java @@ -14,29 +14,17 @@ import fr.xephi.authme.settings.Messages; */ public class LastLoginCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - AuthMe plugin = AuthMe.getInstance(); - - // Messages instance - Messages m = Messages.getInstance(); - // Get the player String playerName = sender.getName(); if(commandArguments.getCount() >= 1) playerName = commandArguments.get(0); // Validate the player + AuthMe plugin = AuthMe.getInstance(); + Messages m = Messages.getInstance(); + PlayerAuth auth; try { auth = plugin.database.getAuth(playerName.toLowerCase()); diff --git a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java index dc258362b..9b6956b25 100644 --- a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java @@ -15,21 +15,8 @@ import fr.xephi.authme.task.ChangePasswordTask; */ public class ChangePasswordCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - - // Messages instance final Messages m = Messages.getInstance(); // Get the passwords @@ -71,6 +58,7 @@ public class ChangePasswordCommand extends ExecutableCommand { } // Set the password + final AuthMe plugin = AuthMe.getInstance(); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, playerPass, playerPassVerify)); return true; } diff --git a/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java index 34d6bba47..68f5e54b1 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/AddEmailCommand.java @@ -12,22 +12,8 @@ import fr.xephi.authme.settings.Messages; */ public class AddEmailCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - - // Messages instance - final Messages m = Messages.getInstance(); - // Get the parameter values String playerMail = commandArguments.get(0); String playerMailVerify = commandArguments.get(1); @@ -37,11 +23,9 @@ public class AddEmailCommand extends ExecutableCommand { return true; } - // Get the player instance and name + // Get the player and perform email addition + final AuthMe plugin = AuthMe.getInstance(); final Player player = (Player) sender; - final String playerName = player.getName().toLowerCase(); - - // Command logic plugin.management.performAddEmail(player, playerMail, playerMailVerify); return true; } diff --git a/src/main/java/fr/xephi/authme/command/executable/email/ChangeEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/ChangeEmailCommand.java index 03a3c156b..d295512e3 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/ChangeEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/ChangeEmailCommand.java @@ -6,28 +6,13 @@ import org.bukkit.entity.Player; import fr.xephi.authme.AuthMe; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.settings.Messages; /** */ public class ChangeEmailCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - - // Messages instance - final Messages m = Messages.getInstance(); - // Get the parameter values String playerMailOld = commandArguments.get(0); String playerMailNew = commandArguments.get(1); @@ -37,11 +22,9 @@ public class ChangeEmailCommand extends ExecutableCommand { return true; } - // Get the player instance and name + // Get the player instance and execute action + final AuthMe plugin = AuthMe.getInstance(); final Player player = (Player) sender; - final String playerName = player.getName(); - - // Command logic plugin.management.performChangeEmail(player, playerMailOld, playerMailNew); return true; } diff --git a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java index 748fed46f..44f007a95 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java @@ -20,23 +20,8 @@ import fr.xephi.authme.settings.Settings; */ public class RecoverEmailCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - - // Messages instance - final Messages m = Messages.getInstance(); - // Get the parameter values String playerMail = commandArguments.get(0); @@ -50,6 +35,9 @@ public class RecoverEmailCommand extends ExecutableCommand { final String playerName = player.getName(); // Command logic + final AuthMe plugin = AuthMe.getInstance(); + final Messages m = Messages.getInstance(); + if (plugin.mail == null) { m.send(player, "error"); return true; diff --git a/src/main/java/fr/xephi/authme/command/executable/login/LoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/login/LoginCommand.java index d6b441642..e9b80cdfc 100644 --- a/src/main/java/fr/xephi/authme/command/executable/login/LoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/login/LoginCommand.java @@ -11,32 +11,19 @@ import fr.xephi.authme.command.ExecutableCommand; */ public class LoginCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - // Make sure the current command executor is a player - if(!(sender instanceof Player)) { + if (!(sender instanceof Player)) { return true; } - // Get the player instance + // Get the necessary objects + final AuthMe plugin = AuthMe.getInstance(); final Player player = (Player) sender; + final String playerPass = commandArguments.get(0); - // Get the password - String playerPass = commandArguments.get(0); - - // Login the player + // Log the player in plugin.management.performLogin(player, playerPass, false); return true; } diff --git a/src/main/java/fr/xephi/authme/command/executable/logout/LogoutCommand.java b/src/main/java/fr/xephi/authme/command/executable/logout/LogoutCommand.java index fcc86ce2e..e2e97806e 100644 --- a/src/main/java/fr/xephi/authme/command/executable/logout/LogoutCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/logout/LogoutCommand.java @@ -11,26 +11,15 @@ import fr.xephi.authme.command.ExecutableCommand; */ public class LogoutCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - // Make sure the current command executor is a player - if(!(sender instanceof Player)) { + if (!(sender instanceof Player)) { return true; } // Get the player instance + final AuthMe plugin = AuthMe.getInstance(); final Player player = (Player) sender; // Logout the player 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 7484793d2..3c7f07ee4 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 @@ -14,21 +14,8 @@ import fr.xephi.authme.settings.Settings; */ public class RegisterCommand extends ExecutableCommand { - /** - * Execute the command. - * - * @param sender The command sender. - * @param commandReference The command reference. - * @param commandArguments The command arguments. - * - - * @return True if the command was executed successfully, false otherwise. */ @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); - - // Messages instance final Messages m = Messages.getInstance(); // Make sure the sender is a player @@ -44,6 +31,7 @@ public class RegisterCommand extends ExecutableCommand { return true; } + final AuthMe plugin = AuthMe.getInstance(); if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { if (Settings.doubleEmailCheck) { if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) {