Fix various code issues as detected by Sonar

Mostly minor changes:
- Add deprecated javadoc tag on deprecated members
- Reduce duplication (FlatFile, BackupService, ...)
- Make methods static
- Reduce size of anonymous classes
- Replace name with displayName in PermissionsSystemType (avoids confusing with Enum name())
- Tabs to spaces
- Merge if statements

Code from third-party sources (BCryptService, BinTools, PHPBB) not modified.
This commit is contained in:
ljacqu
2016-11-22 18:19:46 +01:00
parent 8685e50988
commit 7d65d2a7c4
32 changed files with 172 additions and 197 deletions
@@ -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;
}
}
@@ -25,7 +25,7 @@ public class LastLoginCommand implements ExecutableCommand {
@Override
public void executeCommand(CommandSender sender, List<String> 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) {
@@ -23,7 +23,7 @@ public class ShowEmailCommand extends PlayerCommand {
@Override
public void runCommand(Player player, List<String> 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);