#305 Prepare to remove CommandParts - replace getCount() to List#size()

- Preparations to remove the CommandParts as it's a "decorated list".
This commit is contained in:
ljacqu
2015-12-05 12:06:44 +01:00
parent 9d39fc1127
commit 61875f26fa
13 changed files with 60 additions and 51 deletions
@@ -5,6 +5,8 @@ import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.help.HelpProvider;
import org.bukkit.command.CommandSender;
import java.util.List;
/**
*/
public class HelpCommand extends ExecutableCommand {
@@ -12,10 +14,10 @@ public class HelpCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Check whether quick help should be shown
boolean quickHelp = commandArguments.getCount() == 0;
List<String> arguments = commandArguments.getList();
// Set the proper command arguments for the quick help and show it
if (quickHelp) {
if (arguments.isEmpty()) {
commandArguments = new CommandParts(commandReference.get(0));
HelpProvider.showHelp(sender, commandReference, commandArguments, false, false, false, false, false, true);
} else {
@@ -18,15 +18,14 @@ public class AccountsCommand extends ExecutableCommand {
@Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
List<String> arguments = commandArguments.getList();
// Get the player query
String playerQuery = sender.getName();
if (commandArguments.getCount() >= 1)
if (arguments.size() >= 1)
playerQuery = commandArguments.get(0);
final String playerQueryFinal = playerQuery;
@@ -8,6 +8,8 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class ForceLoginCommand extends ExecutableCommand {
@@ -19,7 +21,8 @@ public class ForceLoginCommand extends ExecutableCommand {
// Get the player query
String playerName = sender.getName();
if (commandArguments.getCount() >= 1)
List<String> arguments = commandArguments.getList();
if (arguments.size() >= 1)
playerName = commandArguments.get(0);
// Command logic
@@ -8,6 +8,8 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender;
import java.util.List;
/**
*/
public class GetEmailCommand extends ExecutableCommand {
@@ -24,8 +26,9 @@ public class GetEmailCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the player name
List<String> arguments = commandArguments.getList();
String playerName = sender.getName();
if (commandArguments.getCount() >= 1)
if (arguments.size() >= 1)
playerName = commandArguments.get(0);
// Get the authenticated user
@@ -7,21 +7,20 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class GetIpCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
List<String> arguments = commandArguments.getList();
// Get the player query
String playerName = sender.getName();
if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0);
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
@SuppressWarnings("deprecation")
Player player = Bukkit.getPlayer(playerName);
if (player == null) {
sender.sendMessage("This player is not actually online");
@@ -9,6 +9,7 @@ import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender;
import java.util.Date;
import java.util.List;
/**
*/
@@ -17,9 +18,8 @@ public class LastLoginCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the player
String playerName = sender.getName();
if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0);
List<String> arguments = commandArguments.getList();
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
// Validate the player
AuthMe plugin = AuthMe.getInstance();
@@ -10,6 +10,8 @@ import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class PurgeLastPositionCommand extends ExecutableCommand {
@@ -25,16 +27,13 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
*/
@Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
List<String> arguments = commandArguments.getList();
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Get the player
String playerName = sender.getName();
if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0);
String playerNameLowerCase = playerName.toLowerCase();
// Purge the last position of the player
@@ -28,9 +28,11 @@ public class SwitchAntiBotCommand extends ExecutableCommand {
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the new state
String newState = null;
if (commandArguments.getCount() == 1) {
List<String> arguments = commandArguments.getList();
if (arguments.size() == 1) {
newState = commandArguments.get(0);
} else if(commandArguments.getCount() == 0) {
} else if (arguments.size() == 0) {
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
return true;
}
@@ -12,39 +12,40 @@ import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class RegisterCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Make sure the sender is a player
if (!(sender instanceof Player)) {
sender.sendMessage("Player Only! Use 'authme register <playername> <password>' instead");
return true;
}
List<String> arguments = commandArguments.getList();
final Wrapper wrapper = Wrapper.getInstance();
final AuthMe plugin = wrapper.getAuthMe();
final Messages m = wrapper.getMessages();
// Make sure the command arguments are valid
final Player player = (Player) sender;
if (commandArguments.getCount() == 0 || (Settings.getEnablePasswordVerifier && commandArguments.getCount() < 2)) {
if (arguments.isEmpty() || (Settings.getEnablePasswordVerifier && arguments.size() < 2)) {
m.send(player, MessageKey.USAGE_REGISTER);
return true;
}
final Management management = plugin.getManagement();
if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
if (Settings.doubleEmailCheck) {
if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) {
m.send(player, MessageKey.USAGE_REGISTER);
return true;
}
if (Settings.doubleEmailCheck && arguments.size() < 2 || !arguments.get(0).equals(arguments.get(1))) {
m.send(player, MessageKey.USAGE_REGISTER);
return true;
}
final String email = commandArguments.get(0);
final String email = arguments.get(0);
if (!Settings.isEmailCorrect(email)) {
m.send(player, MessageKey.INVALID_EMAIL);
return true;
@@ -53,8 +54,8 @@ public class RegisterCommand extends ExecutableCommand {
management.performRegister(player, thePass, email);
return true;
}
if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier) {
if (!commandArguments.get(0).equals(commandArguments.get(1))) {
if (arguments.size() > 1 && Settings.getEnablePasswordVerifier) {
if (!arguments.get(0).equals(commandArguments.get(1))) {
m.send(player, MessageKey.PASSWORD_MATCH_ERROR);
return true;
}