Change ExecutableCommand interface (wip – doesn't compile)

- Change interface to use (CommandSender, List<String> arguments)
- Use CommandArgumentDescription#name instead of "label" (to prevent confusion between command labels and arguments)
- Simplify command difference computation in CommandHandler (no longer consider argument difference)
This commit is contained in:
ljacqu 2015-12-12 11:39:19 +01:00
parent 2f153fb85c
commit eecad80748
39 changed files with 249 additions and 517 deletions

View File

@ -6,9 +6,9 @@ package fr.xephi.authme.command;
public class CommandArgumentDescription {
/**
* Argument label (one-word description of the argument).
* Argument name (one-word description of the argument).
*/
private final String label;
private final String name;
/**
* Argument description.
*/
@ -21,23 +21,23 @@ public class CommandArgumentDescription {
/**
* Constructor.
*
* @param label The argument label.
* @param name The argument name.
* @param description The argument description.
* @param isOptional True if the argument is optional, false otherwise.
*/
public CommandArgumentDescription(String label, String description, boolean isOptional) {
this.label = label;
public CommandArgumentDescription(String name, String description, boolean isOptional) {
this.name = name;
this.description = description;
this.isOptional = isOptional;
}
/**
* Get the argument label.
* Get the argument name.
*
* @return Argument label.
* @return Argument name.
*/
public String getLabel() {
return this.label;
public String getName() {
return this.name;
}
/**

View File

@ -2,15 +2,10 @@ package fr.xephi.authme.command;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static com.google.common.base.Objects.firstNonNull;

View File

@ -6,7 +6,6 @@ import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
@ -152,11 +151,11 @@ public class CommandHandler {
}
// Prefer labels: /register help goes to "Help command", not "Register command" with argument 'help'
List<String> remaining = parts.subList(1, parts.size());
CommandDescription childCommand = getSuitableChild(base, remaining);
List<String> remainingParts = parts.subList(1, parts.size());
CommandDescription childCommand = getSuitableChild(base, remainingParts);
if (childCommand != null) {
return new FoundCommandResult(childCommand, parts.subList(2, parts.size()), parts.subList(0, 2));
} else if (isSuitableArgumentCount(base, remaining.size())) {
} else if (hasSuitableArgumentCount(base, remainingParts.size())) {
return new FoundCommandResult(base, parts.subList(1, parts.size()), parts.subList(0, 1));
}
@ -165,22 +164,17 @@ public class CommandHandler {
private FoundCommandResult getCommandWithSmallestDifference(CommandDescription base, List<String> parts) {
final String label = parts.get(0);
final int argumentCount = parts.size() - 1;
double minDifference = Double.POSITIVE_INFINITY;
CommandDescription closestCommand = null;
for (CommandDescription child : base.getChildren()) {
double labelDifference = getLabelDifference(child, label);
double argumentDifference = getArgumentCountDifference(child, argumentCount);
// Weigh argument difference less
double difference = labelDifference + argumentDifference / 2;
double difference = getLabelDifference(child, label);
if (difference < minDifference) {
minDifference = difference;
closestCommand = child;
}
}
// TODO: Return the full list of labels and arguments
// TODO: Also compare the base command and suggest it if it's the most similar
return new FoundCommandResult(
closestCommand, null, null, minDifference, FoundCommandResult.ResultStatus.UNKNOWN_LABEL);
}
@ -195,7 +189,16 @@ public class CommandHandler {
return null;
}
// Is the given command a suitable match for the given parts? parts is for example [changepassword, newpw, newpw]
/**
* Return a child from a base command if the label and the argument count match.
*
* @param baseCommand The base command whose children should be checked
* @param parts The command parts received from the invocation; the first item is the potential label and any
* other items are command arguments. The first initial part that led to the base command should not
* be present.
*
* @return A command if there was a complete match (including proper argument count), null otherwise
*/
private CommandDescription getSuitableChild(CommandDescription baseCommand, List<String> parts) {
if (CollectionUtils.isEmpty(parts)) {
return null;
@ -205,26 +208,20 @@ public class CommandHandler {
final int argumentCount = parts.size() - 1;
for (CommandDescription child : baseCommand.getChildren()) {
if (child.hasLabel(label) && isSuitableArgumentCount(child, argumentCount)) {
if (child.hasLabel(label) && hasSuitableArgumentCount(child, argumentCount)) {
return child;
}
}
return null;
}
private static boolean isSuitableArgumentCount(CommandDescription command, int argumentCount) {
private static boolean hasSuitableArgumentCount(CommandDescription command, int argumentCount) {
int minArgs = CommandUtils.getMinNumberOfArguments(command);
int maxArgs = CommandUtils.getMaxNumberOfArguments(command);
return argumentCount >= minArgs && argumentCount <= maxArgs;
}
private static int getArgumentCountDifference(CommandDescription commandDescription, int givenArgumentsCount) {
return Math.min(
Math.abs(givenArgumentsCount - CommandUtils.getMinNumberOfArguments(commandDescription)),
Math.abs(givenArgumentsCount - CommandUtils.getMaxNumberOfArguments(commandDescription)));
}
private static double getLabelDifference(CommandDescription command, String givenLabel) {
double minDifference = Double.POSITIVE_INFINITY;
for (String commandLabel : command.getLabels()) {

View File

@ -1,11 +1,7 @@
package fr.xephi.authme.command;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PermissionNode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
@ -42,38 +38,6 @@ public class CommandPermissions {
return this.permissionNodes;
}
/**
* Check whether this command requires any permission to be executed. This is based on the getPermission() method.
*
* @param sender CommandSender
*
* @return True if this command requires any permission to be executed by a player.
*/
public boolean hasPermission(CommandSender sender) {
// Make sure any permission node is set
if (permissionNodes.isEmpty()) {
return true;
}
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
// Make sure the command sender is a player, if not use the default
if (!(sender instanceof Player)) {
return defaultPermission;
}
// Get the player instance
Player player = (Player) sender;
// Get the permissions manager, and make sure it's instance is valid
if (permissionsManager == null)
return false;
// Check whether the player has permission, return the result
return permissionsManager.hasPermission(player, this.permissionNodes, defaultPermission);
}
/**
* Get the default permission if the permission nodes couldn't be used.
@ -85,24 +49,4 @@ public class CommandPermissions {
}
/**
* Get the default permission for a specified command sender.
*
* @param sender The command sender to get the default permission for.
*
* @return True if the command sender has permission by default, false otherwise.
*/
public boolean getDefaultPermissionCommandSender(CommandSender sender) {
switch (getDefaultPermission()) {
case ALLOWED:
return true;
case OP_ONLY:
return sender.isOp();
case NOT_ALLOWED:
default:
return false;
}
}
}

View File

@ -2,19 +2,18 @@ package fr.xephi.authme.command;
import org.bukkit.command.CommandSender;
import java.util.List;
/**
* Base class for AuthMe commands that can be executed.
*/
public abstract class ExecutableCommand {
/**
* Execute the command.
* Execute the command with the given arguments.
*
* @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.
* @param sender The command sender.
* @param arguments The arguments.
*/
public abstract boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments);
public abstract void executeCommand(CommandSender sender, List<String> arguments);
}

View File

@ -3,7 +3,6 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@ -12,21 +11,17 @@ import org.bukkit.command.CommandSender;
import java.util.List;
/**
*/
public class AccountsCommand extends ExecutableCommand {
@Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(final CommandSender sender, List<String> arguments) {
final AuthMe plugin = AuthMe.getInstance();
final Messages m = plugin.getMessages();
List<String> arguments = commandArguments.getList();
// Get the player query
String playerQuery = sender.getName();
if (arguments.size() >= 1)
playerQuery = commandArguments.get(0);
playerQuery = arguments.get(0);
final String playerQueryFinal = playerQuery;
// Command logic
@ -70,7 +65,7 @@ public class AccountsCommand extends ExecutableCommand {
sender.sendMessage(message.toString());
}
});
return true;
return;
} else {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
@ -108,7 +103,6 @@ public class AccountsCommand extends ExecutableCommand {
sender.sendMessage(message.toString());
}
});
return true;
}
}
}

View File

@ -1,21 +1,20 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
/**
*/
import java.util.List;
public class AuthMeCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Show some version info
// FIXME replace use of commandReference
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.getPluginName() + " v" + AuthMe.getPluginVersion() + " b" + AuthMe.getPluginBuildNumber()+ "! " + ChatColor.RED + "<3");
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " help" + ChatColor.YELLOW + " to view help.");
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " about" + ChatColor.YELLOW + " to view about.");
return true;
}
}

