diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 6c87fcbe8..74a986543 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -61,7 +61,7 @@ public class AuthMe extends JavaPlugin { private static final String LOG_FILENAME = "authme.log"; private static final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE; - // Default version and build number values; + // Default version and build number values private static String pluginVersion = "N/D"; private static String pluginBuildNumber = "Unknown"; @@ -132,7 +132,7 @@ public class AuthMe extends JavaPlugin { @Override public void onEnable() { // Load the plugin version data from the plugin description file - loadPluginInfo(); + loadPluginInfo(getDescription().getVersion()); // Initialize the plugin try { @@ -175,9 +175,10 @@ public class AuthMe extends JavaPlugin { /** * Load the version and build number of the plugin from the description file. + * + * @param versionRaw the version as given by the plugin description file */ - private void loadPluginInfo() { - String versionRaw = this.getDescription().getVersion(); + private static void loadPluginInfo(String versionRaw) { int index = versionRaw.lastIndexOf("-"); if (index != -1) { pluginVersion = versionRaw.substring(0, index); @@ -190,10 +191,8 @@ public class AuthMe extends JavaPlugin { /** * Initialize the plugin and all the services. - * - * @throws Exception if the initialization fails */ - private void initialize() throws Exception { + private void initialize() { // Set the Logger instance and log file path ConsoleLogger.setLogger(getLogger()); ConsoleLogger.setLogFile(new File(getDataFolder(), LOG_FILENAME)); @@ -224,7 +223,7 @@ public class AuthMe extends JavaPlugin { // TODO: does this still make sense? -sgdc3 // If the server is empty (fresh start) just set all the players as unlogged - if (bukkitService.getOnlinePlayers().size() == 0) { + if (bukkitService.getOnlinePlayers().isEmpty()) { database.purgeLogged(); } diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 7fa027882..d05fbe6b9 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -19,12 +19,13 @@ import javax.inject.Inject; /** * Deprecated API of AuthMe. Please use {@link NewAPI} instead. + * + * @deprecated Use {@link NewAPI} */ @Deprecated public class API { - public static final String newline = System.getProperty("line.separator"); - public static AuthMe instance; + private static AuthMe instance; private static DataSource dataSource; private static PasswordSecurity passwordSecurity; private static Management management; @@ -83,28 +84,17 @@ public class API { } public static Location getLastLocation(Player player) { - try { - PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); + PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); - if (auth != null) { - Location loc = new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); - return loc; - } else { - return null; - } - - } catch (NullPointerException ex) { - return null; + if (auth != null) { + return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); } + return null; } - public static void setPlayerInventory(Player player, ItemStack[] content, - ItemStack[] armor) { - try { - player.getInventory().setContents(content); - player.getInventory().setArmorContents(armor); - } catch (NullPointerException ignored) { - } + public static void setPlayerInventory(Player player, ItemStack[] content, ItemStack[] armor) { + player.getInventory().setContents(content); + player.getInventory().setArmorContents(armor); } /** diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index 5805e4afd..82a2483bc 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -25,8 +25,8 @@ import java.util.List; */ public class NewAPI { - public static NewAPI singleton; - public final AuthMe plugin; + private static NewAPI singleton; + private final AuthMe plugin; private final PluginHookService pluginHookService; private final DataSource dataSource; private final PasswordSecurity passwordSecurity; diff --git a/src/main/java/fr/xephi/authme/command/CommandMapper.java b/src/main/java/fr/xephi/authme/command/CommandMapper.java index e36664929..8e2b1bdc1 100644 --- a/src/main/java/fr/xephi/authme/command/CommandMapper.java +++ b/src/main/java/fr/xephi/authme/command/CommandMapper.java @@ -87,10 +87,10 @@ public class CommandMapper { return classes; } - private FoundCommandResult getCommandWithSmallestDifference(CommandDescription base, List parts) { + private static FoundCommandResult getCommandWithSmallestDifference(CommandDescription base, List parts) { // Return the base command with incorrect arg count error if we only have one part if (parts.size() <= 1) { - return new FoundCommandResult(base, parts, new ArrayList(), 0.0, INCORRECT_ARGUMENTS); + return new FoundCommandResult(base, parts, new ArrayList<>(), 0.0, INCORRECT_ARGUMENTS); } final String childLabel = parts.get(1); @@ -115,7 +115,7 @@ public class CommandMapper { final int partsSize = parts.size(); List labels = parts.subList(0, Math.min(closestCommand.getLabelCount(), partsSize)); List arguments = (labels.size() == partsSize) - ? new ArrayList() + ? new ArrayList<>() : parts.subList(labels.size(), partsSize); return new FoundCommandResult(closestCommand, labels, arguments, minDifference, status); @@ -141,7 +141,7 @@ public class CommandMapper { * * @return A command if there was a complete match (including proper argument count), null otherwise */ - private CommandDescription getSuitableChild(CommandDescription baseCommand, List parts) { + private static CommandDescription getSuitableChild(CommandDescription baseCommand, List parts) { if (CollectionUtils.isEmpty(parts)) { return null; } diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java index 9842b9f89..8f3a2b0a3 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java @@ -54,33 +54,40 @@ public class ChangePasswordAdminCommand implements ExecutableCommand { } // Set the password - final String playerNameLowerCase = playerName.toLowerCase(); - bukkitService.runTaskOptionallyAsync(new Runnable() { + bukkitService.runTaskOptionallyAsync(() -> changePassword(playerName.toLowerCase(), playerPass, sender)); + } - @Override - public void run() { - PlayerAuth auth = null; - if (playerCache.isAuthenticated(playerNameLowerCase)) { - auth = playerCache.getAuth(playerNameLowerCase); - } else if (dataSource.isAuthAvailable(playerNameLowerCase)) { - auth = dataSource.getAuth(playerNameLowerCase); - } - if (auth == null) { - commandService.send(sender, MessageKey.UNKNOWN_USER); - return; - } + /** + * Changes the password of the given player to the given password. + * + * @param nameLowercase the name of the player + * @param password the password to set + * @param sender the sender initiating the password change + */ + private void changePassword(String nameLowercase, String password, CommandSender sender) { + PlayerAuth auth = getAuth(nameLowercase); + if (auth == null) { + commandService.send(sender, MessageKey.UNKNOWN_USER); + return; + } - HashedPassword hashedPassword = passwordSecurity.computeHash(playerPass, playerNameLowerCase); - auth.setPassword(hashedPassword); + HashedPassword hashedPassword = passwordSecurity.computeHash(password, nameLowercase); + auth.setPassword(hashedPassword); - if (dataSource.updatePassword(auth)) { - commandService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS); - ConsoleLogger.info(sender.getName() + " changed password of " + playerNameLowerCase); - } else { - commandService.send(sender, MessageKey.ERROR); - } - } + if (dataSource.updatePassword(auth)) { + commandService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS); + ConsoleLogger.info(sender.getName() + " changed password of " + nameLowercase); + } else { + commandService.send(sender, MessageKey.ERROR); + } + } - }); + private PlayerAuth getAuth(String nameLowercase) { + if (playerCache.isAuthenticated(nameLowercase)) { + return playerCache.getAuth(nameLowercase); + } else if (dataSource.isAuthAvailable(nameLowercase)) { + return dataSource.getAuth(nameLowercase); + } + return null; } } diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java index 3c2b8cd5d..67fb25916 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java @@ -25,7 +25,7 @@ public class LastLoginCommand implements ExecutableCommand { @Override public void executeCommand(CommandSender sender, List arguments) { // Get the player - String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName(); + String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0); PlayerAuth auth = dataSource.getAuth(playerName); if (auth == null) { diff --git a/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java index ae55c628a..68bc06dd0 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java @@ -23,7 +23,7 @@ public class ShowEmailCommand extends PlayerCommand { @Override public void runCommand(Player player, List arguments) { PlayerAuth auth = playerCache.getAuth(player.getName()); - if (auth.getEmail() != null && !auth.getEmail().equalsIgnoreCase("your@email.com")) { + if (auth.getEmail() != null && !"your@email.com".equalsIgnoreCase(auth.getEmail())) { commandService.send(player, MessageKey.EMAIL_SHOW, auth.getEmail()); } else { commandService.send(player, MessageKey.SHOW_NO_EMAIL); diff --git a/src/main/java/fr/xephi/authme/data/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/data/auth/PlayerAuth.java index e4fd9230f..f6ef65a7a 100644 --- a/src/main/java/fr/xephi/authme/data/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/data/auth/PlayerAuth.java @@ -189,7 +189,7 @@ public class PlayerAuth { * @return String */ public String serialize() { - StringBuffer str = new StringBuffer(); + StringBuilder str = new StringBuilder(); char d = ';'; str.append(this.nickname).append(d); str.append(this.realName).append(d); diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 49b5442d1..8c1ecf4b5 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -9,7 +9,6 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -295,19 +294,11 @@ public class FlatFile implements DataSource { break; } } - } catch (FileNotFoundException ex) { - ConsoleLogger.warning(ex.getMessage()); - return false; } catch (IOException ex) { ConsoleLogger.warning(ex.getMessage()); return false; } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ignored) { - } - } + silentClose(br); } if (newAuth != null) { removeAuth(auth.getNickname()); @@ -330,19 +321,11 @@ public class FlatFile implements DataSource { } } return countIp; - } catch (FileNotFoundException ex) { - ConsoleLogger.warning(ex.getMessage()); - return new ArrayList<>(); } catch (IOException ex) { ConsoleLogger.warning(ex.getMessage()); return new ArrayList<>(); } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ignored) { - } - } + silentClose(br); } } @@ -363,12 +346,7 @@ public class FlatFile implements DataSource { } catch (IOException ex) { ConsoleLogger.warning(ex.getMessage()); } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ignored) { - } - } + silentClose(br); } return 0; } diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index a099ff44d..20ffa6d53 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -47,7 +47,7 @@ public class MySQL implements DataSource { private int phpBbGroup; private String wordpressPrefix; - public MySQL(Settings settings) throws ClassNotFoundException, SQLException, PoolInitializationException { + public MySQL(Settings settings) throws ClassNotFoundException, SQLException { setParameters(settings); // Set the connection arguments (and check if connection is ok) @@ -102,12 +102,12 @@ public class MySQL implements DataSource { } } - private void setConnectionArguments() throws RuntimeException { + private void setConnectionArguments() { ds = new HikariDataSource(); ds.setPoolName("AuthMeMYSQLPool"); // Pool size - ds.setMaximumPoolSize(poolSize); + ds.setMaximumPoolSize(poolSize); // Database URL ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); @@ -134,7 +134,7 @@ public class MySQL implements DataSource { } @Override - public void reload() throws RuntimeException { + public void reload() { if (ds != null) { ds.close(); } diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index d19c4aa22..fdb9c9197 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -3,9 +3,6 @@ package fr.xephi.authme.datasource; import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.data.auth.PlayerAuth; -import fr.xephi.authme.datasource.Columns; -import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; @@ -397,7 +394,7 @@ public class SQLite implements DataSource { } } - private void close(Statement st) { + private static void close(Statement st) { if (st != null) { try { st.close(); @@ -407,7 +404,7 @@ public class SQLite implements DataSource { } } - private void close(Connection con) { + private static void close(Connection con) { if (con != null) { try { con.close(); @@ -417,7 +414,7 @@ public class SQLite implements DataSource { } } - private void close(ResultSet rs) { + private static void close(ResultSet rs) { if (rs != null) { try { rs.close(); @@ -479,7 +476,7 @@ public class SQLite implements DataSource { pst.setString(1, user); rs = pst.executeQuery(); if (rs.next()) - return (rs.getInt(col.IS_LOGGED) == 1); + return rs.getInt(col.IS_LOGGED) == 1; } catch (SQLException ex) { logSqlException(ex); } finally { diff --git a/src/main/java/fr/xephi/authme/datasource/converter/CrazyLoginConverter.java b/src/main/java/fr/xephi/authme/datasource/converter/CrazyLoginConverter.java index 535c0ebab..13266a891 100644 --- a/src/main/java/fr/xephi/authme/datasource/converter/CrazyLoginConverter.java +++ b/src/main/java/fr/xephi/authme/datasource/converter/CrazyLoginConverter.java @@ -43,20 +43,7 @@ public class CrazyLoginConverter implements Converter { try (BufferedReader users = new BufferedReader(new FileReader(source))) { while ((line = users.readLine()) != null) { if (line.contains("|")) { - String[] args = line.split("\\|"); - if (args.length < 2 || "name".equalsIgnoreCase(args[0])) { - continue; - } - String playerName = args[0]; - String password = args[1]; - if (password != null) { - PlayerAuth auth = PlayerAuth.builder() - .name(playerName.toLowerCase()) - .realName(playerName) - .password(password, null) - .build(); - database.saveAuth(auth); - } + migrateAccount(line); } } ConsoleLogger.info("CrazyLogin database has been imported correctly"); @@ -66,4 +53,26 @@ public class CrazyLoginConverter implements Converter { } } + /** + * Moves an account from CrazyLogin to the AuthMe database. + * + * @param line line read from the CrazyLogin file (one account) + */ + private void migrateAccount(String line) { + String[] args = line.split("\\|"); + if (args.length < 2 || "name".equalsIgnoreCase(args[0])) { + return; + } + String playerName = args[0]; + String password = args[1]; + if (password != null) { + PlayerAuth auth = PlayerAuth.builder() + .name(playerName.toLowerCase()) + .realName(playerName) + .password(password, null) + .build(); + database.saveAuth(auth); + } + } + } diff --git a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java index 6141e47ef..1e7862443 100644 --- a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java +++ b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java @@ -76,10 +76,8 @@ public class OnShutdownPlayerSaver { dataSource.updateQuitLoc(auth); } if (settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN) - && !settings.getProperty(RestrictionSettings.NO_TELEPORT)) { - if (!limboPlayerStorage.hasData(player)) { - limboPlayerStorage.saveData(player); - } + && !settings.getProperty(RestrictionSettings.NO_TELEPORT) && !limboPlayerStorage.hasData(player)) { + limboPlayerStorage.saveData(player); } } } diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index 7e68aae42..e3ff4ec5b 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -170,10 +170,9 @@ class OnJoinVerifier implements Reloadable { public void checkPlayerCountry(boolean isAuthAvailable, String playerIp) throws FailedVerificationException { if ((!isAuthAvailable || settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)) - && settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)) { - if (!validationService.isCountryAdmitted(playerIp)) { + && settings.getProperty(ProtectionSettings.ENABLE_PROTECTION) + && !validationService.isCountryAdmitted(playerIp)) { throw new FailedVerificationException(MessageKey.COUNTRY_BANNED_ERROR); - } } } diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 92cf6a841..9b3eda8e9 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -42,6 +42,7 @@ import org.bukkit.event.player.PlayerShearEntityEvent; import javax.inject.Inject; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -53,7 +54,7 @@ import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAU */ public class PlayerListener implements Listener { - public static final ConcurrentHashMap joinMessage = new ConcurrentHashMap<>(); + public static final Map joinMessage = new ConcurrentHashMap<>(); @Inject private Settings settings; @@ -81,7 +82,7 @@ public class PlayerListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String cmd = event.getMessage().split(" ")[0].toLowerCase(); - if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && cmd.equals("/motd")) { + if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && "/motd".equals(cmd)) { return; } if (settings.getProperty(RestrictionSettings.ALLOW_COMMANDS).contains(cmd)) { @@ -113,7 +114,7 @@ public class PlayerListener implements Listener { iter.remove(); } } - if (recipients.size() == 0) { + if (recipients.isEmpty()) { event.setCancelled(true); } } @@ -224,7 +225,7 @@ public class PlayerListener implements Listener { // Get the auth later as this may cause the single session check to fail // Slow stuff final PlayerAuth auth = dataSource.getAuth(name); - final boolean isAuthAvailable = (auth != null); + final boolean isAuthAvailable = auth != null; onJoinVerifier.checkKickNonRegistered(isAuthAvailable); onJoinVerifier.checkAntibot(player, isAuthAvailable); onJoinVerifier.checkNameCasing(player, auth); diff --git a/src/main/java/fr/xephi/authme/output/Log4JFilter.java b/src/main/java/fr/xephi/authme/output/Log4JFilter.java index 90b9f0fb6..1d044e184 100644 --- a/src/main/java/fr/xephi/authme/output/Log4JFilter.java +++ b/src/main/java/fr/xephi/authme/output/Log4JFilter.java @@ -12,14 +12,9 @@ import org.apache.logging.log4j.message.Message; * * @author Xephi59 */ -@SuppressWarnings("serial") public class Log4JFilter extends AbstractFilter { - /** - * Constructor. - */ - public Log4JFilter() { - } + private static final long serialVersionUID = -5594073755007974254L; /** * Validates a Message instance and returns the {@link Result} value diff --git a/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java b/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java index fb4bff486..492c69115 100644 --- a/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java +++ b/src/main/java/fr/xephi/authme/permission/AuthGroupHandler.java @@ -31,7 +31,8 @@ public class AuthGroupHandler implements Reloadable { private String unregisteredGroup; private String registeredGroup; - AuthGroupHandler() { } + AuthGroupHandler() { + } /** * Set the group of a player, by its AuthMe group type. diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index c0c6981aa..29406be6c 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -78,12 +78,12 @@ public class PermissionsManager implements Reloadable { if (handler != null) { // Show a success message and return this.handler = handler; - ConsoleLogger.info("Hooked into " + type.getName() + "!"); + ConsoleLogger.info("Hooked into " + type.getDisplayName() + "!"); return; } } catch (Exception ex) { // An error occurred, show a warning message - ConsoleLogger.logException("Error while hooking into " + type.getName(), ex); + ConsoleLogger.logException("Error while hooking into " + type.getDisplayName(), ex); } } @@ -101,7 +101,7 @@ public class PermissionsManager implements Reloadable { // Make sure the plugin is enabled before hooking if (!plugin.isEnabled()) { - ConsoleLogger.info("Not hooking into " + type.getName() + " because it's disabled!"); + ConsoleLogger.info("Not hooking into " + type.getDisplayName() + " because it's disabled!"); return null; } @@ -414,7 +414,7 @@ public class PermissionsManager implements Reloadable { */ public boolean setGroups(Player player, List groupNames) { // If no permissions system is used or if there's no group supplied, return false - if (!isEnabled() || groupNames.size() <= 0) + if (!isEnabled() || groupNames.isEmpty()) return false; // Set the main group diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java b/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java index 1410bc668..72a0753cb 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java @@ -33,21 +33,21 @@ public enum PermissionsSystemType { /** * The display name of the permissions system. */ - public String name; + private String displayName; /** * The name of the permissions system plugin. */ - public String pluginName; + private String pluginName; /** * Constructor for PermissionsSystemType. * - * @param name Display name of the permissions system. + * @param displayName Display name of the permissions system. * @param pluginName Name of the plugin. */ - PermissionsSystemType(String name, String pluginName) { - this.name = name; + PermissionsSystemType(String displayName, String pluginName) { + this.displayName = displayName; this.pluginName = pluginName; } @@ -56,8 +56,8 @@ public enum PermissionsSystemType { * * @return Display name. */ - public String getName() { - return this.name; + public String getDisplayName() { + return this.displayName; } /** @@ -76,7 +76,7 @@ public enum PermissionsSystemType { */ @Override public String toString() { - return getName(); + return getDisplayName(); } /** diff --git a/src/main/java/fr/xephi/authme/permission/handlers/BPermissionsHandler.java b/src/main/java/fr/xephi/authme/permission/handlers/BPermissionsHandler.java index 983e42e27..9f52214b9 100644 --- a/src/main/java/fr/xephi/authme/permission/handlers/BPermissionsHandler.java +++ b/src/main/java/fr/xephi/authme/permission/handlers/BPermissionsHandler.java @@ -55,7 +55,7 @@ public class BPermissionsHandler implements PermissionHandler { List groups = getGroups(player); // Make sure there is any group available, or return null - if (groups.size() == 0) + if (groups.isEmpty()) return null; // Return the first group diff --git a/src/main/java/fr/xephi/authme/permission/handlers/PermissionsBukkitHandler.java b/src/main/java/fr/xephi/authme/permission/handlers/PermissionsBukkitHandler.java index 344e0aec5..e8e8a21e5 100644 --- a/src/main/java/fr/xephi/authme/permission/handlers/PermissionsBukkitHandler.java +++ b/src/main/java/fr/xephi/authme/permission/handlers/PermissionsBukkitHandler.java @@ -54,7 +54,7 @@ public class PermissionsBukkitHandler implements PermissionHandler { List groups = getGroups(player); // Make sure there is any group available, or return null - if (groups.size() == 0) + if (groups.isEmpty()) return null; // Return the first group diff --git a/src/main/java/fr/xephi/authme/permission/handlers/PermissionsExHandler.java b/src/main/java/fr/xephi/authme/permission/handlers/PermissionsExHandler.java index e3e03ee32..b11d00003 100644 --- a/src/main/java/fr/xephi/authme/permission/handlers/PermissionsExHandler.java +++ b/src/main/java/fr/xephi/authme/permission/handlers/PermissionsExHandler.java @@ -77,7 +77,7 @@ public class PermissionsExHandler implements PermissionHandler { PermissionUser user = permissionManager.getUser(player); List groups = user.getParentIdentifiers(null); - if (groups.size() == 0) + if (groups.isEmpty()) return null; return groups.get(0); diff --git a/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java b/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java index 12471b0ea..80d304dd1 100644 --- a/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java +++ b/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java @@ -27,7 +27,8 @@ public class AsyncChangePassword implements AsynchronousProcess { @Inject private PlayerCache playerCache; - AsyncChangePassword() { } + AsyncChangePassword() { + } public void changePassword(final Player player, String oldPassword, String newPassword) { diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index 2488be8a1..12b6152be 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -14,6 +14,7 @@ import fr.xephi.authme.service.BungeeService; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.TeleportationService; +import fr.xephi.authme.util.StringUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; @@ -90,16 +91,13 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { teleportationService.teleportOnLogin(player, auth, limbo); // We can now display the join message (if delayed) - String jm = PlayerListener.joinMessage.get(name); - if (jm != null) { - if (!jm.isEmpty()) { - for (Player p : bukkitService.getOnlinePlayers()) { - if (p.isOnline()) { - p.sendMessage(jm); - } + String joinMessage = PlayerListener.joinMessage.remove(name); + if (!StringUtils.isEmpty(joinMessage)) { + for (Player p : bukkitService.getOnlinePlayers()) { + if (p.isOnline()) { + p.sendMessage(joinMessage); } } - PlayerListener.joinMessage.remove(name); } if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index de77a17d0..3347b382f 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -21,8 +21,8 @@ public class ProcessSyncEmailRegister implements SynchronousProcess { @Inject private LimboPlayerTaskManager limboPlayerTaskManager; - ProcessSyncEmailRegister() { } - + ProcessSyncEmailRegister() { + } public void processEmailRegister(Player player) { final String name = player.getName().toLowerCase(); 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 dc2cb3b40..a294ca917 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java @@ -1,5 +1,10 @@ package fr.xephi.authme.security.crypts; +/** + * Plaintext password storage. + * + * @deprecated Using this is no longer supported. AuthMe will migrate to SHA256 on startup. + */ @Deprecated public class PLAINTEXT extends UnsaltedMethod { 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 186128744..f2ebf1976 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java +++ b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java @@ -18,14 +18,14 @@ public class XAUTH extends HexSaltedMethod { @Override public String computeHash(String password, String salt, String name) { String hash = getWhirlpool(salt + password).toLowerCase(); - int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length()); + int saltPos = password.length() >= hash.length() ? hash.length() - 1 : password.length(); return hash.substring(0, saltPos) + salt + hash.substring(saltPos); } @Override public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) { String hash = hashedPassword.getHash(); - int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length()); + int saltPos = password.length() >= hash.length() ? hash.length() - 1 : password.length(); if (saltPos + 12 > hash.length()) { return false; } diff --git a/src/main/java/fr/xephi/authme/service/BackupService.java b/src/main/java/fr/xephi/authme/service/BackupService.java index b5dfa06d3..846e34415 100644 --- a/src/main/java/fr/xephi/authme/service/BackupService.java +++ b/src/main/java/fr/xephi/authme/service/BackupService.java @@ -104,36 +104,22 @@ public class BackupService { dirBackup.mkdir(); } String backupWindowsPath = settings.getProperty(BackupSettings.MYSQL_WINDOWS_PATH); - if (checkWindows(backupWindowsPath)) { - String executeCmd = backupWindowsPath + "\\bin\\mysqldump.exe -u " + dbUserName + " -p" + dbPassword + " " + dbName + " --tables " + tblname + " -r " + path + ".sql"; - Process runtimeProcess; - try { - runtimeProcess = Runtime.getRuntime().exec(executeCmd); - int processComplete = runtimeProcess.waitFor(); - if (processComplete == 0) { - ConsoleLogger.info("Backup created successfully."); - return true; - } else { - ConsoleLogger.warning("Could not create the backup! (Windows)"); - } - } catch (IOException | InterruptedException e) { - ConsoleLogger.logException("Error during Windows backup:", e); - } - } else { - String executeCmd = "mysqldump -u " + dbUserName + " -p" + dbPassword + " " + dbName + " --tables " + tblname + " -r " + path + ".sql"; - Process runtimeProcess; - try { - runtimeProcess = Runtime.getRuntime().exec(executeCmd); - int processComplete = runtimeProcess.waitFor(); - if (processComplete == 0) { - ConsoleLogger.info("Backup created successfully."); - return true; - } else { - ConsoleLogger.warning("Could not create the backup!"); - } - } catch (IOException | InterruptedException e) { - ConsoleLogger.logException("Error during backup:", e); + boolean isUsingWindows = checkWindows(backupWindowsPath); + String backupCommand = isUsingWindows + ? backupWindowsPath + "\\bin\\mysqldump.exe" + buildMysqlDumpArguments() + : "mysqldump" + buildMysqlDumpArguments(); + + try { + Process runtimeProcess = Runtime.getRuntime().exec(backupCommand); + int processComplete = runtimeProcess.waitFor(); + if (processComplete == 0) { + ConsoleLogger.info("Backup created successfully. (Using Windows = " + isUsingWindows + ")"); + return true; + } else { + ConsoleLogger.warning("Could not create the backup! (Using Windows = " + isUsingWindows + ")"); } + } catch (IOException | InterruptedException e) { + ConsoleLogger.logException("Error during backup (using Windows = " + isUsingWindows + "):", e); } return false; } @@ -173,6 +159,16 @@ public class BackupService { return false; } + /** + * Builds the command line arguments to pass along when running the {@code mysqldump} command. + * + * @return the mysqldump command line arguments + */ + private String buildMysqlDumpArguments() { + return " -u " + dbUserName + " -p" + dbPassword + " " + dbName + + " --tables " + tblname + " -r " + path + ".sql"; + } + private static void copy(String src, String dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); diff --git a/src/main/java/fr/xephi/authme/service/ValidationService.java b/src/main/java/fr/xephi/authme/service/ValidationService.java index e3a69fc94..c6cdd99a1 100644 --- a/src/main/java/fr/xephi/authme/service/ValidationService.java +++ b/src/main/java/fr/xephi/authme/service/ValidationService.java @@ -40,7 +40,8 @@ public class ValidationService implements Reloadable { private Pattern passwordRegex; private Set unrestrictedNames; - ValidationService() { } + ValidationService() { + } @PostConstruct @Override diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java index b3a06f5eb..ac1742fa6 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -48,10 +48,10 @@ public class SpawnLoader implements Reloadable { @Inject SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHookService pluginHookService, DataSource dataSource) { - File spawnFile = new File(pluginFolder, "spawn.yml"); // TODO ljacqu 20160312: Check if resource could be copied and handle the case if not + File spawnFile = new File(pluginFolder, "spawn.yml"); FileUtils.copyFileFromResource(spawnFile, "spawn.yml"); - this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml"); + this.authMeConfigurationFile = spawnFile; this.settings = settings; this.pluginHookService = pluginHookService; reload(); diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 5fef8a957..39419689e 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -54,7 +54,7 @@ public final class Utils { * * @return the core count */ - public static int getCoreCount() { - return Runtime.getRuntime().availableProcessors(); - } + public static int getCoreCount() { + return Runtime.getRuntime().availableProcessors(); + } } diff --git a/src/test/java/fr/xephi/authme/permission/PermissionsSystemTypeTest.java b/src/test/java/fr/xephi/authme/permission/PermissionsSystemTypeTest.java index 809014ada..ec63c5889 100644 --- a/src/test/java/fr/xephi/authme/permission/PermissionsSystemTypeTest.java +++ b/src/test/java/fr/xephi/authme/permission/PermissionsSystemTypeTest.java @@ -23,15 +23,15 @@ public class PermissionsSystemTypeTest { List pluginNames = new ArrayList<>(PermissionsSystemType.values().length); for (PermissionsSystemType system : PermissionsSystemType.values()) { - assertThat("Name for enum entry '" + system + "' is not null", - system.getName(), not(nullValue())); + assertThat("Display name for enum entry '" + system + "' is not null", + system.getDisplayName(), not(nullValue())); assertThat("Plugin name for enum entry '" + system + "' is not null", system.getPluginName(), not(nullValue())); - assertThat("Only one enum entry has name '" + system.getName() + "'", - names, not(hasItem(system.getName()))); + assertThat("Only one enum entry has display name '" + system.getDisplayName() + "'", + names, not(hasItem(system.getDisplayName()))); assertThat("Only one enum entry has plugin name '" + system.getPluginName() + "'", pluginNames, not(hasItem(system.getPluginName()))); - names.add(system.getName()); + names.add(system.getDisplayName()); pluginNames.add(system.getPluginName()); } }