This commit is contained in:
Gabriele C
2015-11-26 22:14:37 +01:00
22 changed files with 571 additions and 266 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ public class AntiBot {
private static final AuthMe plugin = AuthMe.getInstance();
private static final Messages messages = plugin.getMessages();
private static Wrapper wrapper = new Wrapper(plugin);
private static Wrapper wrapper = Wrapper.getInstance();
private static final List<String> antibotPlayers = new ArrayList<>();
private static AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
@@ -17,7 +17,7 @@ import java.util.Date;
*/
public final class ConsoleLogger {
private static Wrapper wrapper = new Wrapper(AuthMe.getInstance());
private static Wrapper wrapper = Wrapper.getInstance();
private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
private ConsoleLogger() {
@@ -226,11 +226,11 @@ public class CommandDescription {
*/
public void setLabels(List<String> labels) {
// Check whether the command label list should be cleared
if (labels == null)
if (labels == null) {
this.labels.clear();
else
} else {
this.labels = labels;
}
}
/**
@@ -344,7 +344,7 @@ public class CommandDescription {
/**
* Get the absolute command label, without a slash.
*
* @return String
* @return the absolute label
*/
public String getAbsoluteLabel() {
return getAbsoluteLabel(false);
@@ -364,8 +364,8 @@ public class CommandDescription {
/**
* Get the absolute command label.
*
* @param includeSlash boolean
* @param reference CommandParts
* @param includeSlash
* @param reference
*
* @return Absolute command label.
*/
@@ -644,11 +644,11 @@ public class CommandDescription {
*/
public void setArguments(List<CommandArgumentDescription> arguments) {
// Convert null into an empty argument list
if (arguments == null)
if (arguments == null) {
this.arguments.clear();
else
} else {
this.arguments = arguments;
}
}
/**
@@ -659,12 +659,7 @@ public class CommandDescription {
* @return True if this argument already exists, false otherwise.
*/
public boolean hasArgument(CommandArgumentDescription argument) {
// Make sure the argument is valid
if (argument == null)
return false;
// Check whether the argument exists, return the result
return this.arguments.contains(argument);
return argument != null && arguments.contains(argument);
}
/**
@@ -881,19 +876,22 @@ public class CommandDescription {
*/
public int getSuitableArgumentsDifference(CommandParts commandReference) {
// Make sure the command reference is valid
if (commandReference.getCount() <= 0)
if (commandReference.getCount() <= 0) {
return -1;
}
// Get the remaining command reference element count
int remainingElementCount = commandReference.getCount() - getParentCount() - 1;
// Check if there are too less arguments
if (getMinimumArguments() > remainingElementCount)
// Check if there are too few arguments
if (getMinimumArguments() > remainingElementCount) {
return Math.abs(getMinimumArguments() - remainingElementCount);
}
// Check if there are too many arguments
if (getMaximumArguments() < remainingElementCount && getMaximumArguments() >= 0)
if (getMaximumArguments() < remainingElementCount && getMaximumArguments() >= 0) {
return Math.abs(remainingElementCount - getMaximumArguments());
}
// The arguments seem to be EQUALS, return the result
return 0;
@@ -934,12 +932,14 @@ public class CommandDescription {
*/
public boolean isValid() {
// Make sure any command label is set
if (getLabels().size() == 0)
if (getLabels().size() == 0) {
return false;
}
// Make sure the permissions are set up properly
if (this.permissions == null)
if (this.permissions == null) {
return false;
}
// Everything seems to be correct, return the result
return true;
@@ -37,8 +37,18 @@ public class CommandManager {
* Register all commands.
*/
// TODO ljacqu 20151121: Create a builder class for CommandDescription
@SuppressWarnings({"serial"})
public void registerCommands() {
// Create a list of help command labels
final List<String> helpCommandLabels = new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
};
// Register the base AuthMe Reloaded command
CommandDescription authMeBaseCommand = new CommandDescription(new AuthMeCommand(), new ArrayList<String>() {
@@ -48,16 +58,8 @@ public class CommandManager {
}, "Main command", "The main AuthMeReloaded command. The root for all admin commands.", null);
// Register the help command
CommandDescription authMeHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded commands.", authMeBaseCommand);
CommandDescription authMeHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded commands.", authMeBaseCommand);
authMeHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
authMeHelpCommand.setMaximumArguments(false);
@@ -75,16 +77,8 @@ public class CommandManager {
registerCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
// Register the unregister command
CommandDescription unregisterCommand = new CommandDescription(new UnregisterCommand(), new ArrayList<String>() {
{
add("unregister");
add("unreg");
add("unr");
add("delete");
add("del");
}
}, "Unregister a player", "Unregister the specified player.", authMeBaseCommand);
CommandDescription unregisterCommand = new CommandDescription(new UnregisterCommand(), helpCommandLabels,
"Unregister a player", "Unregister the specified player.", authMeBaseCommand);
unregisterCommand.setCommandPermissions("authme.admin.unregister", CommandPermissions.DefaultPermission.OP_ONLY);
unregisterCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
@@ -287,16 +281,8 @@ public class CommandManager {
reloadCommand.setCommandPermissions("authme.admin.reload", CommandPermissions.DefaultPermission.OP_ONLY);
// Register the version command
CommandDescription versionCommand = new CommandDescription(new VersionCommand(), new ArrayList<String>() {
{
add("version");
add("ver");
add("v");
add("about");
add("info");
}
}, "Version info", "Show detailed information about the installed AuthMeReloaded version, and shows the developers, contributors, license and other information.", authMeBaseCommand);
CommandDescription versionCommand = new CommandDescription(new VersionCommand(), helpCommandLabels,
"Version info", "Show detailed information about the installed AuthMeReloaded version, and shows the developers, contributors, license and other information.", authMeBaseCommand);
versionCommand.setMaximumArguments(false);
// Register the base Dungeon Maze command
@@ -311,16 +297,8 @@ public class CommandManager {
loginBaseCommand.addArgument(new CommandArgumentDescription("password", "Login password", false));
// Register the help command
CommandDescription loginHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded login commands.", loginBaseCommand);
CommandDescription loginHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded login commands.", loginBaseCommand);
loginHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
loginHelpCommand.setMaximumArguments(false);
@@ -334,16 +312,8 @@ public class CommandManager {
logoutBaseCommand.setCommandPermissions("authme.logout", CommandPermissions.DefaultPermission.ALLOWED);
// Register the help command
CommandDescription logoutHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded logout commands.", logoutBaseCommand);
CommandDescription logoutHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded logout commands.", logoutBaseCommand);
logoutHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
logoutHelpCommand.setMaximumArguments(false);
@@ -361,16 +331,8 @@ public class CommandManager {
registerBaseCommand.setMaximumArguments(false);
// Register the help command
CommandDescription registerHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded register commands.", registerBaseCommand);
CommandDescription registerHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded register commands.", registerBaseCommand);
registerHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
registerHelpCommand.setMaximumArguments(false);
@@ -386,16 +348,7 @@ public class CommandManager {
unregisterBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
// Register the help command
CommandDescription unregisterHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded unregister commands.", unregisterBaseCommand);
CommandDescription unregisterHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels, "View help", "View detailed help pages about AuthMeReloaded unregister commands.", unregisterBaseCommand);
unregisterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
unregisterHelpCommand.setMaximumArguments(false);
@@ -413,16 +366,8 @@ public class CommandManager {
changePasswordBaseCommand.setMaximumArguments(false);
// Register the help command
CommandDescription changePasswordHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded change password commands.", changePasswordBaseCommand);
CommandDescription changePasswordHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded change password commands.", changePasswordBaseCommand);
changePasswordHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
changePasswordHelpCommand.setMaximumArguments(false);
@@ -436,16 +381,8 @@ public class CommandManager {
}, "E-mail command", "The AuthMe Reloaded E-mail command. The root for all E-mail commands.", null);
// Register the help command
CommandDescription emailHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded help commands.", emailBaseCommand);
CommandDescription emailHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded help commands.", emailBaseCommand);
emailHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
emailHelpCommand.setMaximumArguments(false);
@@ -501,16 +438,8 @@ public class CommandManager {
captchaBaseCommand.setMaximumArguments(false);
// Register the help command
CommandDescription captchaHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded change captcha commands.", captchaBaseCommand);
CommandDescription captchaHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", captchaBaseCommand);
captchaHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
captchaHelpCommand.setMaximumArguments(false);
@@ -528,16 +457,8 @@ public class CommandManager {
converterBaseCommand.setMaximumArguments(false);
// Register the help command
CommandDescription converterHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}
}, "View help", "View detailed help pages about AuthMeReloaded change captcha commands.", converterBaseCommand);
CommandDescription converterHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", converterBaseCommand);
converterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
converterHelpCommand.setMaximumArguments(false);
@@ -17,6 +17,11 @@ public class ChangePasswordCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
}
final AuthMe plugin = AuthMe.getInstance();
final Messages m = plugin.getMessages();
@@ -24,11 +29,6 @@ public class ChangePasswordCommand extends ExecutableCommand {
String playerPass = commandArguments.get(0);
String playerPassVerify = commandArguments.get(1);
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
}
// Get the player instance and make sure it's authenticated
Player player = (Player) sender;
String name = player.getName().toLowerCase();
@@ -38,6 +38,7 @@ public class ChangePasswordCommand extends ExecutableCommand {
}
// Make sure the password is allowed
// TODO ljacqu 20151121: The password confirmation appears to be never verified
String playerPassLowerCase = playerPass.toLowerCase();
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
@@ -56,11 +57,9 @@ public class ChangePasswordCommand extends ExecutableCommand {
m.send(player, MessageKey.INVALID_PASSWORD_LENGTH);
return true;
}
if (!Settings.unsafePasswords.isEmpty()) {
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
return true;
}
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
return true;
}
// Set the password
@@ -12,19 +12,19 @@ public class AddEmailCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the parameter values
String playerMail = commandArguments.get(0);
String playerMailVerify = commandArguments.get(1);
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
}
// Get the parameter values
String playerMail = commandArguments.get(0);
String playerMailVerify = commandArguments.get(1);
// Get the player and perform email addition
final AuthMe plugin = AuthMe.getInstance();
final Player player = (Player) sender;
plugin.management.performAddEmail(player, playerMail, playerMailVerify);
plugin.getManagement().performAddEmail(player, playerMail, playerMailVerify);
return true;
}
}
@@ -12,19 +12,19 @@ public class ChangeEmailCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the parameter values
String playerMailOld = commandArguments.get(0);
String playerMailNew = commandArguments.get(1);
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
}
// Get the parameter values
String playerMailOld = commandArguments.get(0);
String playerMailNew = commandArguments.get(1);
// Get the player instance and execute action
final AuthMe plugin = AuthMe.getInstance();
final Player player = (Player) sender;
plugin.management.performChangeEmail(player, playerMailOld, playerMailNew);
plugin.getManagement().performChangeEmail(player, playerMailOld, playerMailNew);
return true;
}
}
@@ -22,14 +22,14 @@ public class RecoverEmailCommand extends ExecutableCommand {
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the parameter values
String playerMail = commandArguments.get(0);
// Make sure the current command executor is a player
if (!(sender instanceof Player)) {
return true;
}
// Get the parameter values
String playerMail = commandArguments.get(0);
// Get the player instance and name
final Player player = (Player) sender;
final String playerName = player.getName();
@@ -12,8 +12,6 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
/**
* @author Gabriele
* @version $Revision: 1.0 $
*/
public class Management {
@@ -30,13 +28,6 @@ public class Management {
this.sched = this.plugin.getServer().getScheduler();
}
/**
* Method performLogin.
*
* @param player Player
* @param password String
* @param forceLogin boolean
*/
public void performLogin(final Player player, final String password, final boolean forceLogin) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -47,11 +38,6 @@ public class Management {
});
}
/**
* Method performLogout.
*
* @param player Player
*/
public void performLogout(final Player player) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -62,13 +48,6 @@ public class Management {
});
}
/**
* Method performRegister.
*
* @param player Player
* @param password String
* @param email String
*/
public void performRegister(final Player player, final String password, final String email) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -79,13 +58,6 @@ public class Management {
});
}
/**
* Method performUnregister.
*
* @param player Player
* @param password String
* @param force boolean
*/
public void performUnregister(final Player player, final String password, final boolean force) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -96,11 +68,6 @@ public class Management {
});
}
/**
* Method performJoin.
*
* @param player Player
*/
public void performJoin(final Player player) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -112,12 +79,6 @@ public class Management {
});
}
/**
* Method performQuit.
*
* @param player Player
* @param isKick boolean
*/
public void performQuit(final Player player, final boolean isKick) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -129,13 +90,6 @@ public class Management {
});
}
/**
* Method performAddEmail.
*
* @param player Player
* @param newEmail String
* @param newEmailVerify String
*/
public void performAddEmail(final Player player, final String newEmail, final String newEmailVerify) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@Override
@@ -145,13 +99,6 @@ public class Management {
});
}
/**
* Method performChangeEmail.
*
* @param player Player
* @param oldEmail String
* @param newEmail String
*/
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@Override
@@ -17,7 +17,6 @@ public class GeoLiteAPI {
"available at http://www.maxmind.com";
private static final String GEOIP_URL = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry" +
"/GeoIP.dat.gz";
private static final Wrapper wrapper = new Wrapper(AuthMe.getInstance());
private static final AuthMe plugin = AuthMe.getInstance();
private static LookupService lookupService;
@@ -10,10 +10,14 @@ import java.io.StringWriter;
/**
* Utility class for String operations.
*/
public class StringUtils {
public final class StringUtils {
public static final String newline = System.getProperty("line.separator");
private StringUtils() {
// Utility class
}
/**
* Get the difference of two strings.
*
@@ -26,7 +26,7 @@ import java.util.Collections;
*/
public final class Utils {
private static final AuthMe plugin;
private static AuthMe plugin;
private static Wrapper wrapper;
private static boolean getOnlinePlayersIsCollection = false;
@@ -34,7 +34,7 @@ public final class Utils {
static {
plugin = AuthMe.getInstance();
wrapper = new Wrapper(plugin);
wrapper = Wrapper.getInstance();
initializeOnlinePlayersIsCollectionField();
}
@@ -116,9 +116,10 @@ public final class Utils {
// Get the permissions manager, and make sure it's valid
PermissionsManager permsMan = plugin.getPermissionsManager();
if (permsMan == null)
ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
assert permsMan != null;
if (permsMan == null) {
ConsoleLogger.showError("Failed to access permissions manager instance, aborting.");
return false;
}
// Remove old groups
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup,
@@ -13,22 +13,31 @@ import java.util.logging.Logger;
*/
public class Wrapper {
private AuthMe authMe;
private static Wrapper singleton;
public Wrapper(AuthMe authMe) {
this.authMe = authMe;
/**
* Package-private constructor for testing purposes to inject a mock instance.
*/
Wrapper() {
}
public static Wrapper getInstance() {
if (singleton == null) {
singleton = new Wrapper();
}
return singleton;
}
public AuthMe getAuthMe() {
return authMe;
return AuthMe.getInstance();
}
public Server getServer() {
return authMe.getServer();
return getAuthMe().getServer();
}
public Logger getLogger() {
return authMe.getLogger();
return getAuthMe().getLogger();
}
public BukkitScheduler getScheduler() {