View File

@ -4,16 +4,16 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.security.NoSuchAlgorithmException;
import java.util.List;
/**
* Admin command for changing a player's password.
@ -21,14 +21,13 @@ import java.security.NoSuchAlgorithmException;
public class ChangePasswordAdminCommand extends ExecutableCommand {
@Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(final CommandSender sender, List<String> arguments) {
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
// Get the player and password
String playerName = commandArguments.get(0);
final String playerPass = commandArguments.get(1);
String playerName = arguments.get(0);
final String playerPass = arguments.get(1);
// Validate the password
String playerPassLowerCase = playerPass.toLowerCase();
@ -38,20 +37,20 @@ public class ChangePasswordAdminCommand extends ExecutableCommand {
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
m.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
return true;
return;
}
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
return true;
return;
}
if (playerPassLowerCase.length() < Settings.getPasswordMinLen
|| playerPassLowerCase.length() > Settings.passwordMaxLength) {
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
return true;
return;
}
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
return true;
return;
}
// Set the password
final String playerNameLowerCase = playerName.toLowerCase();
@ -90,6 +89,5 @@ public class ChangePasswordAdminCommand extends ExecutableCommand {
}
});
return true;
}
}

View File

@ -1,18 +1,17 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class FirstSpawnCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the command executor is a player
try {
if (sender instanceof Player) {
@ -26,6 +25,5 @@ public class FirstSpawnCommand extends ExecutableCommand {
// TODO ljacqu 20151119: Catching NullPointerException is never a good idea. Find what can cause one instead
ConsoleLogger.showError(ex.getMessage());
}
return true;
}
}

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.permission.PlayerPermission;
import org.bukkit.Bukkit;
@ -15,34 +14,32 @@ import java.util.List;
public class ForceLoginCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Get the player query
String playerName = sender.getName();
List<String> arguments = commandArguments.getList();
if (arguments.size() >= 1)
playerName = commandArguments.get(0);
if (arguments.size() >= 1) {
playerName = arguments.get(0);
}
// Command logic
try {
@SuppressWarnings("deprecation")
// TODO ljacqu 20151212: Retrieve player via Utils method instead
Player player = Bukkit.getPlayer(playerName);
if (player == null || !player.isOnline()) {
sender.sendMessage("Player needs to be online!");
return true;
return;
}
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
sender.sendMessage("You cannot force login for the player " + playerName + "!");
return true;
return;
}
plugin.getManagement().performLogin(player, "dontneed", true);
sender.sendMessage("Force Login for " + playerName + " performed!");
} catch (Exception e) {
sender.sendMessage("An error occurred while trying to get that player!");
}
return true;
}
}

View File

@ -2,7 +2,6 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@ -10,26 +9,11 @@ import org.bukkit.command.CommandSender;
import java.util.List;
/**
*/
public class GetEmailCommand 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) {
// Get the player name
List<String> arguments = commandArguments.getList();
String playerName = sender.getName();
if (arguments.size() >= 1)
playerName = commandArguments.get(0);
public void executeCommand(CommandSender sender, List<String> arguments) {
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Get the authenticated user
AuthMe plugin = AuthMe.getInstance();
@ -37,11 +21,10 @@ public class GetEmailCommand extends ExecutableCommand {
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER);
return true;
return;
}
// Show the email address
sender.sendMessage("[AuthMe] " + playerName + "'s email: " + auth.getEmail());
return true;
}
}

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -9,25 +8,25 @@ import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class GetIpCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
final AuthMe plugin = AuthMe.getInstance();
List<String> arguments = commandArguments.getList();
// Get the player query
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
// TODO ljacqu 20151212: Use the Utils function instead
Player player = Bukkit.getPlayer(playerName);
if (player == null) {
sender.sendMessage("This player is not actually online");
return true;
sender.sendMessage("The player is not online");
return;
}
sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort());
// TODO ljacqu 20151212: Revise the messages (actual IP vs. real IP...?)
sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress()
+ ":" + player.getAddress().getPort());
sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player));
return true;
}
}

