Merge enum branch into master

This commit is contained in:
ljacqu
2015-11-26 21:45:06 +01:00
21 changed files with 537 additions and 155 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;
@@ -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() {