From 36c50c4507a79f649c0e3d551bce0dbffdb3f306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Mon, 23 Nov 2015 21:46:34 +0100 Subject: [PATCH] Reformatted code with new code style --- src/main/java/fr/xephi/authme/AuthMe.java | 1 + .../java/fr/xephi/authme/ConsoleFilter.java | 1 + .../java/fr/xephi/authme/DataManager.java | 3 + .../java/fr/xephi/authme/Log4JFilter.java | 2 + .../java/fr/xephi/authme/PerformBackup.java | 3 + src/main/java/fr/xephi/authme/api/API.java | 8 + src/main/java/fr/xephi/authme/api/NewAPI.java | 7 + .../xephi/authme/cache/auth/PlayerAuth.java | 1 + .../xephi/authme/cache/auth/PlayerCache.java | 2 + .../xephi/authme/cache/backup/JsonCache.java | 4 + .../xephi/authme/cache/limbo/LimboCache.java | 2 + .../authme/command/CommandDescription.java | 24 + .../xephi/authme/command/CommandHandler.java | 2 + .../xephi/authme/command/CommandManager.java | 1 + .../fr/xephi/authme/command/CommandParts.java | 8 + .../authme/command/CommandPermissions.java | 4 + .../authme/command/ExecutableCommand.java | 1 + .../authme/command/FoundCommandResult.java | 2 + .../executable/authme/GetEmailCommand.java | 1 + .../authme/PurgeBannedPlayersCommand.java | 1 + .../executable/authme/PurgeCommand.java | 1 + .../authme/PurgeLastPositionCommand.java | 1 + .../executable/authme/RegisterCommand.java | 1 + .../executable/authme/ReloadCommand.java | 1 + .../executable/authme/ResetNameCommand.java | 1 + .../executable/authme/SetEmailCommand.java | 1 + .../authme/SetFirstSpawnCommand.java | 1 + .../executable/authme/SetSpawnCommand.java | 1 + .../executable/authme/SpawnCommand.java | 1 + .../authme/SwitchAntiBotCommand.java | 1 + .../executable/authme/UnregisterCommand.java | 1 + .../executable/authme/VersionCommand.java | 2 + .../executable/captcha/CaptchaCommand.java | 1 + .../converter/ConverterCommand.java | 2 + .../unregister/UnregisterCommand.java | 1 + .../authme/command/help/HelpSyntaxHelper.java | 1 + .../xephi/authme/converter/FlatToSqlite.java | 1 + .../authme/converter/vAuthFileReader.java | 2 + .../xephi/authme/converter/xAuthToFlat.java | 2 + .../authme/datasource/CacheDataSource.java | 1102 +++++------ .../xephi/authme/datasource/DataSource.java | 436 +++-- .../authme/datasource/DatabaseCalls.java | 1006 +++++----- .../fr/xephi/authme/datasource/FlatFile.java | 20 + .../fr/xephi/authme/datasource/MySQL.java | 20 + .../fr/xephi/authme/datasource/SQLite.java | 1692 +++++++++-------- .../fr/xephi/authme/events/CustomEvent.java | 1 + .../xephi/authme/hooks/BungeeCordMessage.java | 1 + .../AuthMeInventoryPacketAdapter.java | 1 + .../xephi/authme/modules/ModuleManager.java | 4 + .../authme/permission/PermissionsManager.java | 12 + .../authme/security/PasswordSecurity.java | 4 + .../xephi/authme/security/crypts/BCRYPT.java | 13 + .../authme/security/crypts/BCRYPT2Y.java | 2 + .../authme/security/crypts/CRAZYCRYPT1.java | 1 + .../authme/security/crypts/CryptPBKDF2.java | 2 + .../security/crypts/CryptPBKDF2Django.java | 2 + .../authme/security/crypts/DOUBLEMD5.java | 3 + .../security/crypts/EncryptionMethod.java | 2 + .../fr/xephi/authme/security/crypts/IPB3.java | 3 + .../xephi/authme/security/crypts/JOOMLA.java | 3 + .../fr/xephi/authme/security/crypts/MD5.java | 3 + .../xephi/authme/security/crypts/MD5VB.java | 3 + .../fr/xephi/authme/security/crypts/MYBB.java | 3 + .../xephi/authme/security/crypts/PHPBB.java | 12 + .../authme/security/crypts/PHPFUSION.java | 3 + .../authme/security/crypts/PLAINTEXT.java | 2 + .../authme/security/crypts/ROYALAUTH.java | 3 + .../authme/security/crypts/SALTED2MD5.java | 3 + .../authme/security/crypts/SALTEDSHA512.java | 3 + .../fr/xephi/authme/security/crypts/SHA1.java | 3 + .../xephi/authme/security/crypts/SHA256.java | 3 + .../xephi/authme/security/crypts/SHA512.java | 3 + .../fr/xephi/authme/security/crypts/SMF.java | 3 + .../fr/xephi/authme/security/crypts/WBB3.java | 3 + .../fr/xephi/authme/security/crypts/WBB4.java | 2 + .../authme/security/crypts/WHIRLPOOL.java | 3 + .../authme/security/crypts/WORDPRESS.java | 6 + .../xephi/authme/security/crypts/XAUTH.java | 3 + .../fr/xephi/authme/security/crypts/XF.java | 4 + .../authme/security/pbkdf2/BinTools.java | 3 + .../authme/security/pbkdf2/MacBasedPRF.java | 2 + .../xephi/authme/security/pbkdf2/PBKDF2.java | 3 + .../authme/security/pbkdf2/PBKDF2Engine.java | 10 + .../security/pbkdf2/PBKDF2Formatter.java | 2 + .../security/pbkdf2/PBKDF2HexFormatter.java | 2 + .../fr/xephi/authme/security/pbkdf2/PRF.java | 1 + .../xephi/authme/settings/OtherAccounts.java | 1 + .../fr/xephi/authme/settings/Settings.java | 3 + .../java/fr/xephi/authme/settings/Spawn.java | 2 + .../java/fr/xephi/authme/util/GeoLiteAPI.java | 2 + .../fr/xephi/authme/util/StringUtils.java | 5 + src/main/java/fr/xephi/authme/util/Utils.java | 3 + 92 files changed, 2458 insertions(+), 2080 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index db10a55e5..b086511be 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -941,6 +941,7 @@ public class AuthMe extends JavaPlugin { * @param cmd The command (Bukkit). * @param commandLabel The command label (Bukkit). * @param args The command arguments (Bukkit). + * * @return True if the command was executed, false otherwise. */ @Override diff --git a/src/main/java/fr/xephi/authme/ConsoleFilter.java b/src/main/java/fr/xephi/authme/ConsoleFilter.java index 255fa6e96..7e12ef10e 100644 --- a/src/main/java/fr/xephi/authme/ConsoleFilter.java +++ b/src/main/java/fr/xephi/authme/ConsoleFilter.java @@ -18,6 +18,7 @@ public class ConsoleFilter implements Filter { * Method isLoggable. * * @param record LogRecord + * * @return boolean * @see java.util.logging.Filter#isLoggable(LogRecord) */ @Override diff --git a/src/main/java/fr/xephi/authme/DataManager.java b/src/main/java/fr/xephi/authme/DataManager.java index 4254fc7ae..5da1209d8 100644 --- a/src/main/java/fr/xephi/authme/DataManager.java +++ b/src/main/java/fr/xephi/authme/DataManager.java @@ -36,6 +36,7 @@ public class DataManager { * Method getOfflinePlayer. * * @param name String + * * @return OfflinePlayer */ public synchronized OfflinePlayer getOfflinePlayer(final String name) { @@ -226,6 +227,7 @@ public class DataManager { * * @param player Player * @param name String + * * @return boolean */ public boolean isOnline(Player player, final String name) { @@ -256,6 +258,7 @@ public class DataManager { * Method getOnlinePlayerLower. * * @param name String + * * @return Player */ public Player getOnlinePlayerLower(String name) { diff --git a/src/main/java/fr/xephi/authme/Log4JFilter.java b/src/main/java/fr/xephi/authme/Log4JFilter.java index f66d7ba4e..581699f08 100644 --- a/src/main/java/fr/xephi/authme/Log4JFilter.java +++ b/src/main/java/fr/xephi/authme/Log4JFilter.java @@ -34,6 +34,7 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter { * data. * * @param message the Message object to verify + * * @return the Result value */ private static Result validateMessage(Message message) { @@ -48,6 +49,7 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter { * depending on whether the message contains sensitive AuthMe data. * * @param message the message to verify + * * @return the Result value */ private static Result validateMessage(String message) { diff --git a/src/main/java/fr/xephi/authme/PerformBackup.java b/src/main/java/fr/xephi/authme/PerformBackup.java index 7063231b6..29f59c284 100644 --- a/src/main/java/fr/xephi/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/PerformBackup.java @@ -128,6 +128,7 @@ public class PerformBackup { * Method FileBackup. * * @param backend String + * * @return boolean */ private boolean FileBackup(String backend) { @@ -150,6 +151,7 @@ public class PerformBackup { * Method checkWindows. * * @param windowsPath String + * * @return boolean */ private boolean checkWindows(String windowsPath) { @@ -174,6 +176,7 @@ public class PerformBackup { * * @param src File * @param dst File + * * @throws IOException */ void copy(File src, File dst) throws IOException { diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 595e52027..f63ac974e 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -50,6 +50,7 @@ public class API { /** * @param player + * * @return true if player is authenticate */ @Deprecated @@ -59,6 +60,7 @@ public class API { /** * @param player + * * @return true if the player is unrestricted */ @Deprecated @@ -70,6 +72,7 @@ public class API { * Method getLastLocation. * * @param player Player + * * @return Location */ @Deprecated @@ -108,6 +111,7 @@ public class API { /** * @param playerName + * * @return true if player is registered */ @Deprecated @@ -119,6 +123,7 @@ public class API { /** * @param playerName String * @param passwordToCheck String + * * @return true if the password is correct , false else */ @Deprecated @@ -140,6 +145,7 @@ public class API { * * @param playerName String * @param password String + * * @return true if the player is register correctly */ @Deprecated @@ -182,6 +188,7 @@ public class API { /** * @param player + * * @return true if player is a npc */ @Deprecated @@ -191,6 +198,7 @@ public class API { /** * @param player + * * @return true if player is a npc */ @Deprecated diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index a5bc9a68c..6f0f6b4fe 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -67,6 +67,7 @@ public class NewAPI { /** * @param player + * * @return true if player is authenticate */ public boolean isAuthenticated(Player player) { @@ -75,6 +76,7 @@ public class NewAPI { /** * @param player + * * @return true if player is a npc */ public boolean isNPC(Player player) { @@ -83,6 +85,7 @@ public class NewAPI { /** * @param player + * * @return true if the player is unrestricted */ public boolean isUnrestricted(Player player) { @@ -93,6 +96,7 @@ public class NewAPI { * Method getLastLocation. * * @param player Player + * * @return Location */ public Location getLastLocation(Player player) { @@ -112,6 +116,7 @@ public class NewAPI { /** * @param playerName + * * @return true if player is registered */ public boolean isRegistered(String playerName) { @@ -122,6 +127,7 @@ public class NewAPI { /** * @param playerName String * @param passwordToCheck String + * * @return true if the password is correct , false else */ public boolean checkPassword(String playerName, String passwordToCheck) { @@ -141,6 +147,7 @@ public class NewAPI { * * @param playerName String * @param password String + * * @return true if the player is register correctly */ public boolean registerPlayer(String playerName, String password) { diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index fe1457473..846fd1ef5 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -405,6 +405,7 @@ public class PlayerAuth { * Method equals. * * @param obj Object + * * @return boolean */ @Override diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java index 53f0a799e..dcaef24ea 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java @@ -57,6 +57,7 @@ public class PlayerCache { * Method isAuthenticated. * * @param user String + * * @return boolean */ public boolean isAuthenticated(String user) { @@ -67,6 +68,7 @@ public class PlayerCache { * Method getAuth. * * @param user String + * * @return PlayerAuth */ public PlayerAuth getAuth(String user) { diff --git a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java index f855a5830..b07c74d9e 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java @@ -70,6 +70,7 @@ public class JsonCache { * Method readCache. * * @param player Player + * * @return DataFileCache */ public DataFileCache readCache(Player player) { @@ -119,6 +120,7 @@ public class JsonCache { * Method doesCacheExist. * * @param player Player + * * @return boolean */ public boolean doesCacheExist(Player player) { @@ -141,6 +143,7 @@ public class JsonCache { * @param jsonElement JsonElement * @param type Type * @param jsonDeserializationContext JsonDeserializationContext + * * @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) */ @Override @@ -177,6 +180,7 @@ public class JsonCache { * @param dataFileCache DataFileCache * @param type Type * @param jsonSerializationContext JsonSerializationContext + * * @return JsonElement */ @Override diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index 2fb08b669..814fd8a7f 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -124,6 +124,7 @@ public class LimboCache { * Method getLimboPlayer. * * @param name String + * * @return LimboPlayer */ public LimboPlayer getLimboPlayer(String name) { @@ -134,6 +135,7 @@ public class LimboCache { * Method hasLimboPlayer. * * @param name String + * * @return boolean */ public boolean hasLimboPlayer(String name) { diff --git a/src/main/java/fr/xephi/authme/command/CommandDescription.java b/src/main/java/fr/xephi/authme/command/CommandDescription.java index 3db419b01..311758b7a 100644 --- a/src/main/java/fr/xephi/authme/command/CommandDescription.java +++ b/src/main/java/fr/xephi/authme/command/CommandDescription.java @@ -117,6 +117,7 @@ public class CommandDescription { * Check whether a label is valid to use. * * @param label The label to test. + * * @return True if the label is valid to use, false otherwise. */ public static boolean isValidLabel(String label) { @@ -140,6 +141,7 @@ public class CommandDescription { * * @param commandLabel The first command label. * @param otherCommandLabel The other command label. + * * @return True if the labels are equal to each other. */ private static boolean commandLabelEquals(String commandLabel, String otherCommandLabel) { @@ -178,6 +180,7 @@ public class CommandDescription { * Get the label most similar to the reference. The first label will be returned if no reference was supplied. * * @param reference The command reference. + * * @return The most similar label, or the first label. An empty label will be returned if no label was set. */ public String getLabel(CommandParts reference) { @@ -236,6 +239,7 @@ public class CommandDescription { * @param commandLabel Command label to set. * @param overwrite True to replace all old command labels, false to append this command label to the currently * existing labels. + * * @return Trie if the command label is added, or if it was added already. False on failure. */ public boolean setLabel(String commandLabel, boolean overwrite) { @@ -252,6 +256,7 @@ public class CommandDescription { * Add a command label to the list. * * @param commandLabel Command label to add. + * * @return True if the label was added, or if it was added already. False on error. */ public boolean addLabel(String commandLabel) { @@ -271,6 +276,7 @@ public class CommandDescription { * Add a list of command labels. * * @param commandLabels List of command labels to add. + * * @return True if succeed, false on failure. */ public boolean addLabels(List commandLabels) { @@ -285,6 +291,7 @@ public class CommandDescription { * Check whether this command description has a specific command. * * @param commandLabel Command to check for. + * * @return True if this command label equals to the param command. */ public boolean hasLabel(String commandLabel) { @@ -301,6 +308,7 @@ public class CommandDescription { * Check whether this command description has a list of labels * * @param commandLabels List of labels + * * @return True if all labels match, false otherwise */ public boolean hasLabels(List commandLabels) { @@ -318,6 +326,7 @@ public class CommandDescription { * are suitable too. * * @param commandReference The command reference. + * * @return True if the command reference is suitable to this command label, false otherwise. */ public boolean isSuitableLabel(CommandParts commandReference) { @@ -345,6 +354,7 @@ public class CommandDescription { * Get the absolute command label. * * @param includeSlash boolean + * * @return Absolute command label. */ public String getAbsoluteLabel(boolean includeSlash) { @@ -356,6 +366,7 @@ public class CommandDescription { * * @param includeSlash boolean * @param reference CommandParts + * * @return Absolute command label. */ public String getAbsoluteLabel(boolean includeSlash, CommandParts reference) { @@ -372,6 +383,7 @@ public class CommandDescription { * Get the command reference. * * @param reference The reference to use as template, which is used to choose the most similar reference. + * * @return Command reference. */ public CommandParts getCommandReference(CommandParts reference) { @@ -393,6 +405,7 @@ public class CommandDescription { * Get the difference between this command and another command reference. * * @param other The other command reference. + * * @return The command difference. Zero if there's no difference. A negative number on error. */ public double getCommandDifference(CommandParts other) { @@ -404,6 +417,7 @@ public class CommandDescription { * * @param other The other command reference. * @param fullCompare True to fully compare both command references. + * * @return The command difference. Zero if there's no difference. A negative number on error. */ public double getCommandDifference(CommandParts other, boolean fullCompare) { @@ -451,6 +465,7 @@ public class CommandDescription { * @param sender The command sender that triggered the execution of this command. * @param commandReference The command reference. * @param commandArguments The command arguments. + * * @return True on success, false on failure. */ public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { @@ -489,6 +504,7 @@ public class CommandDescription { * Set the parent command. * * @param parent Parent command. + * * @return True on success, false on failure. */ public boolean setParent(CommandDescription parent) { @@ -543,6 +559,7 @@ public class CommandDescription { * Add a child to the command description. * * @param commandDescription The child to add. + * * @return True on success, false on failure. */ public boolean addChild(CommandDescription commandDescription) { @@ -577,6 +594,7 @@ public class CommandDescription { * Check if this command description has a specific child. * * @param commandDescription The command description to check for. + * * @return True if this command description has the specific child, false otherwise. */ public boolean isChild(CommandDescription commandDescription) { @@ -594,6 +612,7 @@ public class CommandDescription { * Add an argument. * * @param argument The argument to add. + * * @return True if succeed, false if failed. */ public boolean addArgument(CommandArgumentDescription argument) { @@ -636,6 +655,7 @@ public class CommandDescription { * Check whether an argument exists. * * @param argument The argument to check for. + * * @return True if this argument already exists, false otherwise. */ public boolean hasArgument(CommandArgumentDescription argument) { @@ -771,6 +791,7 @@ public class CommandDescription { * Find the best suitable command for a query reference. * * @param queryReference The query reference to find a command for. + * * @return The command found, or null. */ public FoundCommandResult findCommand(final CommandParts queryReference) { @@ -832,6 +853,7 @@ public class CommandDescription { * Check whether there's any command description that matches the specified command reference. * * @param commandReference The command reference. + * * @return True if so, false otherwise. */ public boolean hasSuitableCommand(CommandParts commandReference) { @@ -842,6 +864,7 @@ public class CommandDescription { * Check if the remaining command reference elements are suitable with arguments of the current command description. * * @param commandReference The command reference. + * * @return True if the arguments are suitable, false otherwise. */ public boolean hasSuitableArguments(CommandParts commandReference) { @@ -853,6 +876,7 @@ public class CommandDescription { * and get the difference in argument count. * * @param commandReference The command reference. + * * @return The difference in argument count between the reference and the actual command. */ public int getSuitableArgumentsDifference(CommandParts commandReference) { diff --git a/src/main/java/fr/xephi/authme/command/CommandHandler.java b/src/main/java/fr/xephi/authme/command/CommandHandler.java index 365a63f4f..d06c1b876 100644 --- a/src/main/java/fr/xephi/authme/command/CommandHandler.java +++ b/src/main/java/fr/xephi/authme/command/CommandHandler.java @@ -89,6 +89,7 @@ public class CommandHandler { * @param bukkitCommand The command (Bukkit). * @param bukkitCommandLabel The command label (Bukkit). * @param bukkitArgs The command arguments (Bukkit). + * * @return True if the command was executed, false otherwise. */ public boolean onCommand(CommandSender sender, org.bukkit.command.Command bukkitCommand, String bukkitCommandLabel, String[] bukkitArgs) { @@ -181,6 +182,7 @@ public class CommandHandler { * Process the command arguments, and return them as an array list. * * @param args The command arguments to process. + * * @return The processed command arguments. */ private List processArguments(String[] args) { diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index efa9c2cf9..6382e27b4 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -575,6 +575,7 @@ public class CommandManager { * Find the best suitable command for the specified reference. * * @param queryReference The query reference to find a command for. + * * @return The command found, or null. */ public FoundCommandResult findCommand(CommandParts queryReference) { diff --git a/src/main/java/fr/xephi/authme/command/CommandParts.java b/src/main/java/fr/xephi/authme/command/CommandParts.java index 02cc7fa0f..9c261fc49 100644 --- a/src/main/java/fr/xephi/authme/command/CommandParts.java +++ b/src/main/java/fr/xephi/authme/command/CommandParts.java @@ -71,6 +71,7 @@ public class CommandParts { * Add a part. * * @param part The part to add. + * * @return The result. */ public boolean add(String part) { @@ -81,6 +82,7 @@ public class CommandParts { * Add some parts. * * @param parts The parts to add. + * * @return The result. */ public boolean add(List parts) { @@ -91,6 +93,7 @@ public class CommandParts { * Add some parts. * * @param parts The parts to add. + * * @return The result. */ public boolean add(String[] parts) { @@ -112,6 +115,7 @@ public class CommandParts { * Get a part by it's index. * * @param i Part index. + * * @return The part. */ public String get(int i) { @@ -127,6 +131,7 @@ public class CommandParts { * Get a range of the parts starting at the specified index up to the end of the range. * * @param start The starting index. + * * @return The parts range. Arguments that were out of bound are not included. */ public List getRange(int start) { @@ -138,6 +143,7 @@ public class CommandParts { * * @param start The starting index. * @param count The number of parts to get. + * * @return The parts range. Parts that were out of bound are not included. */ public List getRange(int start, int count) { @@ -160,6 +166,7 @@ public class CommandParts { * Get the difference value between two references. This won't do a full compare, just the last reference parts instead. * * @param other The other reference. + * * @return The result from zero to above. A negative number will be returned on error. */ public double getDifference(CommandParts other) { @@ -171,6 +178,7 @@ public class CommandParts { * * @param other The other reference. * @param fullCompare True to compare the full references as far as the range reaches. + * * @return The result from zero to above. A negative number will be returned on error. */ public double getDifference(CommandParts other, boolean fullCompare) { diff --git a/src/main/java/fr/xephi/authme/command/CommandPermissions.java b/src/main/java/fr/xephi/authme/command/CommandPermissions.java index 70064ddbe..06a1b7400 100644 --- a/src/main/java/fr/xephi/authme/command/CommandPermissions.java +++ b/src/main/java/fr/xephi/authme/command/CommandPermissions.java @@ -55,6 +55,7 @@ public class CommandPermissions { * Add a permission node required to execute this command. * * @param permissionNode The permission node to add. + * * @return True on success, false on failure. */ public boolean addPermissionNode(String permissionNode) { @@ -77,6 +78,7 @@ public class CommandPermissions { * Check whether this command requires a specified permission node to execute. * * @param permissionNode The permission node to check for. + * * @return True if this permission node is required, false if not. */ public boolean hasPermissionNode(String permissionNode) { @@ -114,6 +116,7 @@ public class CommandPermissions { * 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) { @@ -165,6 +168,7 @@ 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) { diff --git a/src/main/java/fr/xephi/authme/command/ExecutableCommand.java b/src/main/java/fr/xephi/authme/command/ExecutableCommand.java index 8fb37ee59..78db5ecf5 100644 --- a/src/main/java/fr/xephi/authme/command/ExecutableCommand.java +++ b/src/main/java/fr/xephi/authme/command/ExecutableCommand.java @@ -13,6 +13,7 @@ public abstract class ExecutableCommand { * @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. */ public abstract boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments); diff --git a/src/main/java/fr/xephi/authme/command/FoundCommandResult.java b/src/main/java/fr/xephi/authme/command/FoundCommandResult.java index dea0e9b8a..cde2da746 100644 --- a/src/main/java/fr/xephi/authme/command/FoundCommandResult.java +++ b/src/main/java/fr/xephi/authme/command/FoundCommandResult.java @@ -88,6 +88,7 @@ public class FoundCommandResult { * Execute the command. * * @param sender The command sender that executed the command. + * * @return True on success, false on failure. */ public boolean executeCommand(CommandSender sender) { @@ -103,6 +104,7 @@ public class FoundCommandResult { * Check whether a command sender has permission to execute the command. * * @param sender The command sender. + * * @return True if the command sender has permission, false otherwise. */ public boolean hasPermission(CommandSender sender) { diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java index 62ff055af..5e484c755 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java @@ -17,6 +17,7 @@ public class GetEmailCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java index e209e5ea0..5ecaad8ce 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java @@ -20,6 +20,7 @@ public class PurgeBannedPlayersCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java index 367547b51..69dd80d3c 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java @@ -20,6 +20,7 @@ public class PurgeCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java index 36dca82fb..35b8734d0 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java @@ -19,6 +19,7 @@ public class PurgeLastPositionCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java index 9e7dbcb11..150255f65 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java @@ -23,6 +23,7 @@ public class RegisterCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java index 9b2a42f86..e8b99d58d 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java @@ -21,6 +21,7 @@ public class ReloadCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ResetNameCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ResetNameCommand.java index bbf04d557..ae1f38400 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ResetNameCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ResetNameCommand.java @@ -19,6 +19,7 @@ public class ResetNameCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java index 37cc42884..fbec1640d 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java @@ -19,6 +19,7 @@ public class SetEmailCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SetFirstSpawnCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SetFirstSpawnCommand.java index f77d66cf0..279941d79 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SetFirstSpawnCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SetFirstSpawnCommand.java @@ -17,6 +17,7 @@ public class SetFirstSpawnCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SetSpawnCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SetSpawnCommand.java index b198d112d..355763568 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SetSpawnCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SetSpawnCommand.java @@ -17,6 +17,7 @@ public class SetSpawnCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java index 9c39ade5d..67854f87b 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java @@ -17,6 +17,7 @@ public class SpawnCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java index d321e172a..bbbf89990 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java @@ -17,6 +17,7 @@ public class SwitchAntiBotCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java index d1facf7da..2dcde4ab0 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java @@ -29,6 +29,7 @@ public class UnregisterCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java index 8ef85db05..a07a0f88e 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/VersionCommand.java @@ -18,6 +18,7 @@ public class VersionCommand extends ExecutableCommand { * @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 @@ -70,6 +71,7 @@ public class VersionCommand extends ExecutableCommand { * Check whether a player is online. * * @param minecraftName The Minecraft player name. + * * @return True if the player is online, false otherwise. */ private boolean isPlayerOnline(String minecraftName) { diff --git a/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java b/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java index bb5495ea4..ce8874db4 100644 --- a/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java @@ -20,6 +20,7 @@ public class CaptchaCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java b/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java index 5c60a71bf..c3c7a0e3c 100644 --- a/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java @@ -18,6 +18,7 @@ public class ConverterCommand extends ExecutableCommand { * @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 @@ -104,6 +105,7 @@ public class ConverterCommand extends ExecutableCommand { * Method fromName. * * @param name String + * * @return ConvertType */ public static ConvertType fromName(String name) { diff --git a/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java index b82e87144..dd5192ede 100644 --- a/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java @@ -18,6 +18,7 @@ public class UnregisterCommand extends ExecutableCommand { * @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 diff --git a/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java b/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java index db49a5671..90a9c7716 100644 --- a/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java +++ b/src/main/java/fr/xephi/authme/command/help/HelpSyntaxHelper.java @@ -23,6 +23,7 @@ public final class HelpSyntaxHelper { * @param commandReference The reference of the command. * @param alternativeLabel The alternative label to use for this command syntax. * @param highlight True to highlight the important parts of this command. + * * @return The command with proper syntax. */ public static String getCommandSyntax(CommandDescription commandDescription, CommandParts commandReference, diff --git a/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java index 915732665..6bd9a7343 100644 --- a/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java +++ b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java @@ -179,6 +179,7 @@ public class FlatToSqlite implements Converter { * Method saveAuth. * * @param s String + * * @return boolean */ private synchronized boolean saveAuth(String s) { diff --git a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java index e250f6b42..59e94f75f 100644 --- a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java +++ b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java @@ -73,6 +73,7 @@ public class vAuthFileReader { * Method isUUIDinstance. * * @param s String + * * @return boolean */ private boolean isUUIDinstance(String s) { @@ -85,6 +86,7 @@ public class vAuthFileReader { * Method getName. * * @param uuid UUID + * * @return String */ private String getName(UUID uuid) { diff --git a/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java b/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java index 974192771..fb3bd7246 100644 --- a/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java +++ b/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java @@ -75,6 +75,7 @@ public class xAuthToFlat { * Method getIdPlayer. * * @param id int + * * @return String */ public String getIdPlayer(int id) { @@ -129,6 +130,7 @@ public class xAuthToFlat { * Method getPassword. * * @param accountId int + * * @return String */ public String getPassword(int accountId) { diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 665d877c9..ce809500a 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -1,541 +1,561 @@ -package fr.xephi.authme.datasource; - -import fr.xephi.authme.AuthMe; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.util.Utils; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - */ -public class CacheDataSource implements DataSource { - - private final DataSource source; - private final ExecutorService exec; - private final ConcurrentHashMap cache = new ConcurrentHashMap<>(); - - /** - * Constructor for CacheDataSource. - * - * @param pl AuthMe - * @param src DataSource - */ - public CacheDataSource(final AuthMe pl, DataSource src) { - this.source = src; - this.exec = Executors.newCachedThreadPool(); - pl.setCanConnect(false); - - /* - * We need to load all players in cache ... It will took more time to - * load the server, but it will be much easier to check for an - * isAuthAvailable ! - */ - exec.execute(new Runnable() { - @Override - public void run() { - for (PlayerAuth auth : source.getAllAuths()) { - cache.put(auth.getNickname().toLowerCase(), auth); - } - pl.setCanConnect(true); - } - }); - } - - /** - * Method isAuthAvailable. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) - */ - @Override - public synchronized boolean isAuthAvailable(String user) { - return cache.containsKey(user.toLowerCase()); - } - - /** - * Method getAuth. - * - * @param user String - * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) - */ - @Override - public synchronized PlayerAuth getAuth(String user) { - user = user.toLowerCase(); - if (cache.containsKey(user)) { - return cache.get(user); - } - return null; - } - - /** - * Method saveAuth. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) - */ - @Override - public synchronized boolean saveAuth(final PlayerAuth auth) { - cache.put(auth.getNickname(), auth); - exec.execute(new Runnable() { - @Override - public void run() { - if (!source.saveAuth(auth)) { - cache.remove(auth.getNickname()); - } - } - }); - return true; - } - - /** - * Method updatePassword. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) - */ - @Override - public synchronized boolean updatePassword(final PlayerAuth auth) { - if (!cache.containsKey(auth.getNickname())) { - return false; - } - final String oldHash = cache.get(auth.getNickname()).getHash(); - cache.get(auth.getNickname()).setHash(auth.getHash()); - exec.execute(new Runnable() { - @Override - public void run() { - if (!source.updatePassword(auth)) { - if (cache.containsKey(auth.getNickname())) { - cache.get(auth.getNickname()).setHash(oldHash); - } - } - } - }); - return true; - } - - /** - * Method updateSession. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) - */ - @Override - public boolean updateSession(final PlayerAuth auth) { - if (!cache.containsKey(auth.getNickname())) { - return false; - } - PlayerAuth cachedAuth = cache.get(auth.getNickname()); - final String oldIp = cachedAuth.getIp(); - final long oldLastLogin = cachedAuth.getLastLogin(); - final String oldRealName = cachedAuth.getRealName(); - - cachedAuth.setIp(auth.getIp()); - cachedAuth.setLastLogin(auth.getLastLogin()); - cachedAuth.setRealName(auth.getRealName()); - exec.execute(new Runnable() { - @Override - public void run() { - if (!source.updateSession(auth)) { - if (cache.containsKey(auth.getNickname())) { - PlayerAuth cachedAuth = cache.get(auth.getNickname()); - cachedAuth.setIp(oldIp); - cachedAuth.setLastLogin(oldLastLogin); - cachedAuth.setRealName(oldRealName); - } - } - } - }); - return true; - } - - /** - * Method updateQuitLoc. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) - */ - @Override - public boolean updateQuitLoc(final PlayerAuth auth) { - if (!cache.containsKey(auth.getNickname())) { - return false; - } - final PlayerAuth cachedAuth = cache.get(auth.getNickname()); - final double oldX = cachedAuth.getQuitLocX(); - final double oldY = cachedAuth.getQuitLocY(); - final double oldZ = cachedAuth.getQuitLocZ(); - final String oldWorld = cachedAuth.getWorld(); - - cachedAuth.setQuitLocX(auth.getQuitLocX()); - cachedAuth.setQuitLocY(auth.getQuitLocY()); - cachedAuth.setQuitLocZ(auth.getQuitLocZ()); - cachedAuth.setWorld(auth.getWorld()); - exec.execute(new Runnable() { - @Override - public void run() { - if (!source.updateQuitLoc(auth)) { - if (cache.containsKey(auth.getNickname())) { - PlayerAuth cachedAuth = cache.get(auth.getNickname()); - cachedAuth.setQuitLocX(oldX); - cachedAuth.setQuitLocY(oldY); - cachedAuth.setQuitLocZ(oldZ); - cachedAuth.setWorld(oldWorld); - } - } - } - }); - return true; - } - - /** - * Method getIps. - * - * @param ip String - * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) - */ - @Override - public int getIps(String ip) { - int count = 0; - for (Map.Entry p : cache.entrySet()) { - if (p.getValue().getIp().equals(ip)) { - count++; - } - } - return count; - } - - /** - * Method purgeDatabase. - * - * @param until long - * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) - */ - @Override - public int purgeDatabase(long until) { - int cleared = source.purgeDatabase(until); - if (cleared > 0) { - for (PlayerAuth auth : cache.values()) { - if (auth.getLastLogin() < until) { - cache.remove(auth.getNickname()); - } - } - } - return cleared; - } - - /** - * Method autoPurgeDatabase. - * - * @param until long - * @return List * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) - */ - @Override - public List autoPurgeDatabase(long until) { - List cleared = source.autoPurgeDatabase(until); - if (cleared.size() > 0) { - for (PlayerAuth auth : cache.values()) { - if (auth.getLastLogin() < until) { - cache.remove(auth.getNickname()); - } - } - } - return cleared; - } - - /** - * Method removeAuth. - * - * @param username String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) - */ - @Override - public synchronized boolean removeAuth(String username) { - final String user = username.toLowerCase(); - final PlayerAuth auth = cache.get(user); - cache.remove(user); - exec.execute(new Runnable() { - @Override - public void run() { - if (!source.removeAuth(user)) { - cache.put(user, auth); - } - } - }); - return true; - } - - /** - * Method close. - * - * @see fr.xephi.authme.datasource.DataSource#close() - */ - @Override - public synchronized void close() { - exec.shutdown(); - source.close(); - } - - /** - * Method reload. - * - * @see fr.xephi.authme.datasource.DataSource#reload() - */ - @Override - public void reload() { - exec.execute(new Runnable() { - @Override - public void run() { - cache.clear(); - source.reload(); - for (Player player : Utils.getOnlinePlayers()) { - String user = player.getName().toLowerCase(); - if (PlayerCache.getInstance().isAuthenticated(user)) { - PlayerAuth auth = source.getAuth(user); - cache.put(user, auth); - } - } - } - }); - } - - /** - * Method updateEmail. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) - */ - @Override - public synchronized boolean updateEmail(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() { - return source.updateEmail(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updateSalt. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) - */ - @Override - public synchronized boolean updateSalt(final PlayerAuth auth) { - if (!cache.containsKey(auth.getNickname())) { - return false; - } - PlayerAuth cachedAuth = cache.get(auth.getNickname()); - final String oldSalt = cachedAuth.getSalt(); - cachedAuth.setSalt(auth.getSalt()); - exec.execute(new Runnable() { - @Override - public void run() { - if (!source.updateSalt(auth)) { - if (cache.containsKey(auth.getNickname())) { - cache.get(auth.getNickname()).setSalt(oldSalt); - } - } - } - }); - return true; - } - - /** - * Method getAllAuthsByName. - * - * @param auth PlayerAuth - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) - */ - @Override - public synchronized List getAllAuthsByName(PlayerAuth auth) { - List result = new ArrayList<>(); - for (Map.Entry stringPlayerAuthEntry : cache.entrySet()) { - PlayerAuth p = stringPlayerAuthEntry.getValue(); - if (p.getIp().equals(auth.getIp())) - result.add(p.getNickname()); - } - return result; - } - - /** - * Method getAllAuthsByIp. - * - * @param ip String - * @return List * @throws Exception * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) - */ - @Override - public synchronized List getAllAuthsByIp(final String ip) throws Exception { - return exec.submit(new Callable>() { - public List call() throws Exception { - return source.getAllAuthsByIp(ip); - } - }).get(); - } - - /** - * Method getAllAuthsByEmail. - * - * @param email String - * @return List * @throws Exception * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) - */ - @Override - public synchronized List getAllAuthsByEmail(final String email) throws Exception { - return exec.submit(new Callable>() { - public List call() throws Exception { - return source.getAllAuthsByEmail(email); - } - }).get(); - } - - /** - * Method purgeBanned. - * - * @param banned List - * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) - */ - @Override - public synchronized void purgeBanned(final List banned) { - exec.execute(new Runnable() { - @Override - public void run() { - source.purgeBanned(banned); - for (PlayerAuth auth : cache.values()) { - if (banned.contains(auth.getNickname())) { - cache.remove(auth.getNickname()); - } - } - } - }); - } - - /** - * Method getType. - * - * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() - */ - @Override - public DataSourceType getType() { - return source.getType(); - } - - /** - * Method isLogged. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) - */ - @Override - public boolean isLogged(String user) { - user = user.toLowerCase(); - return PlayerCache.getInstance().getCache().containsKey(user); - } - - /** - * Method setLogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setLogged(String) - */ - @Override - public void setLogged(final String user) { - exec.execute(new Runnable() { - @Override - public void run() { - source.setLogged(user.toLowerCase()); - } - }); - } - - /** - * Method setUnlogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) - */ - @Override - public void setUnlogged(final String user) { - exec.execute(new Runnable() { - @Override - public void run() { - source.setUnlogged(user.toLowerCase()); - } - }); - } - - /** - * Method purgeLogged. - * - * @see fr.xephi.authme.datasource.DataSource#purgeLogged() - */ - @Override - public void purgeLogged() { - exec.execute(new Runnable() { - @Override - public void run() { - source.purgeLogged(); - } - }); - } - - /** - * Method getAccountsRegistered. - * - * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() - */ - @Override - public int getAccountsRegistered() { - return cache.size(); - } - - /** - * Method updateName. - * - * @param oldone String - * @param newone String - * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) - */ - @Override - public void updateName(final String oldone, final String newone) { - if (cache.containsKey(oldone)) { - cache.put(newone, cache.get(oldone)); - cache.remove(oldone); - } - exec.execute(new Runnable() { - @Override - public void run() { - source.updateName(oldone, newone); - } - }); - } - - /** - * Method getAllAuths. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() - */ - @Override - public List getAllAuths() { - return new ArrayList<>(cache.values()); - } - - /** - * Method getLoggedPlayers. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() - */ - @Override - public List getLoggedPlayers() { - return new ArrayList<>(PlayerCache.getInstance().getCache().values()); - } -} +package fr.xephi.authme.datasource; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.util.Utils; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + */ +public class CacheDataSource implements DataSource { + + private final DataSource source; + private final ExecutorService exec; + private final ConcurrentHashMap cache = new ConcurrentHashMap<>(); + + /** + * Constructor for CacheDataSource. + * + * @param pl AuthMe + * @param src DataSource + */ + public CacheDataSource(final AuthMe pl, DataSource src) { + this.source = src; + this.exec = Executors.newCachedThreadPool(); + pl.setCanConnect(false); + + /* + * We need to load all players in cache ... It will took more time to + * load the server, but it will be much easier to check for an + * isAuthAvailable ! + */ + exec.execute(new Runnable() { + @Override + public void run() { + for (PlayerAuth auth : source.getAllAuths()) { + cache.put(auth.getNickname().toLowerCase(), auth); + } + pl.setCanConnect(true); + } + }); + } + + /** + * Method isAuthAvailable. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) + */ + @Override + public synchronized boolean isAuthAvailable(String user) { + return cache.containsKey(user.toLowerCase()); + } + + /** + * Method getAuth. + * + * @param user String + * + * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) + */ + @Override + public synchronized PlayerAuth getAuth(String user) { + user = user.toLowerCase(); + if (cache.containsKey(user)) { + return cache.get(user); + } + return null; + } + + /** + * Method saveAuth. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) + */ + @Override + public synchronized boolean saveAuth(final PlayerAuth auth) { + cache.put(auth.getNickname(), auth); + exec.execute(new Runnable() { + @Override + public void run() { + if (!source.saveAuth(auth)) { + cache.remove(auth.getNickname()); + } + } + }); + return true; + } + + /** + * Method updatePassword. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) + */ + @Override + public synchronized boolean updatePassword(final PlayerAuth auth) { + if (!cache.containsKey(auth.getNickname())) { + return false; + } + final String oldHash = cache.get(auth.getNickname()).getHash(); + cache.get(auth.getNickname()).setHash(auth.getHash()); + exec.execute(new Runnable() { + @Override + public void run() { + if (!source.updatePassword(auth)) { + if (cache.containsKey(auth.getNickname())) { + cache.get(auth.getNickname()).setHash(oldHash); + } + } + } + }); + return true; + } + + /** + * Method updateSession. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) + */ + @Override + public boolean updateSession(final PlayerAuth auth) { + if (!cache.containsKey(auth.getNickname())) { + return false; + } + PlayerAuth cachedAuth = cache.get(auth.getNickname()); + final String oldIp = cachedAuth.getIp(); + final long oldLastLogin = cachedAuth.getLastLogin(); + final String oldRealName = cachedAuth.getRealName(); + + cachedAuth.setIp(auth.getIp()); + cachedAuth.setLastLogin(auth.getLastLogin()); + cachedAuth.setRealName(auth.getRealName()); + exec.execute(new Runnable() { + @Override + public void run() { + if (!source.updateSession(auth)) { + if (cache.containsKey(auth.getNickname())) { + PlayerAuth cachedAuth = cache.get(auth.getNickname()); + cachedAuth.setIp(oldIp); + cachedAuth.setLastLogin(oldLastLogin); + cachedAuth.setRealName(oldRealName); + } + } + } + }); + return true; + } + + /** + * Method updateQuitLoc. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) + */ + @Override + public boolean updateQuitLoc(final PlayerAuth auth) { + if (!cache.containsKey(auth.getNickname())) { + return false; + } + final PlayerAuth cachedAuth = cache.get(auth.getNickname()); + final double oldX = cachedAuth.getQuitLocX(); + final double oldY = cachedAuth.getQuitLocY(); + final double oldZ = cachedAuth.getQuitLocZ(); + final String oldWorld = cachedAuth.getWorld(); + + cachedAuth.setQuitLocX(auth.getQuitLocX()); + cachedAuth.setQuitLocY(auth.getQuitLocY()); + cachedAuth.setQuitLocZ(auth.getQuitLocZ()); + cachedAuth.setWorld(auth.getWorld()); + exec.execute(new Runnable() { + @Override + public void run() { + if (!source.updateQuitLoc(auth)) { + if (cache.containsKey(auth.getNickname())) { + PlayerAuth cachedAuth = cache.get(auth.getNickname()); + cachedAuth.setQuitLocX(oldX); + cachedAuth.setQuitLocY(oldY); + cachedAuth.setQuitLocZ(oldZ); + cachedAuth.setWorld(oldWorld); + } + } + } + }); + return true; + } + + /** + * Method getIps. + * + * @param ip String + * + * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) + */ + @Override + public int getIps(String ip) { + int count = 0; + for (Map.Entry p : cache.entrySet()) { + if (p.getValue().getIp().equals(ip)) { + count++; + } + } + return count; + } + + /** + * Method purgeDatabase. + * + * @param until long + * + * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) + */ + @Override + public int purgeDatabase(long until) { + int cleared = source.purgeDatabase(until); + if (cleared > 0) { + for (PlayerAuth auth : cache.values()) { + if (auth.getLastLogin() < until) { + cache.remove(auth.getNickname()); + } + } + } + return cleared; + } + + /** + * Method autoPurgeDatabase. + * + * @param until long + * + * @return List * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) + */ + @Override + public List autoPurgeDatabase(long until) { + List cleared = source.autoPurgeDatabase(until); + if (cleared.size() > 0) { + for (PlayerAuth auth : cache.values()) { + if (auth.getLastLogin() < until) { + cache.remove(auth.getNickname()); + } + } + } + return cleared; + } + + /** + * Method removeAuth. + * + * @param username String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) + */ + @Override + public synchronized boolean removeAuth(String username) { + final String user = username.toLowerCase(); + final PlayerAuth auth = cache.get(user); + cache.remove(user); + exec.execute(new Runnable() { + @Override + public void run() { + if (!source.removeAuth(user)) { + cache.put(user, auth); + } + } + }); + return true; + } + + /** + * Method close. + * + * @see fr.xephi.authme.datasource.DataSource#close() + */ + @Override + public synchronized void close() { + exec.shutdown(); + source.close(); + } + + /** + * Method reload. + * + * @see fr.xephi.authme.datasource.DataSource#reload() + */ + @Override + public void reload() { + exec.execute(new Runnable() { + @Override + public void run() { + cache.clear(); + source.reload(); + for (Player player : Utils.getOnlinePlayers()) { + String user = player.getName().toLowerCase(); + if (PlayerCache.getInstance().isAuthenticated(user)) { + PlayerAuth auth = source.getAuth(user); + cache.put(user, auth); + } + } + } + }); + } + + /** + * Method updateEmail. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) + */ + @Override + public synchronized boolean updateEmail(final PlayerAuth auth) { + try { + return exec.submit(new Callable() { + public Boolean call() { + return source.updateEmail(auth); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method updateSalt. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) + */ + @Override + public synchronized boolean updateSalt(final PlayerAuth auth) { + if (!cache.containsKey(auth.getNickname())) { + return false; + } + PlayerAuth cachedAuth = cache.get(auth.getNickname()); + final String oldSalt = cachedAuth.getSalt(); + cachedAuth.setSalt(auth.getSalt()); + exec.execute(new Runnable() { + @Override + public void run() { + if (!source.updateSalt(auth)) { + if (cache.containsKey(auth.getNickname())) { + cache.get(auth.getNickname()).setSalt(oldSalt); + } + } + } + }); + return true; + } + + /** + * Method getAllAuthsByName. + * + * @param auth PlayerAuth + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) + */ + @Override + public synchronized List getAllAuthsByName(PlayerAuth auth) { + List result = new ArrayList<>(); + for (Map.Entry stringPlayerAuthEntry : cache.entrySet()) { + PlayerAuth p = stringPlayerAuthEntry.getValue(); + if (p.getIp().equals(auth.getIp())) + result.add(p.getNickname()); + } + return result; + } + + /** + * Method getAllAuthsByIp. + * + * @param ip String + * + * @return List * @throws Exception * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) + */ + @Override + public synchronized List getAllAuthsByIp(final String ip) throws Exception { + return exec.submit(new Callable>() { + public List call() throws Exception { + return source.getAllAuthsByIp(ip); + } + }).get(); + } + + /** + * Method getAllAuthsByEmail. + * + * @param email String + * + * @return List * @throws Exception * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) + */ + @Override + public synchronized List getAllAuthsByEmail(final String email) throws Exception { + return exec.submit(new Callable>() { + public List call() throws Exception { + return source.getAllAuthsByEmail(email); + } + }).get(); + } + + /** + * Method purgeBanned. + * + * @param banned List + * + * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) + */ + @Override + public synchronized void purgeBanned(final List banned) { + exec.execute(new Runnable() { + @Override + public void run() { + source.purgeBanned(banned); + for (PlayerAuth auth : cache.values()) { + if (banned.contains(auth.getNickname())) { + cache.remove(auth.getNickname()); + } + } + } + }); + } + + /** + * Method getType. + * + * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() + */ + @Override + public DataSourceType getType() { + return source.getType(); + } + + /** + * Method isLogged. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) + */ + @Override + public boolean isLogged(String user) { + user = user.toLowerCase(); + return PlayerCache.getInstance().getCache().containsKey(user); + } + + /** + * Method setLogged. + * + * @param user String + * + * @see fr.xephi.authme.datasource.DataSource#setLogged(String) + */ + @Override + public void setLogged(final String user) { + exec.execute(new Runnable() { + @Override + public void run() { + source.setLogged(user.toLowerCase()); + } + }); + } + + /** + * Method setUnlogged. + * + * @param user String + * + * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) + */ + @Override + public void setUnlogged(final String user) { + exec.execute(new Runnable() { + @Override + public void run() { + source.setUnlogged(user.toLowerCase()); + } + }); + } + + /** + * Method purgeLogged. + * + * @see fr.xephi.authme.datasource.DataSource#purgeLogged() + */ + @Override + public void purgeLogged() { + exec.execute(new Runnable() { + @Override + public void run() { + source.purgeLogged(); + } + }); + } + + /** + * Method getAccountsRegistered. + * + * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() + */ + @Override + public int getAccountsRegistered() { + return cache.size(); + } + + /** + * Method updateName. + * + * @param oldone String + * @param newone String + * + * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) + */ + @Override + public void updateName(final String oldone, final String newone) { + if (cache.containsKey(oldone)) { + cache.put(newone, cache.get(oldone)); + cache.remove(oldone); + } + exec.execute(new Runnable() { + @Override + public void run() { + source.updateName(oldone, newone); + } + }); + } + + /** + * Method getAllAuths. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() + */ + @Override + public List getAllAuths() { + return new ArrayList<>(cache.values()); + } + + /** + * Method getLoggedPlayers. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() + */ + @Override + public List getLoggedPlayers() { + return new ArrayList<>(PlayerCache.getInstance().getCache().values()); + } +} diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index de7d37e3e..6a2f387e8 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -1,210 +1,226 @@ -package fr.xephi.authme.datasource; - -import fr.xephi.authme.cache.auth.PlayerAuth; - -import java.util.List; - -/** - */ -public interface DataSource { - - /** - * Method isAuthAvailable. - * - * @param user String - * @return boolean - */ - boolean isAuthAvailable(String user); - - /** - * Method getAuth. - * - * @param user String - * @return PlayerAuth - */ - PlayerAuth getAuth(String user); - - /** - * Method saveAuth. - * - * @param auth PlayerAuth - * @return boolean - */ - boolean saveAuth(PlayerAuth auth); - - /** - * Method updateSession. - * - * @param auth PlayerAuth - * @return boolean - */ - boolean updateSession(PlayerAuth auth); - - /** - * Method updatePassword. - * - * @param auth PlayerAuth - * @return boolean - */ - boolean updatePassword(PlayerAuth auth); - - /** - * Method purgeDatabase. - * - * @param until long - * @return int - */ - int purgeDatabase(long until); - - /** - * Method autoPurgeDatabase. - * - * @param until long - * @return List - */ - List autoPurgeDatabase(long until); - - /** - * Method removeAuth. - * - * @param user String - * @return boolean - */ - boolean removeAuth(String user); - - /** - * Method updateQuitLoc. - * - * @param auth PlayerAuth - * @return boolean - */ - boolean updateQuitLoc(PlayerAuth auth); - - /** - * Method getIps. - * - * @param ip String - * @return int - */ - int getIps(String ip); - - /** - * Method getAllAuthsByName. - * - * @param auth PlayerAuth - * @return List - */ - List getAllAuthsByName(PlayerAuth auth); - - /** - * Method getAllAuthsByIp. - * - * @param ip String - * @return List * @throws Exception - */ - List getAllAuthsByIp(String ip) throws Exception; - - /** - * Method getAllAuthsByEmail. - * - * @param email String - * @return List * @throws Exception - */ - List getAllAuthsByEmail(String email) throws Exception; - - /** - * Method updateEmail. - * - * @param auth PlayerAuth - * @return boolean - */ - boolean updateEmail(PlayerAuth auth); - - /** - * Method updateSalt. - * - * @param auth PlayerAuth - * @return boolean - */ - boolean updateSalt(PlayerAuth auth); - - void close(); - - void reload(); - - /** - * Method purgeBanned. - * - * @param banned List - */ - void purgeBanned(List banned); - - /** - * Method getType. - * - * @return DataSourceType - */ - DataSourceType getType(); - - /** - * Method isLogged. - * - * @param user String - * @return boolean - */ - boolean isLogged(String user); - - /** - * Method setLogged. - * - * @param user String - */ - void setLogged(String user); - - /** - * Method setUnlogged. - * - * @param user String - */ - void setUnlogged(String user); - - void purgeLogged(); - - /** - * Method getAccountsRegistered. - * - * @return int - */ - int getAccountsRegistered(); - - /** - * Method updateName. - * - * @param oldone String - * @param newone String - */ - void updateName(String oldone, String newone); - - /** - * Method getAllAuths. - * - * @return List - */ - List getAllAuths(); - - /** - * Method getLoggedPlayers. - * - * @return List - */ - List getLoggedPlayers(); - - /** - */ - enum DataSourceType { - MYSQL, - FILE, - SQLITE - } - -} +package fr.xephi.authme.datasource; + +import fr.xephi.authme.cache.auth.PlayerAuth; + +import java.util.List; + +/** + */ +public interface DataSource { + + /** + * Method isAuthAvailable. + * + * @param user String + * + * @return boolean + */ + boolean isAuthAvailable(String user); + + /** + * Method getAuth. + * + * @param user String + * + * @return PlayerAuth + */ + PlayerAuth getAuth(String user); + + /** + * Method saveAuth. + * + * @param auth PlayerAuth + * + * @return boolean + */ + boolean saveAuth(PlayerAuth auth); + + /** + * Method updateSession. + * + * @param auth PlayerAuth + * + * @return boolean + */ + boolean updateSession(PlayerAuth auth); + + /** + * Method updatePassword. + * + * @param auth PlayerAuth + * + * @return boolean + */ + boolean updatePassword(PlayerAuth auth); + + /** + * Method purgeDatabase. + * + * @param until long + * + * @return int + */ + int purgeDatabase(long until); + + /** + * Method autoPurgeDatabase. + * + * @param until long + * + * @return List + */ + List autoPurgeDatabase(long until); + + /** + * Method removeAuth. + * + * @param user String + * + * @return boolean + */ + boolean removeAuth(String user); + + /** + * Method updateQuitLoc. + * + * @param auth PlayerAuth + * + * @return boolean + */ + boolean updateQuitLoc(PlayerAuth auth); + + /** + * Method getIps. + * + * @param ip String + * + * @return int + */ + int getIps(String ip); + + /** + * Method getAllAuthsByName. + * + * @param auth PlayerAuth + * + * @return List + */ + List getAllAuthsByName(PlayerAuth auth); + + /** + * Method getAllAuthsByIp. + * + * @param ip String + * + * @return List * @throws Exception + */ + List getAllAuthsByIp(String ip) throws Exception; + + /** + * Method getAllAuthsByEmail. + * + * @param email String + * + * @return List * @throws Exception + */ + List getAllAuthsByEmail(String email) throws Exception; + + /** + * Method updateEmail. + * + * @param auth PlayerAuth + * + * @return boolean + */ + boolean updateEmail(PlayerAuth auth); + + /** + * Method updateSalt. + * + * @param auth PlayerAuth + * + * @return boolean + */ + boolean updateSalt(PlayerAuth auth); + + void close(); + + void reload(); + + /** + * Method purgeBanned. + * + * @param banned List + */ + void purgeBanned(List banned); + + /** + * Method getType. + * + * @return DataSourceType + */ + DataSourceType getType(); + + /** + * Method isLogged. + * + * @param user String + * + * @return boolean + */ + boolean isLogged(String user); + + /** + * Method setLogged. + * + * @param user String + */ + void setLogged(String user); + + /** + * Method setUnlogged. + * + * @param user String + */ + void setUnlogged(String user); + + void purgeLogged(); + + /** + * Method getAccountsRegistered. + * + * @return int + */ + int getAccountsRegistered(); + + /** + * Method updateName. + * + * @param oldone String + * @param newone String + */ + void updateName(String oldone, String newone); + + /** + * Method getAllAuths. + * + * @return List + */ + List getAllAuths(); + + /** + * Method getLoggedPlayers. + * + * @return List + */ + List getLoggedPlayers(); + + /** + */ + enum DataSourceType { + MYSQL, + FILE, + SQLITE + } + +} diff --git a/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java b/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java index 59bef4d8e..3d2bd546f 100644 --- a/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java +++ b/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java @@ -1,493 +1,513 @@ -package fr.xephi.authme.datasource; - -import fr.xephi.authme.cache.auth.PlayerAuth; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - */ -public class DatabaseCalls implements DataSource { - - private final ExecutorService exec; - private DataSource database; - - /** - * Constructor for DatabaseCalls. - * - * @param database DataSource - */ - public DatabaseCalls(DataSource database) { - this.database = database; - this.exec = Executors.newCachedThreadPool(); - } - - /** - * Method isAuthAvailable. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) - */ - @Override - public synchronized boolean isAuthAvailable(final String user) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.isAuthAvailable(user); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method getAuth. - * - * @param user String - * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) - */ - @Override - public synchronized PlayerAuth getAuth(final String user) { - try { - return exec.submit(new Callable() { - public PlayerAuth call() throws Exception { - return database.getAuth(user); - } - }).get(); - } catch (Exception e) { - return null; - } - } - - /** - * Method saveAuth. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) - */ - @Override - public synchronized boolean saveAuth(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.saveAuth(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updateSession. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) - */ - @Override - public synchronized boolean updateSession(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateSession(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updatePassword. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) - */ - @Override - public synchronized boolean updatePassword(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updatePassword(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method purgeDatabase. - * - * @param until long - * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) - */ - @Override - public synchronized int purgeDatabase(final long until) { - try { - return exec.submit(new Callable() { - public Integer call() throws Exception { - return database.purgeDatabase(until); - } - }).get(); - } catch (Exception e) { - return -1; - } - } - - /** - * Method autoPurgeDatabase. - * - * @param until long - * @return List * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) - */ - @Override - public synchronized List autoPurgeDatabase(final long until) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.autoPurgeDatabase(until); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method removeAuth. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) - */ - @Override - public synchronized boolean removeAuth(final String user) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.removeAuth(user); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updateQuitLoc. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) - */ - @Override - public synchronized boolean updateQuitLoc(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateQuitLoc(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method getIps. - * - * @param ip String - * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) - */ - @Override - public synchronized int getIps(final String ip) { - try { - return exec.submit(new Callable() { - - public Integer call() throws Exception { - return database.getIps(ip); - } - }).get(); - } catch (Exception e) { - return -1; - } - } - - /** - * Method getAllAuthsByName. - * - * @param auth PlayerAuth - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) - */ - @Override - public synchronized List getAllAuthsByName(final PlayerAuth auth) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuthsByName(auth); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method getAllAuthsByIp. - * - * @param ip String - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) - */ - @Override - public synchronized List getAllAuthsByIp(final String ip) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuthsByIp(ip); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method getAllAuthsByEmail. - * - * @param email String - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) - */ - @Override - public synchronized List getAllAuthsByEmail(final String email) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuthsByEmail(email); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method updateEmail. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) - */ - @Override - public synchronized boolean updateEmail(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateEmail(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updateSalt. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) - */ - @Override - public synchronized boolean updateSalt(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateSalt(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method close. - * - * @see fr.xephi.authme.datasource.DataSource#close() - */ - @Override - public synchronized void close() { - exec.shutdown(); - database.close(); - } - - /** - * Method reload. - * - * @see fr.xephi.authme.datasource.DataSource#reload() - */ - @Override - public synchronized void reload() { - database.reload(); - } - - /** - * Method purgeBanned. - * - * @param banned List - * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) - */ - @Override - public synchronized void purgeBanned(final List banned) { - new Thread(new Runnable() { - public synchronized void run() { - database.purgeBanned(banned); - } - }).start(); - } - - /** - * Method getType. - * - * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() - */ - @Override - public synchronized DataSourceType getType() { - return database.getType(); - } - - /** - * Method isLogged. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) - */ - @Override - public synchronized boolean isLogged(final String user) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.isLogged(user); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method setLogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setLogged(String) - */ - @Override - public synchronized void setLogged(final String user) { - exec.execute(new Runnable() { - public synchronized void run() { - database.setLogged(user); - } - }); - } - - /** - * Method setUnlogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) - */ - @Override - public synchronized void setUnlogged(final String user) { - exec.execute(new Runnable() { - public synchronized void run() { - database.setUnlogged(user); - } - }); - } - - /** - * Method purgeLogged. - * - * @see fr.xephi.authme.datasource.DataSource#purgeLogged() - */ - @Override - public synchronized void purgeLogged() { - exec.execute(new Runnable() { - public synchronized void run() { - database.purgeLogged(); - } - }); - } - - /** - * Method getAccountsRegistered. - * - * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() - */ - @Override - public synchronized int getAccountsRegistered() { - try { - return exec.submit(new Callable() { - public Integer call() throws Exception { - return database.getAccountsRegistered(); - } - }).get(); - } catch (Exception e) { - return -1; - } - } - - /** - * Method updateName. - * - * @param oldone String - * @param newone String - * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) - */ - @Override - public synchronized void updateName(final String oldone, final String newone) { - exec.execute(new Runnable() { - public synchronized void run() { - database.updateName(oldone, newone); - } - }); - } - - /** - * Method getAllAuths. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() - */ - @Override - public synchronized List getAllAuths() { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuths(); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method getLoggedPlayers. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() - */ - @Override - public List getLoggedPlayers() { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getLoggedPlayers(); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - -} +package fr.xephi.authme.datasource; + +import fr.xephi.authme.cache.auth.PlayerAuth; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + */ +public class DatabaseCalls implements DataSource { + + private final ExecutorService exec; + private DataSource database; + + /** + * Constructor for DatabaseCalls. + * + * @param database DataSource + */ + public DatabaseCalls(DataSource database) { + this.database = database; + this.exec = Executors.newCachedThreadPool(); + } + + /** + * Method isAuthAvailable. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) + */ + @Override + public synchronized boolean isAuthAvailable(final String user) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.isAuthAvailable(user); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method getAuth. + * + * @param user String + * + * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) + */ + @Override + public synchronized PlayerAuth getAuth(final String user) { + try { + return exec.submit(new Callable() { + public PlayerAuth call() throws Exception { + return database.getAuth(user); + } + }).get(); + } catch (Exception e) { + return null; + } + } + + /** + * Method saveAuth. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) + */ + @Override + public synchronized boolean saveAuth(final PlayerAuth auth) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.saveAuth(auth); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method updateSession. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) + */ + @Override + public synchronized boolean updateSession(final PlayerAuth auth) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.updateSession(auth); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method updatePassword. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) + */ + @Override + public synchronized boolean updatePassword(final PlayerAuth auth) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.updatePassword(auth); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method purgeDatabase. + * + * @param until long + * + * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) + */ + @Override + public synchronized int purgeDatabase(final long until) { + try { + return exec.submit(new Callable() { + public Integer call() throws Exception { + return database.purgeDatabase(until); + } + }).get(); + } catch (Exception e) { + return -1; + } + } + + /** + * Method autoPurgeDatabase. + * + * @param until long + * + * @return List * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) + */ + @Override + public synchronized List autoPurgeDatabase(final long until) { + try { + return exec.submit(new Callable>() { + public List call() throws Exception { + return database.autoPurgeDatabase(until); + } + }).get(); + } catch (Exception e) { + return new ArrayList<>(); + } + } + + /** + * Method removeAuth. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) + */ + @Override + public synchronized boolean removeAuth(final String user) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.removeAuth(user); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method updateQuitLoc. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) + */ + @Override + public synchronized boolean updateQuitLoc(final PlayerAuth auth) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.updateQuitLoc(auth); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method getIps. + * + * @param ip String + * + * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) + */ + @Override + public synchronized int getIps(final String ip) { + try { + return exec.submit(new Callable() { + + public Integer call() throws Exception { + return database.getIps(ip); + } + }).get(); + } catch (Exception e) { + return -1; + } + } + + /** + * Method getAllAuthsByName. + * + * @param auth PlayerAuth + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) + */ + @Override + public synchronized List getAllAuthsByName(final PlayerAuth auth) { + try { + return exec.submit(new Callable>() { + public List call() throws Exception { + return database.getAllAuthsByName(auth); + } + }).get(); + } catch (Exception e) { + return new ArrayList<>(); + } + } + + /** + * Method getAllAuthsByIp. + * + * @param ip String + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) + */ + @Override + public synchronized List getAllAuthsByIp(final String ip) { + try { + return exec.submit(new Callable>() { + public List call() throws Exception { + return database.getAllAuthsByIp(ip); + } + }).get(); + } catch (Exception e) { + return new ArrayList<>(); + } + } + + /** + * Method getAllAuthsByEmail. + * + * @param email String + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) + */ + @Override + public synchronized List getAllAuthsByEmail(final String email) { + try { + return exec.submit(new Callable>() { + public List call() throws Exception { + return database.getAllAuthsByEmail(email); + } + }).get(); + } catch (Exception e) { + return new ArrayList<>(); + } + } + + /** + * Method updateEmail. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) + */ + @Override + public synchronized boolean updateEmail(final PlayerAuth auth) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.updateEmail(auth); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method updateSalt. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) + */ + @Override + public synchronized boolean updateSalt(final PlayerAuth auth) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.updateSalt(auth); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method close. + * + * @see fr.xephi.authme.datasource.DataSource#close() + */ + @Override + public synchronized void close() { + exec.shutdown(); + database.close(); + } + + /** + * Method reload. + * + * @see fr.xephi.authme.datasource.DataSource#reload() + */ + @Override + public synchronized void reload() { + database.reload(); + } + + /** + * Method purgeBanned. + * + * @param banned List + * + * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) + */ + @Override + public synchronized void purgeBanned(final List banned) { + new Thread(new Runnable() { + public synchronized void run() { + database.purgeBanned(banned); + } + }).start(); + } + + /** + * Method getType. + * + * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() + */ + @Override + public synchronized DataSourceType getType() { + return database.getType(); + } + + /** + * Method isLogged. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) + */ + @Override + public synchronized boolean isLogged(final String user) { + try { + return exec.submit(new Callable() { + public Boolean call() throws Exception { + return database.isLogged(user); + } + }).get(); + } catch (Exception e) { + return false; + } + } + + /** + * Method setLogged. + * + * @param user String + * + * @see fr.xephi.authme.datasource.DataSource#setLogged(String) + */ + @Override + public synchronized void setLogged(final String user) { + exec.execute(new Runnable() { + public synchronized void run() { + database.setLogged(user); + } + }); + } + + /** + * Method setUnlogged. + * + * @param user String + * + * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) + */ + @Override + public synchronized void setUnlogged(final String user) { + exec.execute(new Runnable() { + public synchronized void run() { + database.setUnlogged(user); + } + }); + } + + /** + * Method purgeLogged. + * + * @see fr.xephi.authme.datasource.DataSource#purgeLogged() + */ + @Override + public synchronized void purgeLogged() { + exec.execute(new Runnable() { + public synchronized void run() { + database.purgeLogged(); + } + }); + } + + /** + * Method getAccountsRegistered. + * + * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() + */ + @Override + public synchronized int getAccountsRegistered() { + try { + return exec.submit(new Callable() { + public Integer call() throws Exception { + return database.getAccountsRegistered(); + } + }).get(); + } catch (Exception e) { + return -1; + } + } + + /** + * Method updateName. + * + * @param oldone String + * @param newone String + * + * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) + */ + @Override + public synchronized void updateName(final String oldone, final String newone) { + exec.execute(new Runnable() { + public synchronized void run() { + database.updateName(oldone, newone); + } + }); + } + + /** + * Method getAllAuths. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() + */ + @Override + public synchronized List getAllAuths() { + try { + return exec.submit(new Callable>() { + public List call() throws Exception { + return database.getAllAuths(); + } + }).get(); + } catch (Exception e) { + return new ArrayList<>(); + } + } + + /** + * Method getLoggedPlayers. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() + */ + @Override + public List getLoggedPlayers() { + try { + return exec.submit(new Callable>() { + public List call() throws Exception { + return database.getLoggedPlayers(); + } + }).get(); + } catch (Exception e) { + return new ArrayList<>(); + } + } + +} diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index f03a67ad5..947848f10 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -48,6 +48,7 @@ public class FlatFile implements DataSource { * Method isAuthAvailable. * * @param user String + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) */ @Override @@ -83,6 +84,7 @@ public class FlatFile implements DataSource { * Method saveAuth. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) */ @Override @@ -112,6 +114,7 @@ public class FlatFile implements DataSource { * Method updatePassword. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) */ @Override @@ -177,6 +180,7 @@ public class FlatFile implements DataSource { * Method updateSession. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) */ @Override @@ -242,6 +246,7 @@ public class FlatFile implements DataSource { * Method updateQuitLoc. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) */ @Override @@ -286,6 +291,7 @@ public class FlatFile implements DataSource { * Method getIps. * * @param ip String + * * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) */ @Override @@ -322,6 +328,7 @@ public class FlatFile implements DataSource { * Method purgeDatabase. * * @param until long + * * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) */ @Override @@ -374,6 +381,7 @@ public class FlatFile implements DataSource { * Method autoPurgeDatabase. * * @param until long + * * @return List * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) */ @Override @@ -426,6 +434,7 @@ public class FlatFile implements DataSource { * Method removeAuth. * * @param user String + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) */ @Override @@ -476,6 +485,7 @@ public class FlatFile implements DataSource { * Method getAuth. * * @param user String + * * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) */ @Override @@ -542,6 +552,7 @@ public class FlatFile implements DataSource { * Method updateEmail. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) */ @Override @@ -586,6 +597,7 @@ public class FlatFile implements DataSource { * Method updateSalt. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) */ @Override @@ -597,6 +609,7 @@ public class FlatFile implements DataSource { * Method getAllAuthsByName. * * @param auth PlayerAuth + * * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) */ @Override @@ -633,6 +646,7 @@ public class FlatFile implements DataSource { * Method getAllAuthsByIp. * * @param ip String + * * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) */ @Override @@ -669,6 +683,7 @@ public class FlatFile implements DataSource { * Method getAllAuthsByEmail. * * @param email String + * * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) */ @Override @@ -705,6 +720,7 @@ public class FlatFile implements DataSource { * Method purgeBanned. * * @param banned List + * * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) */ @Override @@ -765,6 +781,7 @@ public class FlatFile implements DataSource { * Method isLogged. * * @param user String + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) */ @Override @@ -776,6 +793,7 @@ public class FlatFile implements DataSource { * Method setLogged. * * @param user String + * * @see fr.xephi.authme.datasource.DataSource#setLogged(String) */ @Override @@ -786,6 +804,7 @@ public class FlatFile implements DataSource { * Method setUnlogged. * * @param user String + * * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) */ @Override @@ -834,6 +853,7 @@ public class FlatFile implements DataSource { * * @param oldone String * @param newone String + * * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 71a8e27fb..57bd81a4a 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -218,6 +218,7 @@ public class MySQL implements DataSource { * Method isAuthAvailable. * * @param user String + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) */ @Override @@ -246,6 +247,7 @@ public class MySQL implements DataSource { * Method getAuth. * * @param user String + * * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) */ @Override @@ -305,6 +307,7 @@ public class MySQL implements DataSource { * Method saveAuth. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) */ @Override @@ -518,6 +521,7 @@ public class MySQL implements DataSource { * Method updatePassword. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) */ @Override @@ -569,6 +573,7 @@ public class MySQL implements DataSource { * Method updateSession. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) */ @Override @@ -598,6 +603,7 @@ public class MySQL implements DataSource { * Method purgeDatabase. * * @param until long + * * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) */ @Override @@ -623,6 +629,7 @@ public class MySQL implements DataSource { * Method autoPurgeDatabase. * * @param until long + * * @return List * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) */ @Override @@ -659,6 +666,7 @@ public class MySQL implements DataSource { * Method removeAuth. * * @param user String + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) */ @Override @@ -702,6 +710,7 @@ public class MySQL implements DataSource { * Method updateQuitLoc. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) */ @Override @@ -732,6 +741,7 @@ public class MySQL implements DataSource { * Method getIps. * * @param ip String + * * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) */ @Override @@ -764,6 +774,7 @@ public class MySQL implements DataSource { * Method updateEmail. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) */ @Override @@ -792,6 +803,7 @@ public class MySQL implements DataSource { * Method updateSalt. * * @param auth PlayerAuth + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) */ @Override @@ -869,6 +881,7 @@ public class MySQL implements DataSource { * Method getAllAuthsByName. * * @param auth PlayerAuth + * * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) */ @Override @@ -901,6 +914,7 @@ public class MySQL implements DataSource { * Method getAllAuthsByIp. * * @param ip String + * * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) */ @Override @@ -933,6 +947,7 @@ public class MySQL implements DataSource { * Method getAllAuthsByEmail. * * @param email String + * * @return List * @throws SQLException * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) */ @Override @@ -961,6 +976,7 @@ public class MySQL implements DataSource { * Method purgeBanned. * * @param banned List + * * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) */ @Override @@ -997,6 +1013,7 @@ public class MySQL implements DataSource { * Method isLogged. * * @param user String + * * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) */ @Override @@ -1027,6 +1044,7 @@ public class MySQL implements DataSource { * Method setLogged. * * @param user String + * * @see fr.xephi.authme.datasource.DataSource#setLogged(String) */ @Override @@ -1052,6 +1070,7 @@ public class MySQL implements DataSource { * Method setUnlogged. * * @param user String + * * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) */ @Override @@ -1132,6 +1151,7 @@ public class MySQL implements DataSource { * * @param oldone String * @param newone String + * * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 7d9ed0348..c50007d07 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -1,836 +1,856 @@ -package fr.xephi.authme.datasource; - -import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.settings.Settings; - -import java.sql.*; -import java.util.ArrayList; -import java.util.List; - -/** - */ -public class SQLite implements DataSource { - - private String database; - private String tableName; - private String columnName; - private String columnPassword; - private String columnIp; - private String columnLastLogin; - private String columnSalt; - private String columnGroup; - private String lastlocX; - private String lastlocY; - private String lastlocZ; - private String lastlocWorld; - private String columnEmail; - private String columnID; - private Connection con; - private String columnLogged; - private String columnRealName; - - /** - * Constructor for SQLite. - * - * @throws ClassNotFoundException * @throws SQLException - */ - public SQLite() throws ClassNotFoundException, SQLException { - this.database = Settings.getMySQLDatabase; - this.tableName = Settings.getMySQLTablename; - this.columnName = Settings.getMySQLColumnName; - this.columnPassword = Settings.getMySQLColumnPassword; - this.columnIp = Settings.getMySQLColumnIp; - this.columnLastLogin = Settings.getMySQLColumnLastLogin; - this.columnSalt = Settings.getMySQLColumnSalt; - this.columnGroup = Settings.getMySQLColumnGroup; - this.lastlocX = Settings.getMySQLlastlocX; - this.lastlocY = Settings.getMySQLlastlocY; - this.lastlocZ = Settings.getMySQLlastlocZ; - this.lastlocWorld = Settings.getMySQLlastlocWorld; - this.columnEmail = Settings.getMySQLColumnEmail; - this.columnID = Settings.getMySQLColumnId; - this.columnLogged = Settings.getMySQLColumnLogged; - this.columnRealName = Settings.getMySQLColumnRealName; - - try { - this.connect(); - this.setup(); - } catch (ClassNotFoundException | SQLException cnf) { - ConsoleLogger.showError("Can't use SQLITE... !"); - throw cnf; - } - } - - /** - * Method connect. - * - * @throws ClassNotFoundException * @throws SQLException - */ - private synchronized void connect() throws ClassNotFoundException, SQLException { - Class.forName("org.sqlite.JDBC"); - ConsoleLogger.info("SQLite driver loaded"); - this.con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db"); - - } - - /** - * Method setup. - * - * @throws SQLException - */ - private synchronized void setup() throws SQLException { - Statement st = null; - ResultSet rs = null; - try { - st = con.createStatement(); - st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); - rs = con.getMetaData().getColumns(null, null, tableName, columnPassword); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnIp); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT DEFAULT '0';"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';"); - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';"); - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnLogged); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';"); - } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, columnRealName); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player';"); - } - } finally { - close(rs); - close(st); - } - ConsoleLogger.info("SQLite Setup finished"); - } - - /** - * Method isAuthAvailable. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) - */ - @Override - public synchronized boolean isAuthAvailable(String user) { - PreparedStatement pst = null; - ResultSet rs = null; - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); - pst.setString(1, user); - rs = pst.executeQuery(); - return rs.next(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(rs); - close(pst); - } - } - - /** - * Method getAuth. - * - * @param user String - * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) - */ - @Override - public synchronized PlayerAuth getAuth(String user) { - PreparedStatement pst = null; - ResultSet rs = null; - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); - pst.setString(1, user); - rs = pst.executeQuery(); - if (rs.next()) { - if (rs.getString(columnIp).isEmpty()) { - return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - if (!columnSalt.isEmpty()) { - return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } - } - } else { - return null; - } - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return null; - } finally { - close(rs); - close(pst); - } - } - - /** - * Method saveAuth. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) - */ - @Override - public synchronized boolean saveAuth(PlayerAuth auth) { - PreparedStatement pst = null; - try { - if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) { - pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);"); - pst.setString(1, auth.getNickname()); - pst.setString(2, auth.getHash()); - pst.setString(3, auth.getIp()); - pst.setLong(4, auth.getLastLogin()); - pst.setString(5, auth.getRealName()); - pst.executeUpdate(); - } else { - pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + "," + columnRealName + ") VALUES (?,?,?,?,?,?);"); - pst.setString(1, auth.getNickname()); - pst.setString(2, auth.getHash()); - pst.setString(3, auth.getIp()); - pst.setLong(4, auth.getLastLogin()); - pst.setString(5, auth.getSalt()); - pst.setString(6, auth.getRealName()); - pst.executeUpdate(); - } - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - } - return true; - } - - /** - * Method updatePassword. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) - */ - @Override - public synchronized boolean updatePassword(PlayerAuth auth) { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE " + columnName + "=?;"); - pst.setString(1, auth.getHash()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - } - return true; - } - - /** - * Method updateSession. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) - */ - @Override - public boolean updateSession(PlayerAuth auth) { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;"); - pst.setString(1, auth.getIp()); - pst.setLong(2, auth.getLastLogin()); - pst.setString(3, auth.getRealName()); - pst.setString(4, auth.getNickname()); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - } - return true; - } - - /** - * Method purgeDatabase. - * - * @param until long - * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) - */ - @Override - public int purgeDatabase(long until) { - PreparedStatement pst = null; - try { - - pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) - */ - @Override - public List autoPurgeDatabase(long until) { - PreparedStatement pst = null; - ResultSet rs = null; - List list = new ArrayList<>(); - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); - } finally { - close(rs); - close(pst); - } - } - - /** - * Method removeAuth. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) - */ - @Override - public synchronized boolean removeAuth(String user) { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); - pst.setString(1, user); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - } - return true; - } - - /** - * Method updateQuitLoc. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) - */ - @Override - public boolean updateQuitLoc(PlayerAuth auth) { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;"); - pst.setDouble(1, auth.getQuitLocX()); - pst.setDouble(2, auth.getQuitLocY()); - pst.setDouble(3, auth.getQuitLocZ()); - pst.setString(4, auth.getWorld()); - pst.setString(5, auth.getNickname()); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - } - return true; - } - - /** - * Method getIps. - * - * @param ip String - * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) - */ - @Override - public int getIps(String ip) { - PreparedStatement pst = null; - ResultSet rs = null; - int countIp = 0; - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); - pst.setString(1, ip); - rs = pst.executeQuery(); - while (rs.next()) { - countIp++; - } - return countIp; - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return 0; - } finally { - close(rs); - close(pst); - } - } - - /** - * Method updateEmail. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) - */ - @Override - public boolean updateEmail(PlayerAuth auth) { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;"); - pst.setString(1, auth.getEmail()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - } - return true; - } - - /** - * Method updateSalt. - * - * @param auth PlayerAuth - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) - */ - @Override - public boolean updateSalt(PlayerAuth auth) { - if (columnSalt.isEmpty()) { - return false; - } - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + "=? WHERE " + columnName + "=?;"); - pst.setString(1, auth.getSalt()); - pst.setString(2, auth.getNickname()); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(pst); - } - return true; - } - - /** - * Method close. - * - * @see fr.xephi.authme.datasource.DataSource#close() - */ - @Override - public synchronized void close() { - try { - con.close(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } - } - - /** - * Method reload. - * - * @see fr.xephi.authme.datasource.DataSource#reload() - */ - @Override - public void reload() { - } - - /** - * Method close. - * - * @param st Statement - */ - private void close(Statement st) { - if (st != null) { - try { - st.close(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } - } - } - - /** - * Method close. - * - * @param rs ResultSet - */ - private void close(ResultSet rs) { - if (rs != null) { - try { - rs.close(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } - } - } - - /** - * Method getAllAuthsByName. - * - * @param auth PlayerAuth - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) - */ - @Override - public List getAllAuthsByName(PlayerAuth auth) { - PreparedStatement pst = null; - ResultSet rs = null; - List countIp = new ArrayList<>(); - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); - pst.setString(1, auth.getIp()); - rs = pst.executeQuery(); - while (rs.next()) { - countIp.add(rs.getString(columnName)); - } - return countIp; - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return new ArrayList<>(); - } catch (NullPointerException npe) { - return new ArrayList<>(); - } finally { - close(rs); - close(pst); - } - } - - /** - * Method getAllAuthsByIp. - * - * @param ip String - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) - */ - @Override - public List getAllAuthsByIp(String ip) { - PreparedStatement pst = null; - ResultSet rs = null; - List countIp = new ArrayList<>(); - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); - pst.setString(1, ip); - rs = pst.executeQuery(); - while (rs.next()) { - countIp.add(rs.getString(columnName)); - } - return countIp; - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return new ArrayList<>(); - } catch (NullPointerException npe) { - return new ArrayList<>(); - } finally { - close(rs); - close(pst); - } - } - - /** - * Method getAllAuthsByEmail. - * - * @param email String - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) - */ - @Override - public List getAllAuthsByEmail(String email) { - PreparedStatement pst = null; - ResultSet rs = null; - List countEmail = new ArrayList<>(); - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); - pst.setString(1, email); - rs = pst.executeQuery(); - while (rs.next()) { - countEmail.add(rs.getString(columnName)); - } - return countEmail; - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return new ArrayList<>(); - } catch (NullPointerException npe) { - return new ArrayList<>(); - } finally { - close(rs); - close(pst); - } - } - - /** - * Method purgeBanned. - * - * @param banned List - * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) - */ - @Override - public void purgeBanned(List banned) { - PreparedStatement pst = null; - try { - for (String name : banned) { - pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); - pst.setString(1, name); - pst.executeUpdate(); - } - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - } - } - - /** - * Method getType. - * - * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() - */ - @Override - public DataSourceType getType() { - return DataSourceType.SQLITE; - } - - /** - * Method isLogged. - * - * @param user String - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) - */ - @Override - public boolean isLogged(String user) { - PreparedStatement pst = null; - ResultSet rs = null; - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); - pst.setString(1, user); - rs = pst.executeQuery(); - if (rs.next()) - return (rs.getInt(columnLogged) == 1); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return false; - } finally { - close(rs); - close(pst); - } - return false; - } - - /** - * Method setLogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setLogged(String) - */ - @Override - public void setLogged(String user) { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setInt(1, 1); - pst.setString(2, user); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - } - } - - /** - * Method setUnlogged. - * - * @param user String - * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) - */ - @Override - public void setUnlogged(String user) { - PreparedStatement pst = null; - if (user != null) - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); - pst.setInt(1, 0); - pst.setString(2, user); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - } - } - - /** - * Method purgeLogged. - * - * @see fr.xephi.authme.datasource.DataSource#purgeLogged() - */ - @Override - public void purgeLogged() { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;"); - pst.setInt(1, 0); - pst.setInt(2, 1); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - } - } - - /** - * Method getAccountsRegistered. - * - * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() - */ - @Override - public int getAccountsRegistered() { - int result = 0; - PreparedStatement pst = null; - ResultSet rs; - try { - pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";"); - rs = pst.executeQuery(); - if (rs != null && rs.next()) { - result = rs.getInt(1); - } - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return result; - } finally { - close(pst); - } - return result; - } - - /** - * Method updateName. - * - * @param oldone String - * @param newone String - * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) - */ - @Override - public void updateName(String oldone, String newone) { - PreparedStatement pst = null; - try { - pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;"); - pst.setString(1, newone); - pst.setString(2, oldone); - pst.executeUpdate(); - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - } finally { - close(pst); - } - } - - /** - * Method getAllAuths. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() - */ - @Override - public List getAllAuths() { - List auths = new ArrayList<>(); - PreparedStatement pst = null; - ResultSet rs; - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + ";"); - rs = pst.executeQuery(); - while (rs.next()) { - PlayerAuth pAuth; - if (rs.getString(columnIp).isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - if (!columnSalt.isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } - } - auths.add(pAuth); - } - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return auths; - } finally { - close(pst); - } - return auths; - } - - /** - * Method getLoggedPlayers. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() - */ - @Override - public List getLoggedPlayers() { - List auths = new ArrayList<>(); - PreparedStatement pst = null; - ResultSet rs; - try { - pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); - rs = pst.executeQuery(); - while (rs.next()) { - PlayerAuth pAuth; - if (rs.getString(columnIp).isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - if (!columnSalt.isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); - } - } - auths.add(pAuth); - } - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - return auths; - } finally { - close(pst); - } - return auths; - } -} +package fr.xephi.authme.datasource; + +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.settings.Settings; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +/** + */ +public class SQLite implements DataSource { + + private String database; + private String tableName; + private String columnName; + private String columnPassword; + private String columnIp; + private String columnLastLogin; + private String columnSalt; + private String columnGroup; + private String lastlocX; + private String lastlocY; + private String lastlocZ; + private String lastlocWorld; + private String columnEmail; + private String columnID; + private Connection con; + private String columnLogged; + private String columnRealName; + + /** + * Constructor for SQLite. + * + * @throws ClassNotFoundException * @throws SQLException + */ + public SQLite() throws ClassNotFoundException, SQLException { + this.database = Settings.getMySQLDatabase; + this.tableName = Settings.getMySQLTablename; + this.columnName = Settings.getMySQLColumnName; + this.columnPassword = Settings.getMySQLColumnPassword; + this.columnIp = Settings.getMySQLColumnIp; + this.columnLastLogin = Settings.getMySQLColumnLastLogin; + this.columnSalt = Settings.getMySQLColumnSalt; + this.columnGroup = Settings.getMySQLColumnGroup; + this.lastlocX = Settings.getMySQLlastlocX; + this.lastlocY = Settings.getMySQLlastlocY; + this.lastlocZ = Settings.getMySQLlastlocZ; + this.lastlocWorld = Settings.getMySQLlastlocWorld; + this.columnEmail = Settings.getMySQLColumnEmail; + this.columnID = Settings.getMySQLColumnId; + this.columnLogged = Settings.getMySQLColumnLogged; + this.columnRealName = Settings.getMySQLColumnRealName; + + try { + this.connect(); + this.setup(); + } catch (ClassNotFoundException | SQLException cnf) { + ConsoleLogger.showError("Can't use SQLITE... !"); + throw cnf; + } + } + + /** + * Method connect. + * + * @throws ClassNotFoundException * @throws SQLException + */ + private synchronized void connect() throws ClassNotFoundException, SQLException { + Class.forName("org.sqlite.JDBC"); + ConsoleLogger.info("SQLite driver loaded"); + this.con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db"); + + } + + /** + * Method setup. + * + * @throws SQLException + */ + private synchronized void setup() throws SQLException { + Statement st = null; + ResultSet rs = null; + try { + st = con.createStatement(); + st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));"); + rs = con.getMetaData().getColumns(null, null, tableName, columnPassword); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnIp); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT DEFAULT '0';"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnLogged); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';"); + } + rs.close(); + rs = con.getMetaData().getColumns(null, null, tableName, columnRealName); + if (!rs.next()) { + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player';"); + } + } finally { + close(rs); + close(st); + } + ConsoleLogger.info("SQLite Setup finished"); + } + + /** + * Method isAuthAvailable. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) + */ + @Override + public synchronized boolean isAuthAvailable(String user) { + PreparedStatement pst = null; + ResultSet rs = null; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); + pst.setString(1, user); + rs = pst.executeQuery(); + return rs.next(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + } + } + + /** + * Method getAuth. + * + * @param user String + * + * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) + */ + @Override + public synchronized PlayerAuth getAuth(String user) { + PreparedStatement pst = null; + ResultSet rs = null; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); + pst.setString(1, user); + rs = pst.executeQuery(); + if (rs.next()) { + if (rs.getString(columnIp).isEmpty()) { + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + if (!columnSalt.isEmpty()) { + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } + } + } else { + return null; + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return null; + } finally { + close(rs); + close(pst); + } + } + + /** + * Method saveAuth. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) + */ + @Override + public synchronized boolean saveAuth(PlayerAuth auth) { + PreparedStatement pst = null; + try { + if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.setString(5, auth.getRealName()); + pst.executeUpdate(); + } else { + pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + "," + columnRealName + ") VALUES (?,?,?,?,?,?);"); + pst.setString(1, auth.getNickname()); + pst.setString(2, auth.getHash()); + pst.setString(3, auth.getIp()); + pst.setLong(4, auth.getLastLogin()); + pst.setString(5, auth.getSalt()); + pst.setString(6, auth.getRealName()); + pst.executeUpdate(); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + /** + * Method updatePassword. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) + */ + @Override + public synchronized boolean updatePassword(PlayerAuth auth) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getHash()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + /** + * Method updateSession. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) + */ + @Override + public boolean updateSession(PlayerAuth auth) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getIp()); + pst.setLong(2, auth.getLastLogin()); + pst.setString(3, auth.getRealName()); + pst.setString(4, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + /** + * Method purgeDatabase. + * + * @param until long + * + * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) + */ + @Override + public int purgeDatabase(long until) { + PreparedStatement pst = null; + try { + + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) + */ + @Override + public List autoPurgeDatabase(long until) { + PreparedStatement pst = null; + ResultSet rs = null; + List list = new ArrayList<>(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); + } finally { + close(rs); + close(pst); + } + } + + /** + * Method removeAuth. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) + */ + @Override + public synchronized boolean removeAuth(String user) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, user); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + /** + * Method updateQuitLoc. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) + */ + @Override + public boolean updateQuitLoc(PlayerAuth auth) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;"); + pst.setDouble(1, auth.getQuitLocX()); + pst.setDouble(2, auth.getQuitLocY()); + pst.setDouble(3, auth.getQuitLocZ()); + pst.setString(4, auth.getWorld()); + pst.setString(5, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + /** + * Method getIps. + * + * @param ip String + * + * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) + */ + @Override + public int getIps(String ip) { + PreparedStatement pst = null; + ResultSet rs = null; + int countIp = 0; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); + pst.setString(1, ip); + rs = pst.executeQuery(); + while (rs.next()) { + countIp++; + } + return countIp; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return 0; + } finally { + close(rs); + close(pst); + } + } + + /** + * Method updateEmail. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) + */ + @Override + public boolean updateEmail(PlayerAuth auth) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getEmail()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + /** + * Method updateSalt. + * + * @param auth PlayerAuth + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) + */ + @Override + public boolean updateSalt(PlayerAuth auth) { + if (columnSalt.isEmpty()) { + return false; + } + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + "=? WHERE " + columnName + "=?;"); + pst.setString(1, auth.getSalt()); + pst.setString(2, auth.getNickname()); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(pst); + } + return true; + } + + /** + * Method close. + * + * @see fr.xephi.authme.datasource.DataSource#close() + */ + @Override + public synchronized void close() { + try { + con.close(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } + } + + /** + * Method reload. + * + * @see fr.xephi.authme.datasource.DataSource#reload() + */ + @Override + public void reload() { + } + + /** + * Method close. + * + * @param st Statement + */ + private void close(Statement st) { + if (st != null) { + try { + st.close(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } + } + } + + /** + * Method close. + * + * @param rs ResultSet + */ + private void close(ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } + } + } + + /** + * Method getAllAuthsByName. + * + * @param auth PlayerAuth + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) + */ + @Override + public List getAllAuthsByName(PlayerAuth auth) { + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList<>(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); + pst.setString(1, auth.getIp()); + rs = pst.executeQuery(); + while (rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList<>(); + } catch (NullPointerException npe) { + return new ArrayList<>(); + } finally { + close(rs); + close(pst); + } + } + + /** + * Method getAllAuthsByIp. + * + * @param ip String + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) + */ + @Override + public List getAllAuthsByIp(String ip) { + PreparedStatement pst = null; + ResultSet rs = null; + List countIp = new ArrayList<>(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); + pst.setString(1, ip); + rs = pst.executeQuery(); + while (rs.next()) { + countIp.add(rs.getString(columnName)); + } + return countIp; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList<>(); + } catch (NullPointerException npe) { + return new ArrayList<>(); + } finally { + close(rs); + close(pst); + } + } + + /** + * Method getAllAuthsByEmail. + * + * @param email String + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) + */ + @Override + public List getAllAuthsByEmail(String email) { + PreparedStatement pst = null; + ResultSet rs = null; + List countEmail = new ArrayList<>(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); + pst.setString(1, email); + rs = pst.executeQuery(); + while (rs.next()) { + countEmail.add(rs.getString(columnName)); + } + return countEmail; + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList<>(); + } catch (NullPointerException npe) { + return new ArrayList<>(); + } finally { + close(rs); + close(pst); + } + } + + /** + * Method purgeBanned. + * + * @param banned List + * + * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) + */ + @Override + public void purgeBanned(List banned) { + PreparedStatement pst = null; + try { + for (String name : banned) { + pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, name); + pst.executeUpdate(); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + } + } + + /** + * Method getType. + * + * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() + */ + @Override + public DataSourceType getType() { + return DataSourceType.SQLITE; + } + + /** + * Method isLogged. + * + * @param user String + * + * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) + */ + @Override + public boolean isLogged(String user) { + PreparedStatement pst = null; + ResultSet rs = null; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); + pst.setString(1, user); + rs = pst.executeQuery(); + if (rs.next()) + return (rs.getInt(columnLogged) == 1); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return false; + } finally { + close(rs); + close(pst); + } + return false; + } + + /** + * Method setLogged. + * + * @param user String + * + * @see fr.xephi.authme.datasource.DataSource#setLogged(String) + */ + @Override + public void setLogged(String user) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setInt(1, 1); + pst.setString(2, user); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + } + } + + /** + * Method setUnlogged. + * + * @param user String + * + * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) + */ + @Override + public void setUnlogged(String user) { + PreparedStatement pst = null; + if (user != null) + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); + pst.setInt(1, 0); + pst.setString(2, user); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + } + } + + /** + * Method purgeLogged. + * + * @see fr.xephi.authme.datasource.DataSource#purgeLogged() + */ + @Override + public void purgeLogged() { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;"); + pst.setInt(1, 0); + pst.setInt(2, 1); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + } + } + + /** + * Method getAccountsRegistered. + * + * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() + */ + @Override + public int getAccountsRegistered() { + int result = 0; + PreparedStatement pst = null; + ResultSet rs; + try { + pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";"); + rs = pst.executeQuery(); + if (rs != null && rs.next()) { + result = rs.getInt(1); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return result; + } finally { + close(pst); + } + return result; + } + + /** + * Method updateName. + * + * @param oldone String + * @param newone String + * + * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) + */ + @Override + public void updateName(String oldone, String newone) { + PreparedStatement pst = null; + try { + pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;"); + pst.setString(1, newone); + pst.setString(2, oldone); + pst.executeUpdate(); + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + } finally { + close(pst); + } + } + + /** + * Method getAllAuths. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() + */ + @Override + public List getAllAuths() { + List auths = new ArrayList<>(); + PreparedStatement pst = null; + ResultSet rs; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + ";"); + rs = pst.executeQuery(); + while (rs.next()) { + PlayerAuth pAuth; + if (rs.getString(columnIp).isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + if (!columnSalt.isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } + } + auths.add(pAuth); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } finally { + close(pst); + } + return auths; + } + + /** + * Method getLoggedPlayers. + * + * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() + */ + @Override + public List getLoggedPlayers() { + List auths = new ArrayList<>(); + PreparedStatement pst = null; + ResultSet rs; + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); + rs = pst.executeQuery(); + while (rs.next()) { + PlayerAuth pAuth; + if (rs.getString(columnIp).isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + if (!columnSalt.isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } + } + auths.add(pAuth); + } + } catch (SQLException ex) { + ConsoleLogger.showError(ex.getMessage()); + return auths; + } finally { + close(pst); + } + return auths; + } +} diff --git a/src/main/java/fr/xephi/authme/events/CustomEvent.java b/src/main/java/fr/xephi/authme/events/CustomEvent.java index daf19b314..0dfd00050 100644 --- a/src/main/java/fr/xephi/authme/events/CustomEvent.java +++ b/src/main/java/fr/xephi/authme/events/CustomEvent.java @@ -57,6 +57,7 @@ public class CustomEvent extends Event implements Cancellable { * Method setCancelled. * * @param cancelled boolean + * * @see org.bukkit.event.Cancellable#setCancelled(boolean) */ public void setCancelled(boolean cancelled) { diff --git a/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java b/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java index 65e7ce719..3a63078d5 100644 --- a/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java +++ b/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java @@ -27,6 +27,7 @@ public class BungeeCordMessage implements PluginMessageListener { * @param channel String * @param player Player * @param message byte[] + * * @see org.bukkit.plugin.messaging.PluginMessageListener#onPluginMessageReceived(String, Player, byte[]) */ @Override diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java index f44559260..96495fdb1 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java @@ -57,6 +57,7 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter { * Method onPacketSending. * * @param packetEvent PacketEvent + * * @see com.comphenix.protocol.events.PacketListener#onPacketSending(PacketEvent) */ @Override diff --git a/src/main/java/fr/xephi/authme/modules/ModuleManager.java b/src/main/java/fr/xephi/authme/modules/ModuleManager.java index 015c7e6c7..b6a718b66 100644 --- a/src/main/java/fr/xephi/authme/modules/ModuleManager.java +++ b/src/main/java/fr/xephi/authme/modules/ModuleManager.java @@ -33,6 +33,7 @@ public class ModuleManager { * Method isModuleEnabled. * * @param name String + * * @return boolean */ public boolean isModuleEnabled(String name) { @@ -47,6 +48,7 @@ public class ModuleManager { * Method isModuleEnabled. * * @param type Module.ModuleType + * * @return boolean */ public boolean isModuleEnabled(Module.ModuleType type) { @@ -61,6 +63,7 @@ public class ModuleManager { * Method getModule. * * @param name String + * * @return Module */ public Module getModule(String name) { @@ -75,6 +78,7 @@ public class ModuleManager { * Method getModule. * * @param type Module.ModuleType + * * @return Module */ public Module getModule(Module.ModuleType type) { diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index e56fc80f4..6614deaa4 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -318,6 +318,7 @@ public class PermissionsManager { * * @param player The player. * @param permsNode Permissions node. + * * @return True if the player has permission. */ public boolean hasPermission(Player player, String permsNode) { @@ -330,6 +331,7 @@ public class PermissionsManager { * @param player The player. * @param permsNode The permission node. * @param def Default returned if no permissions system is used. + * * @return True if the player has permission. */ public boolean hasPermission(Player player, String permsNode, boolean def) { @@ -425,6 +427,7 @@ public class PermissionsManager { * Get the permission groups of a player, if available. * * @param player The player. + * * @return Permission groups, or an empty list if this feature is not supported. */ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) @@ -489,6 +492,7 @@ public class PermissionsManager { * Get the primary group of a player, if available. * * @param player The player. + * * @return The name of the primary permission group. Or null. */ @SuppressWarnings("deprecation") @@ -542,6 +546,7 @@ public class PermissionsManager { * * @param player The player. * @param groupName The group name. + * * @return True if the player is in the specified group, false otherwise. * False is also returned if groups aren't supported by the used permissions system. */ @@ -599,6 +604,7 @@ public class PermissionsManager { * * @param player The player * @param groupName The name of the group. + * * @return True if succeed, false otherwise. * False is also returned if this feature isn't supported for the current permissions system. */ @@ -660,6 +666,7 @@ public class PermissionsManager { * * @param player The player * @param groupNames The name of the groups to add. + * * @return True if succeed, false otherwise. * False is also returned if this feature isn't supported for the current permissions system. */ @@ -683,6 +690,7 @@ public class PermissionsManager { * * @param player The player * @param groupName The name of the group. + * * @return True if succeed, false otherwise. * False is also returned if this feature isn't supported for the current permissions system. */ @@ -744,6 +752,7 @@ public class PermissionsManager { * * @param player The player * @param groupNames The name of the groups to add. + * * @return True if succeed, false otherwise. * False is also returned if this feature isn't supported for the current permissions system. */ @@ -768,6 +777,7 @@ public class PermissionsManager { * * @param player The player * @param groupName The name of the group. + * * @return True if succeed, false otherwise. * False is also returned if this feature isn't supported for the current permissions system. */ @@ -837,6 +847,7 @@ public class PermissionsManager { * * @param player The player * @param groupNames The name of the groups to set. + * * @return True if succeed, false otherwise. * False is also returned if this feature isn't supported for the current permissions system. */ @@ -870,6 +881,7 @@ public class PermissionsManager { * in it's primary group. All the subgroups are removed just fine. * * @param player The player to remove all groups from. + * * @return True if succeed, false otherwise. * False will also be returned if this feature isn't supported for the used permissions system. */ diff --git a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java index 2a679da7b..f5ed174d4 100644 --- a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java +++ b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java @@ -25,6 +25,7 @@ public class PasswordSecurity { * Method createSalt. * * @param length int + * * @return String * @throws NoSuchAlgorithmException */ public static String createSalt(int length) @@ -43,6 +44,7 @@ public class PasswordSecurity { * @param alg HashAlgorithm * @param password String * @param playerName String + * * @return String * @throws NoSuchAlgorithmException */ public static String getHash(HashAlgorithm alg, String password, @@ -146,6 +148,7 @@ public class PasswordSecurity { * @param password String * @param hash String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException */ public static boolean comparePasswordWithHash(String password, String hash, @@ -184,6 +187,7 @@ public class PasswordSecurity { * @param password String * @param hash String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException */ private static boolean compareWithAllEncryptionMethod(String password, diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java index 23412bf1b..0311d9f52 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java +++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java @@ -92,6 +92,7 @@ public class BCRYPT implements EncryptionMethod { * * @param d the byte array to encode * @param len the number of bytes to encode + * * @return base64-encoded string * @throws IllegalArgumentException if the length is invalid * @throws IllegalArgumentException */ private static String encode_base64(byte d[], int len) @@ -132,6 +133,7 @@ public class BCRYPT implements EncryptionMethod { * range-checking againt conversion table * * @param x the base64-encoded value + * * @return the decoded value of x */ private static byte char64(char x) { @@ -147,6 +149,7 @@ public class BCRYPT implements EncryptionMethod { * * @param s the string to decode * @param maxolen the maximum number of bytes to decode + * * @return an array containing the decoded bytes * @throws IllegalArgumentException if maxolen is invalid * @throws IllegalArgumentException */ private static byte[] decode_base64(String s, int maxolen) @@ -196,6 +199,7 @@ public class BCRYPT implements EncryptionMethod { * @param data the string to extract the data from * @param offp a "pointer" (as a one-entry array) to the current offset into * data + * * @return the next word of material from data */ private static int streamtoword(byte data[], int offp[]) { @@ -217,6 +221,7 @@ public class BCRYPT implements EncryptionMethod { * * @param password the password to hash * @param salt the salt to hash with (perhaps generated using BCrypt.gensalt) + * * @return the hashed password */ public static String hashpw(String password, String salt) { @@ -274,6 +279,7 @@ public class BCRYPT implements EncryptionMethod { * @param log_rounds the log2 of the number of rounds of hashing to apply - the * work factor therefore increases as 2**log_rounds. * @param random an instance of SecureRandom to use + * * @return an encoded salt value */ public static String gensalt(int log_rounds, SecureRandom random) { @@ -296,6 +302,7 @@ public class BCRYPT implements EncryptionMethod { * * @param log_rounds the log2 of the number of rounds of hashing to apply - the * work factor therefore increases as 2**log_rounds. + * * @return an encoded salt value */ public static String gensalt(int log_rounds) { @@ -317,6 +324,7 @@ public class BCRYPT implements EncryptionMethod { * * @param plaintext the plaintext password to verify * @param hashed the previously-hashed password + * * @return true if the passwords match, false otherwise */ public static boolean checkpw(String plaintext, String hashed) { @@ -330,6 +338,7 @@ public class BCRYPT implements EncryptionMethod { * @param text plaintext or hashed text * @param hashed the previously-hashed password * @param rounds number of rounds to hash the password + * * @return boolean */ public static boolean checkpw(String text, String hashed, int rounds) { @@ -355,6 +364,7 @@ public class BCRYPT implements EncryptionMethod { * * @param text String * @param salt String + * * @return String */ public static String getDoubleHash(String text, String salt) { @@ -467,6 +477,7 @@ public class BCRYPT implements EncryptionMethod { * @param salt the binary salt to hash with the password * @param log_rounds the binary logarithm of the number of rounds of hashing to * apply + * * @return an array containing the binary hashed password */ private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) { @@ -509,6 +520,7 @@ public class BCRYPT implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -523,6 +535,7 @@ public class BCRYPT implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java index 2ff8a44f9..63d10985e 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java +++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java @@ -12,6 +12,7 @@ public class BCRYPT2Y implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -28,6 +29,7 @@ public class BCRYPT2Y implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java b/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java index 041113c73..45845229c 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java +++ b/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java @@ -32,6 +32,7 @@ public class CRAZYCRYPT1 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java index 18e5b532c..c93171af1 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java +++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java @@ -15,6 +15,7 @@ public class CryptPBKDF2 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -33,6 +34,7 @@ public class CryptPBKDF2 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java index 0bf1d1718..98ff78836 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java +++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java @@ -16,6 +16,7 @@ public class CryptPBKDF2Django implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -34,6 +35,7 @@ public class CryptPBKDF2Django implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java index fb008fec4..349929868 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java @@ -12,6 +12,7 @@ public class DOUBLEMD5 implements EncryptionMethod { * Method getMD5. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) @@ -29,6 +30,7 @@ public class DOUBLEMD5 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class DOUBLEMD5 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java index ac61f9935..16635fa7c 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java +++ b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java @@ -24,6 +24,7 @@ public interface EncryptionMethod { * @param salt (can be an other data like playerName;salt , playerName, * etc... for customs methods) * @param name String + * * @return Hashing password * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException */ String getHash(String password, String salt, String name) @@ -33,6 +34,7 @@ public interface EncryptionMethod { * @param hash * @param password * @param playerName + * * @return true if password match, false else * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException */ boolean comparePassword(String hash, String password, String playerName) diff --git a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java index 60bd159bd..ecfc459e7 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java @@ -14,6 +14,7 @@ public class IPB3 implements EncryptionMethod { * Method getMD5. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) @@ -31,6 +32,7 @@ public class IPB3 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -45,6 +47,7 @@ public class IPB3 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java index 9a988ad1e..d4eb0f7f0 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java +++ b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java @@ -12,6 +12,7 @@ public class JOOMLA implements EncryptionMethod { * Method getMD5. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) @@ -29,6 +30,7 @@ public class JOOMLA implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class JOOMLA implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5.java b/src/main/java/fr/xephi/authme/security/crypts/MD5.java index 38ba26fe4..a4e0bc131 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MD5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MD5.java @@ -12,6 +12,7 @@ public class MD5 implements EncryptionMethod { * Method getMD5. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) @@ -29,6 +30,7 @@ public class MD5 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class MD5 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java index 4004f7a30..79892c284 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java @@ -12,6 +12,7 @@ public class MD5VB implements EncryptionMethod { * Method getMD5. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) @@ -29,6 +30,7 @@ public class MD5VB implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class MD5VB implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java index 8e1b0d1ae..501a591ae 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java @@ -14,6 +14,7 @@ public class MYBB implements EncryptionMethod { * Method getMD5. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) @@ -31,6 +32,7 @@ public class MYBB implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -45,6 +47,7 @@ public class MYBB implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java index 30e580b63..e7e9e50cf 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java @@ -21,6 +21,7 @@ public class PHPBB implements EncryptionMethod { * Method md5. * * @param data String + * * @return String */ public static String md5(String data) { @@ -38,6 +39,7 @@ public class PHPBB implements EncryptionMethod { * Method hexToInt. * * @param ch char + * * @return int */ static int hexToInt(char ch) { @@ -53,6 +55,7 @@ public class PHPBB implements EncryptionMethod { * Method bytes2hex. * * @param bytes byte[] + * * @return String */ private static String bytes2hex(byte[] bytes) { @@ -70,6 +73,7 @@ public class PHPBB implements EncryptionMethod { * Method pack. * * @param hex String + * * @return String */ static String pack(String hex) { @@ -88,6 +92,7 @@ public class PHPBB implements EncryptionMethod { * * @param password String * @param salt String + * * @return String */ public String phpbb_hash(String password, String salt) { @@ -110,6 +115,7 @@ public class PHPBB implements EncryptionMethod { * * @param input String * @param itoa64 String + * * @return String */ private String _hash_gensalt_private(String input, String itoa64) { @@ -122,6 +128,7 @@ public class PHPBB implements EncryptionMethod { * @param input String * @param itoa64 String * @param iteration_count_log2 int + * * @return String */ private String _hash_gensalt_private(String input, String itoa64, @@ -140,6 +147,7 @@ public class PHPBB implements EncryptionMethod { * * @param input String * @param count int + * * @return String */ private String _hash_encode64(String input, int count) { @@ -168,6 +176,7 @@ public class PHPBB implements EncryptionMethod { * * @param password String * @param setting String + * * @return String */ String _hash_crypt_private(String password, String setting) { @@ -196,6 +205,7 @@ public class PHPBB implements EncryptionMethod { * * @param password String * @param hash String + * * @return boolean */ public boolean phpbb_check_hash(String password, String hash) { @@ -210,6 +220,7 @@ public class PHPBB implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -224,6 +235,7 @@ public class PHPBB implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java index d793fbd47..682bdc432 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java @@ -18,6 +18,7 @@ public class PHPFUSION implements EncryptionMethod { * Method getSHA1. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) @@ -35,6 +36,7 @@ public class PHPFUSION implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -70,6 +72,7 @@ public class PHPFUSION implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java index 7f9bffaaa..def0e1af7 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java @@ -12,6 +12,7 @@ public class PLAINTEXT implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -26,6 +27,7 @@ public class PLAINTEXT implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java index 8c6f4a51a..242a88317 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java +++ b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java @@ -13,6 +13,7 @@ public class ROYALAUTH implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -28,6 +29,7 @@ public class ROYALAUTH implements EncryptionMethod { * * @param password String * @param salt String + * * @return String * @throws NoSuchAlgorithmException */ public String hash(String password, String salt) @@ -47,6 +49,7 @@ public class ROYALAUTH implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java index 88194ad78..5b29db9ed 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java @@ -14,6 +14,7 @@ public class SALTED2MD5 implements EncryptionMethod { * Method getMD5. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getMD5(String message) @@ -31,6 +32,7 @@ public class SALTED2MD5 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -45,6 +47,7 @@ public class SALTED2MD5 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java index ea58023a9..27d3cc8db 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java @@ -14,6 +14,7 @@ public class SALTEDSHA512 implements EncryptionMethod { * Method getSHA512. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getSHA512(String message) @@ -31,6 +32,7 @@ public class SALTEDSHA512 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -45,6 +47,7 @@ public class SALTEDSHA512 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA1.java b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java index 834428afb..360cfaf37 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SHA1.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java @@ -12,6 +12,7 @@ public class SHA1 implements EncryptionMethod { * Method getSHA1. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) @@ -29,6 +30,7 @@ public class SHA1 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class SHA1 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA256.java b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java index 2522852c5..ff25dd2f4 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SHA256.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java @@ -12,6 +12,7 @@ public class SHA256 implements EncryptionMethod { * Method getSHA256. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getSHA256(String message) @@ -29,6 +30,7 @@ public class SHA256 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class SHA256 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java index df4f7e411..3e7b93451 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SHA512.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java @@ -12,6 +12,7 @@ public class SHA512 implements EncryptionMethod { * Method getSHA512. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getSHA512(String message) @@ -29,6 +30,7 @@ public class SHA512 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class SHA512 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/SMF.java b/src/main/java/fr/xephi/authme/security/crypts/SMF.java index af40aa819..16f19cf7e 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SMF.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SMF.java @@ -12,6 +12,7 @@ public class SMF implements EncryptionMethod { * Method getSHA1. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) @@ -29,6 +30,7 @@ public class SMF implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class SMF implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java index 57bd1b2cc..c1ea4276e 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java @@ -14,6 +14,7 @@ public class WBB3 implements EncryptionMethod { * Method getSHA1. * * @param message String + * * @return String * @throws NoSuchAlgorithmException */ private static String getSHA1(String message) @@ -31,6 +32,7 @@ public class WBB3 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -45,6 +47,7 @@ public class WBB3 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB4.java b/src/main/java/fr/xephi/authme/security/crypts/WBB4.java index 50ef3fb75..41b528899 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WBB4.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WBB4.java @@ -12,6 +12,7 @@ public class WBB4 implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -26,6 +27,7 @@ public class WBB4 implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java index ef0ec6c18..03682f2dd 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java @@ -168,6 +168,7 @@ public class WHIRLPOOL implements EncryptionMethod { * Method display. * * @param array byte[] + * * @return String */ protected static String display(byte[] array) { @@ -395,6 +396,7 @@ public class WHIRLPOOL implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -413,6 +415,7 @@ public class WHIRLPOOL implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java index b16015ade..8ef6f6a19 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java @@ -18,6 +18,7 @@ public class WORDPRESS implements EncryptionMethod { * * @param src byte[] * @param count int + * * @return String */ private String encode64(byte[] src, int count) { @@ -59,6 +60,7 @@ public class WORDPRESS implements EncryptionMethod { * * @param password String * @param setting String + * * @return String */ private String crypt(String password, String setting) { @@ -103,6 +105,7 @@ public class WORDPRESS implements EncryptionMethod { * Method gensaltPrivate. * * @param input byte[] + * * @return String */ private String gensaltPrivate(byte[] input) { @@ -117,6 +120,7 @@ public class WORDPRESS implements EncryptionMethod { * Method stringToUtf8. * * @param string String + * * @return byte[] */ private byte[] stringToUtf8(String string) { @@ -133,6 +137,7 @@ public class WORDPRESS implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -149,6 +154,7 @@ public class WORDPRESS implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java index 1560f9565..49500ddb5 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java +++ b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java @@ -10,6 +10,7 @@ public class XAUTH implements EncryptionMethod { * Method getWhirlpool. * * @param message String + * * @return String */ public static String getWhirlpool(String message) { @@ -27,6 +28,7 @@ public class XAUTH implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -43,6 +45,7 @@ public class XAUTH implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override diff --git a/src/main/java/fr/xephi/authme/security/crypts/XF.java b/src/main/java/fr/xephi/authme/security/crypts/XF.java index 0a879a219..bbfd5901e 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/XF.java +++ b/src/main/java/fr/xephi/authme/security/crypts/XF.java @@ -19,6 +19,7 @@ public class XF implements EncryptionMethod { * @param password String * @param salt String * @param name String + * * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */ @Override @@ -33,6 +34,7 @@ public class XF implements EncryptionMethod { * @param hash String * @param password String * @param playerName String + * * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */ @Override @@ -46,6 +48,7 @@ public class XF implements EncryptionMethod { * Method getSHA256. * * @param password String + * * @return String * @throws NoSuchAlgorithmException */ public String getSHA256(String password) throws NoSuchAlgorithmException { @@ -72,6 +75,7 @@ public class XF implements EncryptionMethod { * * @param pattern String * @param line String + * * @return String */ public String regmatch(String pattern, String line) { diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java b/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java index d465bbc61..9db3150fb 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java @@ -38,6 +38,7 @@ public class BinTools { * Simple binary-to-hexadecimal conversion. * * @param b Input bytes. May be null. + * * @return Hexadecimal representation of b. Uppercase A-F, two characters * per byte. Empty string on null input. */ @@ -59,6 +60,7 @@ public class BinTools { * * @param s String containing hexadecimal digits. May be null * . On odd length leading zero will be assumed. + * * @return Array on bytes, non-null. * @throws IllegalArgumentException * when string contains non-hex character */ @@ -84,6 +86,7 @@ public class BinTools { * Convert hex digit to numerical value. * * @param c 0-9, a-f, A-F allowd. + * * @return 0-15 * @throws IllegalArgumentException * on non-hex character */ diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java index 0332003b2..2ba32cfe8 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java @@ -83,6 +83,7 @@ public class MacBasedPRF implements PRF { * Method doFinal. * * @param M byte[] + * * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PRF#doFinal(byte[]) */ public byte[] doFinal(byte[] M) { @@ -103,6 +104,7 @@ public class MacBasedPRF implements PRF { * Method init. * * @param P byte[] + * * @see fr.xephi.authme.security.pbkdf2.PRF#init(byte[]) */ public void init(byte[] P) { diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java index f5bd34450..c66a42ec3 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java @@ -38,6 +38,7 @@ public interface PBKDF2 { * Desired key length defaults to Pseudo Random Function block size. * * @param inputPassword Candidate password to compute the derived key for. + * * @return internal byte array */ public abstract byte[] deriveKey(String inputPassword); @@ -47,6 +48,7 @@ public interface PBKDF2 { * * @param inputPassword Candidate password to compute the derived key for. * @param dkLen Specify desired key length + * * @return internal byte array */ public abstract byte[] deriveKey(String inputPassword, int dkLen); @@ -57,6 +59,7 @@ public interface PBKDF2 { * PBKDF2Parameters. * * @param inputPassword Candidate password to compute the derived key for. + * * @return true password match; false incorrect * password */ diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java index f1009c0a0..67b65f05d 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java @@ -120,6 +120,7 @@ public class PBKDF2Engine implements PBKDF2 { * 48290A0B96C426C3:1000:973899B1D4AFEB3ED371060D0797E0EE0142BD04 * * @param args Supply the password as argument. + * * @throws IOException * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException */ public static void main(String[] args) @@ -162,6 +163,7 @@ public class PBKDF2Engine implements PBKDF2 { * Method deriveKey. * * @param inputPassword String + * * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String) */ public byte[] deriveKey(String inputPassword) { @@ -173,6 +175,7 @@ public class PBKDF2Engine implements PBKDF2 { * * @param inputPassword String * @param dkLen int + * * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String, int) */ public byte[] deriveKey(String inputPassword, int dkLen) { @@ -203,6 +206,7 @@ public class PBKDF2Engine implements PBKDF2 { * Method verifyKey. * * @param inputPassword String + * * @return boolean * @see fr.xephi.authme.security.pbkdf2.PBKDF2#verifyKey(String) */ public boolean verifyKey(String inputPassword) { @@ -249,6 +253,7 @@ public class PBKDF2Engine implements PBKDF2 { * Method setPseudoRandomFunction. * * @param prf PRF + * * @see fr.xephi.authme.security.pbkdf2.PBKDF2#setPseudoRandomFunction(PRF) */ public void setPseudoRandomFunction(PRF prf) { @@ -262,6 +267,7 @@ public class PBKDF2Engine implements PBKDF2 { * @param S Salt as array of bytes. null means no salt. * @param c Iteration count (see RFC 2898 4.2) * @param dkLen desired length of derived key. + * * @return internal byte array * @see RFC 2898 5.2 */ protected byte[] PBKDF2(PRF prf, byte[] S, int c, int dkLen) { @@ -291,6 +297,7 @@ public class PBKDF2Engine implements PBKDF2 { * * @param a * @param b + * * @return ceil(a/b) * @see RFC 2898 5.2 Step * 2. */ @@ -311,6 +318,7 @@ public class PBKDF2Engine implements PBKDF2 { * @param S Salt as array of bytes * @param c Iteration count * @param blockIndex + * * @see RFC 2898 5.2 Step * 3. */ @@ -350,6 +358,7 @@ public class PBKDF2Engine implements PBKDF2 { * @param dest * @param offset * @param i + * * @see RFC 2898 5.2 Step * 3. */ @@ -373,6 +382,7 @@ public class PBKDF2Engine implements PBKDF2 { * Method setParameters. * * @param parameters PBKDF2Parameters + * * @see fr.xephi.authme.security.pbkdf2.PBKDF2#setParameters(PBKDF2Parameters) */ public void setParameters(PBKDF2Parameters parameters) { diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java index 52e1c85c9..dc82ea208 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java @@ -37,6 +37,7 @@ public interface PBKDF2Formatter { * Convert parameters to String. * * @param p Parameters object to output. + * * @return String representation */ public abstract String toString(PBKDF2Parameters p); @@ -47,6 +48,7 @@ public interface PBKDF2Formatter { * * @param s String representation of parameters to decode. * @param p PBKDF2Parameters + * * @return false syntax OK, true some syntax * issue. */ diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java index 32f393bd8..ed07217ff 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java @@ -38,6 +38,7 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter { * * @param p PBKDF2Parameters * @param s String + * * @return boolean * @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#fromString(PBKDF2Parameters, String) */ public boolean fromString(PBKDF2Parameters p, String s) { @@ -64,6 +65,7 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter { * Method toString. * * @param p PBKDF2Parameters + * * @return String * @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#toString(PBKDF2Parameters) */ public String toString(PBKDF2Parameters p) { diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java index 42c64600d..408588c6d 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java @@ -46,6 +46,7 @@ public interface PRF { * * @param M Input data/message etc. Together with any data supplied during * initilization. + * * @return Random bytes of hLen length. */ public byte[] doFinal(byte[] M); diff --git a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java index 9dee23d14..063e6af60 100644 --- a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java +++ b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java @@ -87,6 +87,7 @@ public class OtherAccounts extends CustomConfiguration { * Method getAllPlayersByUUID. * * @param uuid UUID + * * @return List */ public List getAllPlayersByUUID(UUID uuid) { diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 7dbb2f26e..e29f50682 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -338,6 +338,7 @@ public final class Settings extends YamlConfiguration { * * @param name String * @param ip String + * * @return boolean */ public static boolean getRestrictedIp(String name, String ip) { @@ -377,6 +378,7 @@ public final class Settings extends YamlConfiguration { * Method checkLang. * * @param lang String + * * @return String */ public static String checkLang(String lang) { @@ -442,6 +444,7 @@ public final class Settings extends YamlConfiguration { * Method isEmailCorrect. * * @param email String + * * @return boolean */ public static boolean isEmailCorrect(String email) { diff --git a/src/main/java/fr/xephi/authme/settings/Spawn.java b/src/main/java/fr/xephi/authme/settings/Spawn.java index a37e90ce2..4c20b2960 100644 --- a/src/main/java/fr/xephi/authme/settings/Spawn.java +++ b/src/main/java/fr/xephi/authme/settings/Spawn.java @@ -58,6 +58,7 @@ public class Spawn extends CustomConfiguration { * Method setSpawn. * * @param location Location + * * @return boolean */ public boolean setSpawn(Location location) { @@ -79,6 +80,7 @@ public class Spawn extends CustomConfiguration { * Method setFirstSpawn. * * @param location Location + * * @return boolean */ public boolean setFirstSpawn(Location location) { diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index 21fd8f0d5..f59437a30 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -71,6 +71,7 @@ public class GeoLiteAPI { * Get the country code of the given IP address. * * @param ip Ip address + * * @return String */ public static String getCountryCode(String ip) { @@ -84,6 +85,7 @@ public class GeoLiteAPI { * Get the country name of the given IP address. * * @param ip Ip address + * * @return String */ public static String getCountryName(String ip) { diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index c5c0f6e8f..b0328a45c 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -19,6 +19,7 @@ public class StringUtils { * * @param first First string * @param second Second string + * * @return The difference value */ public static double getDifference(String first, String second) { @@ -38,6 +39,7 @@ public class StringUtils { * * @param str the string to analyze * @param pieces the items to check the string for + * * @return true if the string contains at least one of the items */ public static boolean containsAny(String str, String... pieces) { @@ -57,6 +59,7 @@ public class StringUtils { * is trimmed, so this method also considers a string with whitespace as empty. * * @param str the string to verify + * * @return true if the string is empty, false otherwise */ public static boolean isEmpty(String str) { @@ -68,6 +71,7 @@ public class StringUtils { * * @param delimiter the delimiter to use * @param elements the elements to join + * * @return a new String that is composed of the elements separated by the delimiter */ public static String join(String delimiter, Iterable elements) { @@ -89,6 +93,7 @@ public class StringUtils { * Get a full stack trace of an exception as a string. * * @param exception The exception. + * * @return Stack trace as a string. */ public static String getStackTrace(Exception exception) { diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index a928f05f8..d0d6734cc 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -100,6 +100,7 @@ public final class Utils { * * @param player The player. * @param group The group type. + * * @return True if succeed, false otherwise. False is also returned if groups aren't supported * with the current permissions system. */ @@ -159,6 +160,7 @@ public final class Utils { * * @param player The player. * @param group The normal group. + * * @return True on success, false on failure. */ public static boolean addNormal(Player player, String group) { @@ -277,6 +279,7 @@ public final class Utils { * Bukkit#getOnlinePlayers()} directly. * * @return collection of online players + * * @see SpigotMC * forum * @see StackOverflow