View File

@ -2,7 +2,6 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@ -16,9 +15,8 @@ import java.util.List;
public class LastLoginCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Get the player
List<String> arguments = commandArguments.getList();
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
// Validate the player
@ -30,11 +28,11 @@ public class LastLoginCommand extends ExecutableCommand {
auth = plugin.database.getAuth(playerName.toLowerCase());
} catch (NullPointerException e) {
m.send(sender, MessageKey.UNKNOWN_USER);
return true;
return;
}
if (auth == null) {
m.send(sender, MessageKey.USER_NOT_REGISTERED);
return true;
return;
}
// Get the last login date
@ -45,7 +43,8 @@ public class LastLoginCommand extends ExecutableCommand {
final long diff = System.currentTimeMillis() - lastLogin;
// Build the message
final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs.";
final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours "
+ (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs.";
// Get the player's last IP
String lastIP = auth.getIp();
@ -54,6 +53,5 @@ public class LastLoginCommand extends ExecutableCommand {
sender.sendMessage("[AuthMe] " + playerName + " last login : " + date.toString());
sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " is unlogged since " + msg);
sender.sendMessage("[AuthMe] Last Player's IP: " + lastIP);
return true;
}
}

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Settings;
import org.bukkit.OfflinePlayer;
@ -10,21 +9,10 @@ import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
/**
*/
public class PurgeBannedPlayersCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
@ -47,6 +35,5 @@ public class PurgeBannedPlayersCommand extends ExecutableCommand {
// Show a status message
sender.sendMessage("[AuthMe] Database has been purged correctly");
return true;
}
}

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Settings;
import org.bukkit.ChatColor;
@ -10,40 +9,29 @@ import org.bukkit.command.CommandSender;
import java.util.Calendar;
import java.util.List;
/**
*/
public class PurgeCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// AuthMe plugin instance
AuthMe plugin = AuthMe.getInstance();
// Get the days parameter
String daysStr = commandArguments.get(0);
String daysStr = arguments.get(0);
// Convert the days string to an integer value, and make sure it's valid
int days;
try {
days = Integer.valueOf(daysStr);
} catch (Exception ex) {
days = Integer.parseInt(daysStr);
} catch (NumberFormatException ex) {
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
return true;
return;
}
// Validate the value
if (days < 30) {
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
return true;
return;
}
// Create a calender instance to determine the date
@ -69,6 +57,5 @@ public class PurgeCommand extends ExecutableCommand {
// Show a status message
sender.sendMessage(ChatColor.GREEN + "[AuthMe] Database has been purged correctly");
return true;
}
}

View File

@ -3,7 +3,6 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@ -12,25 +11,13 @@ import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class PurgeLastPositionCommand 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) {
public void executeCommand(final CommandSender sender, List<String> arguments) {
final AuthMe plugin = AuthMe.getInstance();
final Messages m = plugin.getMessages();
List<String> arguments = commandArguments.getList();
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Get the player
@ -42,7 +29,7 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase);
if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER);
return true;
return;
}
// Set the last position
@ -61,6 +48,5 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
if (sender instanceof Player)
sender.sendMessage("An error occurred while trying to reset location or player do not exist, please see logs");
}
return true;
}
}

View File

@ -5,9 +5,9 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

View File

@ -1,10 +1,7 @@
package fr.xephi.authme.command.executable.authme;
//import org.bukkit.ChatColor;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@ -12,21 +9,12 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Profiler;
import org.bukkit.command.CommandSender;
/**
*/
import java.util.List;
public class ReloadCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Profile the reload process
Profiler p = new Profiler(true);
@ -48,7 +36,6 @@ public class ReloadCommand extends ExecutableCommand {
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
ConsoleLogger.writeStackTrace(e);
plugin.stopOrUnload();
return false;
}
// Show a status message
@ -57,6 +44,5 @@ public class ReloadCommand extends ExecutableCommand {
// AuthMeReloaded reloaded, show a status message
// sender.sendMessage(ChatColor.GREEN + "AuthMeReloaded has been reloaded successfully, took " + p.getTimeFormatted() + "!");
return true;
}
}

View File

@ -3,28 +3,18 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
/**
*/
import java.util.List;
public class SetEmailCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// AuthMe plugin instance
AuthMe plugin = AuthMe.getInstance();
@ -32,27 +22,27 @@ public class SetEmailCommand extends ExecutableCommand {
Messages m = plugin.getMessages();
// Get the player name and email address
String playerName = commandArguments.get(0);
String playerEmail = commandArguments.get(1);
String playerName = arguments.get(0);
String playerEmail = arguments.get(1);
// Validate the email address
if (!Settings.isEmailCorrect(playerEmail)) {
m.send(sender, MessageKey.INVALID_EMAIL);
return true;
return;
}
// Validate the user
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER);
return true;
return;
}
// Set the email address
auth.setEmail(playerEmail);
if (!plugin.database.updateEmail(auth)) {
m.send(sender, MessageKey.ERROR);
return true;
return;
}
// Update the player cache
@ -61,6 +51,6 @@ public class SetEmailCommand extends ExecutableCommand {
// Show a status message
m.send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
return true;
return;
}
}

View File

@ -1,27 +1,17 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class SetFirstSpawnCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
try {
if (sender instanceof Player) {
if (Spawn.getInstance().setFirstSpawn(((Player) sender).getLocation()))
@ -33,6 +23,5 @@ public class SetFirstSpawnCommand extends ExecutableCommand {
} catch (NullPointerException ex) {
ConsoleLogger.showError(ex.getMessage());
}
return true;
}
}

View File

@ -1,27 +1,17 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class SetSpawnCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the command executor is a player
try {
if (sender instanceof Player) {
@ -36,6 +26,5 @@ public class SetSpawnCommand extends ExecutableCommand {
} catch (NullPointerException ex) {
ConsoleLogger.showError(ex.getMessage());
}
return true;
}
}

View File

@ -1,27 +1,17 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class SpawnCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the command executor is a player
try {
if (sender instanceof Player) {
@ -29,11 +19,10 @@ public class SpawnCommand extends ExecutableCommand {
((Player) sender).teleport(Spawn.getInstance().getSpawn());
else sender.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
} else {
sender.sendMessage("[AuthMe] Please use that command in game");
sender.sendMessage("[AuthMe] Please use the command in game");
}
} catch (NullPointerException ex) {
ConsoleLogger.showError(ex.getMessage());
}
return true;
}
}

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AntiBot;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.CommandUtils;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.help.HelpProvider;
@ -11,56 +10,44 @@ import org.bukkit.command.CommandSender;
import java.util.List;
/**
*/
public class SwitchAntiBotCommand 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) {
public void executeCommand(final CommandSender sender, List<String> arguments) {
// Get the new state
String newState = null;
List<String> arguments = commandArguments.getList();
if (arguments.size() == 1) {
newState = commandArguments.get(0);
newState = arguments.get(0);
} else if (arguments.size() == 0) {
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
return true;
return;
}
// Enable the mod
if ("ON".equalsIgnoreCase(newState)) {
AntiBot.overrideAntiBotStatus(true);
sender.sendMessage("[AuthMe] AntiBot Manual Override: enabled!");
return true;
return;
}
// Disable the mod
if ("OFF".equalsIgnoreCase(newState)) {
AntiBot.overrideAntiBotStatus(false);
sender.sendMessage("[AuthMe] AntiBotMod Manual Override: disabled!");
return true;
return;
}
// Show the invalid arguments warning
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");
// Show the command argument help
// FIXME fix help reference
HelpProvider.showHelp(sender, commandReference, commandReference, true, false, true, false, false, false);
// Show the command to use for detailed help
List<String> helpCommandReference = CollectionUtils.getRange(commandReference.getList(), 1);
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/"
+ commandReference.get(0) + " help " + CommandUtils.labelsToString(helpCommandReference));
return true;
}
}

View File

@ -4,7 +4,6 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@ -20,22 +19,16 @@ import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import java.util.List;
/**
* Admin command to unregister a player.
*/
public class UnregisterAdminCommand 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) {
public void executeCommand(final CommandSender sender, List<String> arguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
@ -43,19 +36,19 @@ public class UnregisterAdminCommand extends ExecutableCommand {
final Messages m = plugin.getMessages();
// Get the player name
String playerName = commandArguments.get(0);
String playerName = arguments.get(0);
String playerNameLowerCase = playerName.toLowerCase();
// Make sure the user is valid
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
m.send(sender, MessageKey.UNKNOWN_USER);
return true;
return;
}
// Remove the player
if (!plugin.database.removeAuth(playerNameLowerCase)) {
m.send(sender, MessageKey.ERROR);
return true;
return;
}
// Unregister the player
@ -88,6 +81,5 @@ public class UnregisterAdminCommand extends ExecutableCommand {
// Show a status message
m.send(sender, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(playerName + " unregistered");
return true;
}
}

View File

@ -1,30 +1,19 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class VersionCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Show some version info
sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader.toUpperCase() + " ABOUT ]==========");
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName() + " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
@ -37,7 +26,6 @@ public class VersionCommand extends ExecutableCommand {
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE + "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0" + ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE + "Copyright (c) Xephi 2015. All rights reserved.");
return true;
}
/**

View File

@ -2,25 +2,24 @@ package fr.xephi.authme.command.executable.captcha;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class CaptchaCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
// Get the player instance and name
@ -28,7 +27,7 @@ public class CaptchaCommand extends ExecutableCommand {
final String playerNameLowerCase = player.getName().toLowerCase();
// Get the parameter values
String captcha = commandArguments.get(0);
String captcha = arguments.get(0);
// AuthMe plugin instance
final Wrapper wrapper = Wrapper.getInstance();
@ -40,18 +39,18 @@ public class CaptchaCommand extends ExecutableCommand {
// Command logic
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return true;
return;
}
if (!Settings.useCaptcha) {
m.send(player, MessageKey.USAGE_LOGIN);
return true;
return;
}
if (!plugin.cap.containsKey(playerNameLowerCase)) {
m.send(player, MessageKey.USAGE_LOGIN);
return true;
return;
}
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
@ -61,7 +60,7 @@ public class CaptchaCommand extends ExecutableCommand {
for (String s : m.retrieve(MessageKey.CAPTCHA_WRONG_ERROR)) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
}
return true;
return;
}
plugin.captcha.remove(playerNameLowerCase);
@ -70,6 +69,5 @@ public class CaptchaCommand extends ExecutableCommand {
// Show a status message
m.send(player, MessageKey.CAPTCHA_SUCCESS);
m.send(player, MessageKey.LOGIN_MESSAGE);
return true;
}
}

View File

@ -2,7 +2,6 @@ package fr.xephi.authme.command.executable.changepassword;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@ -12,24 +11,26 @@ import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
* The command for a player to change his password with.
*/
public class ChangePasswordCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
final Wrapper wrapper = Wrapper.getInstance();
final Messages m = wrapper.getMessages();
// Get the passwords
String oldPassword = commandArguments.get(0);
String newPassword = commandArguments.get(1);
String oldPassword = arguments.get(0);
String newPassword = arguments.get(1);
// Get the player instance and make sure he's authenticated
Player player = (Player) sender;
@ -37,7 +38,7 @@ public class ChangePasswordCommand extends ExecutableCommand {
final PlayerCache playerCache = wrapper.getPlayerCache();
if (!playerCache.isAuthenticated(name)) {
m.send(player, MessageKey.NOT_LOGGED_IN);
return true;
return;
}
// Make sure the password is allowed
@ -48,26 +49,25 @@ public class ChangePasswordCommand extends ExecutableCommand {
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
m.send(player, MessageKey.PASSWORD_MATCH_ERROR);
return true;
return;
}
if (playerPassLowerCase.equalsIgnoreCase(name)) {
m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR);
return true;
return;
}
if (playerPassLowerCase.length() < Settings.getPasswordMinLen
|| playerPassLowerCase.length() > Settings.passwordMaxLength) {
m.send(player, MessageKey.INVALID_PASSWORD_LENGTH);
return true;
return;
}
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
return true;
return;
}
// Set the password
final AuthMe plugin = wrapper.getAuthMe();
wrapper.getScheduler().runTaskAsynchronously(plugin,
new ChangePasswordTask(plugin, player, oldPassword, newPassword));
return true;
}
}

View File

@ -1,29 +1,27 @@
package fr.xephi.authme.command.executable.converter;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.converter.*;
import fr.xephi.authme.converter.Converter;
import fr.xephi.authme.converter.CrazyLoginConverter;
import fr.xephi.authme.converter.FlatToSql;
import fr.xephi.authme.converter.FlatToSqlite;
import fr.xephi.authme.converter.RakamakConverter;
import fr.xephi.authme.converter.RoyalAuthConverter;
import fr.xephi.authme.converter.SqlToFlat;
import fr.xephi.authme.converter.vAuthConverter;
import fr.xephi.authme.converter.xAuthConverter;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
/**
*/
import java.util.List;
public class ConverterCommand 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) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
@ -31,40 +29,40 @@ public class ConverterCommand extends ExecutableCommand {
final Messages m = plugin.getMessages();
// Get the conversion job
String job = commandArguments.get(0);
String job = arguments.get(0);
// Determine the job type
ConvertType jobType = ConvertType.fromName(job);
if (jobType == null) {
m.send(sender, MessageKey.ERROR);
return true;
return;
}
// Get the proper converter instance
Converter converter = null;
switch (jobType) {
case ftsql:
case FTSQL:
converter = new FlatToSql();
break;
case ftsqlite:
case FTSQLITE:
converter = new FlatToSqlite(sender);
break;
case xauth:
case XAUTH:
converter = new xAuthConverter(plugin, sender);
break;
case crazylogin:
case CRAZYLOGIN:
converter = new CrazyLoginConverter(plugin, sender);
break;
case rakamak:
case RAKAMAK:
converter = new RakamakConverter(plugin, sender);
break;
case royalauth:
case ROYALAUTH:
converter = new RoyalAuthConverter(plugin);
break;
case vauth:
case VAUTH:
converter = new vAuthConverter(plugin, sender);
break;
case sqltoflat:
case SQLTOFLAT:
converter = new SqlToFlat(plugin, sender);
break;
default:
@ -76,52 +74,33 @@ public class ConverterCommand extends ExecutableCommand {
// Show a status message
sender.sendMessage("[AuthMe] Successfully converted from " + jobType.getName());
return true;
}
/**
*/
public enum ConvertType {
ftsql("flattosql"),
ftsqlite("flattosqlite"),
xauth("xauth"),
crazylogin("crazylogin"),
rakamak("rakamak"),
royalauth("royalauth"),
vauth("vauth"),
sqltoflat("sqltoflat");
FTSQL("flattosql"),
FTSQLITE("flattosqlite"),
XAUTH("xauth"),
CRAZYLOGIN("crazylogin"),
RAKAMAK("rakamak"),
ROYALAUTH("royalauth"),
VAUTH("vauth"),
SQLTOFLAT("sqltoflat");
final String name;
/**
* Constructor for ConvertType.
*
* @param name String
*/
ConvertType(String name) {
this.name = name;
}
/**
* Method fromName.
*
* @param name String
*
* @return ConvertType
*/
public static ConvertType fromName(String name) {
for (ConvertType type : ConvertType.values()) {
if (type.getName().equalsIgnoreCase(name))
if (type.getName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
/**
* Method getName.
*
* @return String
*/
String getName() {
return this.name;
}

View File

@ -1,31 +1,29 @@
package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class AddEmailCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
// Get the parameter values
String playerMail = commandArguments.get(0);
String playerMailVerify = commandArguments.get(1);
String playerMail = arguments.get(0);
String playerMailVerify = arguments.get(1);
// Get the player and perform email addition
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
final Player player = (Player) sender;
plugin.getManagement().performAddEmail(player, playerMail, playerMailVerify);
return true;
}
}

View File

@ -1,31 +1,31 @@
package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class ChangeEmailCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
// Get the parameter values
String playerMailOld = commandArguments.get(0);
String playerMailNew = commandArguments.get(1);
String playerMailOld = arguments.get(0);
String playerMailNew = arguments.get(1);
// Get the player instance and execute action
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
final Player player = (Player) sender;
plugin.getManagement().performChangeEmail(player, playerMailOld, playerMailNew);
return true;
}
}

View File

@ -4,32 +4,30 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.security.NoSuchAlgorithmException;
import java.util.List;
/**
*/
public class RecoverEmailCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
// Get the parameter values
String playerMail = commandArguments.get(0);
String playerMail = arguments.get(0);
// Get the player instance and name
final Player player = (Player) sender;
@ -42,12 +40,12 @@ public class RecoverEmailCommand extends ExecutableCommand {
if (plugin.mail == null) {
m.send(player, MessageKey.ERROR);
return true;
return;
}
if (plugin.database.isAuthAvailable(playerName)) {
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return true;
return;
}
try {
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
@ -60,16 +58,17 @@ public class RecoverEmailCommand extends ExecutableCommand {
auth = plugin.database.getAuth(playerName);
} else {
m.send(player, MessageKey.UNKNOWN_USER);
return true;
return;
}
if (Settings.getmailAccount.equals("") || Settings.getmailAccount.isEmpty()) {
m.send(player, MessageKey.ERROR);
return true;
return;
}
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com") || auth.getEmail().equalsIgnoreCase("your@email.com")) {
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com")
|| auth.getEmail().equalsIgnoreCase("your@email.com")) {
m.send(player, MessageKey.INVALID_EMAIL);
return true;
return;
}
auth.setHash(hashNew);
plugin.database.updatePassword(auth);
@ -83,7 +82,5 @@ public class RecoverEmailCommand extends ExecutableCommand {
} else {
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
}
return true;
}
}

View File

@ -1,30 +1,28 @@
package fr.xephi.authme.command.executable.login;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class LoginCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
// Get the necessary objects
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
final Player player = (Player) sender;
final String password = commandArguments.get(0);
final String password = arguments.get(0);
// Log the player in
plugin.getManagement().performLogin(player, password, false);
return true;
}
}

View File

@ -1,21 +1,22 @@
package fr.xephi.authme.command.executable.logout;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class LogoutCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
// Get the player instance
@ -24,6 +25,5 @@ public class LogoutCommand extends ExecutableCommand {
// Logout the player
plugin.getManagement().performLogout(player);
return true;
}
}

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.register;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.command.CommandSender;
@ -14,20 +13,16 @@ import org.bukkit.entity.Player;
import java.util.List;
/**
*/
public class RegisterCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the sender is a player
if (!(sender instanceof Player)) {
sender.sendMessage("Player Only! Use 'authme register <playername> <password>' instead");
return true;
return;
}
List<String> arguments = commandArguments.getList();
final Wrapper wrapper = Wrapper.getInstance();
final AuthMe plugin = wrapper.getAuthMe();
final Messages m = wrapper.getMessages();
@ -36,31 +31,30 @@ public class RegisterCommand extends ExecutableCommand {
final Player player = (Player) sender;
if (arguments.isEmpty() || (Settings.getEnablePasswordVerifier && arguments.size() < 2)) {
m.send(player, MessageKey.USAGE_REGISTER);
return true;
return;
}
final Management management = plugin.getManagement();
if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
if (Settings.doubleEmailCheck && arguments.size() < 2 || !arguments.get(0).equals(arguments.get(1))) {
m.send(player, MessageKey.USAGE_REGISTER);
return true;
return;
}
final String email = arguments.get(0);
if (!Settings.isEmailCorrect(email)) {
m.send(player, MessageKey.INVALID_EMAIL);
return true;
return;
}
final String thePass = new RandomString(Settings.getRecoveryPassLength).nextString();
management.performRegister(player, thePass, email);
return true;
return;
}
if (arguments.size() > 1 && Settings.getEnablePasswordVerifier) {
if (!arguments.get(0).equals(commandArguments.get(1))) {
if (!arguments.get(0).equals(arguments.get(1))) {
m.send(player, MessageKey.PASSWORD_MATCH_ERROR);
return true;
return;
}
}
management.performRegister(player, commandArguments.get(0), "");
return true;
management.performRegister(player, arguments.get(0), "");
}
}

View File

@ -2,41 +2,28 @@ package fr.xephi.authme.command.executable.unregister;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*/
import java.util.List;
public class UnregisterCommand 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 = plugin.getMessages();
public void executeCommand(CommandSender sender, List<String> arguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
return;
}
final AuthMe plugin = AuthMe.getInstance();
final Messages m = plugin.getMessages();
// Get the password
String playerPass = commandArguments.get(0);
String playerPass = arguments.get(0);
// Get the player instance and name
final Player player = (Player) sender;
@ -45,11 +32,10 @@ public class UnregisterCommand extends ExecutableCommand {
// Make sure the player is authenticated
if (!PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
m.send(player, MessageKey.NOT_LOGGED_IN);
return true;
return;
}
// Unregister the player
plugin.getManagement().performUnregister(player, playerPass, false);
return true;
}
}

View File

@ -69,7 +69,7 @@ public class HelpPrinter {
for (CommandArgumentDescription arg : command.getArguments()) {
// Create a string builder to build the syntax in
StringBuilder argString = new StringBuilder();
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription());
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getName() + " : " + ChatColor.WHITE + arg.getDescription());
// Suffix a note if the command is optional
if (arg.isOptional())

View File

@ -29,6 +29,13 @@ public class HelpProvider {
showHelp(sender, reference, helpQuery, true, true, true, true, true, true);
}
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery,
boolean showCommand, boolean showDescription, boolean showArguments,
boolean showPermissions, boolean showAlternatives, boolean showCommands) {
showHelp(sender, reference.getList(), helpQuery.getList(), showCommand, showDescription, showArguments,
showPermissions, showAlternatives, showCommands);
}
/**
* Show help for a specific command.
*
@ -42,7 +49,9 @@ public class HelpProvider {
* @param showAlternatives True to show the command alternatives.
* @param showCommands True to show the child commands.
*/
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery, boolean showCommand, boolean showDescription, boolean showArguments, boolean showPermissions, boolean showAlternatives, boolean showCommands) {
public static void showHelp(CommandSender sender, List<String> reference, List<String> helpQuery,
boolean showCommand, boolean showDescription, boolean showArguments,
boolean showPermissions, boolean showAlternatives, boolean showCommands) {
// Find the command for this help query, one with and one without a prefixed base command
FoundCommandResult result = AuthMe.getInstance().getCommandHandler().findCommand(new CommandParts(helpQuery.getList()));
@ -77,7 +86,7 @@ public class HelpProvider {
}
// Get the proper command reference to use for the help page
CommandParts commandReference = command.getCommandReference(result.getQueryReference());
CommandParts commandReference = command.getCommandReference(result.getLabels());
// Get the base command
String baseCommand = commandReference.get(0);

View File

@ -73,8 +73,8 @@ public final class HelpSyntaxHelper {
private static String formatArgument(CommandArgumentDescription argument) {
if (argument.isOptional()) {
return " [" + argument.getLabel() + "]";
return " [" + argument.getName() + "]";
}
return " <" + argument.getLabel() + ">";
return " <" + argument.getName() + ">";
}
}

View File

@ -1,6 +1,7 @@
package fr.xephi.authme.command;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.util.WrapperMock;
import org.bukkit.command.CommandSender;
@ -21,7 +22,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
@ -35,6 +36,7 @@ public class CommandHandlerTest {
private static Set<CommandDescription> commands;
private static CommandHandler handler;
private static PermissionsManager permissionsManagerMock;
@BeforeClass
public static void setUpCommandHandler() {
@ -47,7 +49,8 @@ public class CommandHandlerTest {
CommandDescription testBase = createCommand(null, null, singletonList("test"), newArgument("test", true));
commands = new HashSet<>(asList(authMeBase, testBase));
handler = new CommandHandler(commands);
permissionsManagerMock = mock(PermissionsManager.class);
handler = new CommandHandler(commands, permissionsManagerMock);
}
@Test
@ -65,8 +68,7 @@ public class CommandHandlerTest {
// then
final CommandDescription loginCmd = getChildWithLabel("login", getCommandWithLabel("authme", commands));
verify(sender, never()).sendMessage(anyString());
verify(loginCmd.getExecutableCommand()).executeCommand(
eq(sender), any(CommandParts.class), any(CommandParts.class));
verify(loginCmd.getExecutableCommand()).executeCommand(eq(sender), anyListOf(String.class));
}
@Test
@ -98,7 +100,7 @@ public class CommandHandlerTest {
if (arguments != null && arguments.length > 0) {
for (CommandArgumentDescription argument : arguments) {
command.withArgument(argument.getLabel(), "Test description", argument.isOptional());
command.withArgument(argument.getName(), "Test description", argument.isOptional());
}
}