#306 Remove singleton getters in admin commands

- Note: this commit does not remove all singleton getters
This commit is contained in:
ljacqu 2015-12-26 17:57:53 +01:00
parent 283bb7c113
commit 74ceb66430
15 changed files with 141 additions and 204 deletions

View File

@ -5,6 +5,8 @@ import fr.xephi.authme.command.help.HelpProvider;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages; import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.process.Management;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
@ -100,4 +102,22 @@ public class CommandService {
} }
} }
/**
* Returns the management instance of the plugin.
*
* @return The Management instance linked to the AuthMe instance
*/
public Management getManagement() {
return authMe.getManagement();
}
public PermissionsManager getPermissionsManager() {
// TODO ljacqu 20151226: Might be nicer to pass the perm manager via constructor
return authMe.getPermissionsManager();
}
public String[] retrieveMessage(MessageKey key) {
return messages.retrieve(key);
}
} }

View File

@ -6,6 +6,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages; import fr.xephi.authme.output.Messages;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
@ -22,70 +23,70 @@ import java.util.List;
public class ChangePasswordAdminCommand implements ExecutableCommand { public class ChangePasswordAdminCommand implements ExecutableCommand {
@Override @Override
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(final CommandSender sender, List<String> arguments,
final AuthMe plugin = AuthMe.getInstance(); final CommandService commandService) {
final Messages m = plugin.getMessages();
// Get the player and password // Get the player and password
String playerName = arguments.get(0); String playerName = arguments.get(0);
final String playerPass = arguments.get(1); final String playerPass = arguments.get(1);
// Validate the password // Validate the password
String playerPassLowerCase = playerPass.toLowerCase(); String playerPassLowerCase = playerPass.toLowerCase();
// TODO #308: Remove this check
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|| !playerPassLowerCase.matches(Settings.getPassRegex)) { || !playerPassLowerCase.matches(Settings.getPassRegex)) {
m.send(sender, MessageKey.PASSWORD_MATCH_ERROR); commandService.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
return; return;
} }
if (playerPassLowerCase.equalsIgnoreCase(playerName)) { if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR); commandService.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
return; return;
} }
if (playerPassLowerCase.length() < Settings.getPasswordMinLen if (playerPassLowerCase.length() < Settings.getPasswordMinLen
|| playerPassLowerCase.length() > Settings.passwordMaxLength) { || playerPassLowerCase.length() > Settings.passwordMaxLength) {
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH); commandService.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
return; return;
} }
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) { if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR); commandService.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
return; return;
} }
// Set the password // Set the password
final String playerNameLowerCase = playerName.toLowerCase(); final String playerNameLowerCase = playerName.toLowerCase();
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { commandService.runTaskAsynchronously(new Runnable() {
@Override @Override
public void run() { public void run() {
DataSource dataSource = commandService.getDataSource();
String hash; String hash;
try { try {
hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase); hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
m.send(sender, MessageKey.ERROR); commandService.send(sender, MessageKey.ERROR);
return; return;
} }
PlayerAuth auth = null; PlayerAuth auth = null;
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) { if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
auth = PlayerCache.getInstance().getAuth(playerNameLowerCase); auth = PlayerCache.getInstance().getAuth(playerNameLowerCase);
} else if (plugin.database.isAuthAvailable(playerNameLowerCase)) { } else if (dataSource.isAuthAvailable(playerNameLowerCase)) {
auth = plugin.database.getAuth(playerNameLowerCase); auth = dataSource.getAuth(playerNameLowerCase);
} }
if (auth == null) { if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER); commandService.send(sender, MessageKey.UNKNOWN_USER);
return; return;
} }
auth.setHash(hash); auth.setHash(hash);
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase)) { if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase)) {
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase)); auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
plugin.database.updateSalt(auth); commandService.getDataSource().updateSalt(auth);
} }
if (!plugin.database.updatePassword(auth)) { if (!dataSource.updatePassword(auth)) {
m.send(sender, MessageKey.ERROR); commandService.send(sender, MessageKey.ERROR);
return; return;
} }
sender.sendMessage("pwd_changed"); commandService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
ConsoleLogger.info(playerNameLowerCase + "'s password changed"); ConsoleLogger.info(playerNameLowerCase + "'s password changed");
} }

View File

@ -1,46 +1,33 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.permission.PlayerPermission;
import org.bukkit.Bukkit; import fr.xephi.authme.util.Utils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
/** /**
* Forces the login of a player, i.e. logs the player in without the need of a (correct) password.
*/ */
public class ForceLoginCommand implements ExecutableCommand { public class ForceLoginCommand implements ExecutableCommand {
@Override @Override
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Get the player query // Get the player query
String playerName = sender.getName(); String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
if (arguments.size() >= 1) {
playerName = arguments.get(0);
}
// Command logic Player player = Utils.getPlayer(playerName);
try {
// TODO ljacqu 20151212: Retrieve player via Utils method instead
Player player = Bukkit.getPlayer(playerName);
if (player == null || !player.isOnline()) { if (player == null || !player.isOnline()) {
sender.sendMessage("Player needs to be online!"); sender.sendMessage("Player needs to be online!");
return; } else if (!commandService.getPermissionsManager()
} .hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
sender.sendMessage("You cannot force login for the player " + playerName + "!"); sender.sendMessage("You cannot force login for the player " + playerName + "!");
return; } else {
} commandService.getManagement().performLogin(player, "dontneed", true);
plugin.getManagement().performLogin(player, "dontneed", true);
sender.sendMessage("Force Login for " + playerName + " performed!"); sender.sendMessage("Force Login for " + playerName + " performed!");
} catch (Exception e) {
sender.sendMessage("An error occurred while trying to get that player!");
} }
} }
} }

View File

@ -1,11 +1,9 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
@ -16,16 +14,11 @@ public class GetEmailCommand implements ExecutableCommand {
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0); String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Get the authenticated user PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
AuthMe plugin = AuthMe.getInstance();
Messages m = plugin.getMessages();
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
if (auth == null) { if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER); commandService.send(sender, MessageKey.UNKNOWN_USER);
return; } else {
}
// Show the email address
sender.sendMessage("[AuthMe] " + playerName + "'s email: " + auth.getEmail()); sender.sendMessage("[AuthMe] " + playerName + "'s email: " + auth.getEmail());
} }
} }
}

View File

@ -3,6 +3,7 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -18,8 +19,7 @@ public class GetIpCommand implements ExecutableCommand {
// Get the player query // Get the player query
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName(); String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
// TODO ljacqu 20151212: Use the Utils function instead Player player = Utils.getPlayer(playerName);
Player player = Bukkit.getPlayer(playerName);
if (player == null) { if (player == null) {
sender.sendMessage("The player is not online"); sender.sendMessage("The player is not online");
return; return;

View File

@ -20,39 +20,23 @@ public class LastLoginCommand implements ExecutableCommand {
// Get the player // Get the player
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName(); String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
// Validate the player PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
AuthMe plugin = AuthMe.getInstance();
Messages m = plugin.getMessages();
PlayerAuth auth;
try {
auth = plugin.database.getAuth(playerName.toLowerCase());
} catch (NullPointerException e) {
m.send(sender, MessageKey.UNKNOWN_USER);
return;
}
if (auth == null) { if (auth == null) {
m.send(sender, MessageKey.USER_NOT_REGISTERED); commandService.send(sender, MessageKey.USER_NOT_REGISTERED);
return; return;
} }
// Get the last login date // Get the last login date
long lastLogin = auth.getLastLogin(); long lastLogin = auth.getLastLogin();
Date date = new Date(lastLogin);
// Get the difference
final long diff = System.currentTimeMillis() - lastLogin; final long diff = System.currentTimeMillis() - lastLogin;
final String lastLoginMessage = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours "
// Build the message + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs";
final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " Date date = new Date(lastLogin);
+ (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs.";
// Get the player's last IP
String lastIP = auth.getIp();
// Show the player status // Show the player status
sender.sendMessage("[AuthMe] " + playerName + " last login: " + date.toString()); sender.sendMessage("[AuthMe] " + playerName + " last login: " + date.toString());
sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " is unlogged since " + msg); sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " last logged in "
sender.sendMessage("[AuthMe] Last Player's IP: " + lastIP); + lastLoginMessage + " ago.");
sender.sendMessage("[AuthMe] Last Player's IP: " + auth.getIp());
} }
} }

View File

@ -41,7 +41,7 @@ public class PurgeCommand implements ExecutableCommand {
long until = calendar.getTimeInMillis(); long until = calendar.getTimeInMillis();
// Purge the data, get the purged values // Purge the data, get the purged values
List<String> purged = plugin.database.autoPurgeDatabase(until); List<String> purged = commandService.getDataSource().autoPurgeDatabase(until);
// Show a status message // Show a status message
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts"); sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");

View File

@ -1,14 +1,10 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
@ -16,20 +12,13 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
@Override @Override
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
final AuthMe plugin = AuthMe.getInstance();
final Messages m = plugin.getMessages();
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0); String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Get the player
String playerNameLowerCase = playerName.toLowerCase(); String playerNameLowerCase = playerName.toLowerCase();
// Purge the last position of the player
try {
// Get the user auth and make sure the user exists // Get the user auth and make sure the user exists
PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase); PlayerAuth auth = commandService.getDataSource().getAuth(playerNameLowerCase);
if (auth == null) { if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER); commandService.send(sender, MessageKey.UNKNOWN_USER);
return; return;
} }
@ -38,16 +27,9 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
auth.setQuitLocY(0D); auth.setQuitLocY(0D);
auth.setQuitLocZ(0D); auth.setQuitLocZ(0D);
auth.setWorld("world"); auth.setWorld("world");
plugin.database.updateQuitLoc(auth); commandService.getDataSource().updateQuitLoc(auth);
// Show a status message // Show a status message
sender.sendMessage(playerNameLowerCase + "'s last position location is now reset"); sender.sendMessage(playerNameLowerCase + "'s last position location is now reset");
} catch (Exception e) {
ConsoleLogger.showError("An error occurred while trying to reset location or player do not exist, please see below: ");
ConsoleLogger.showError(e.getMessage());
if (sender instanceof Player)
sender.sendMessage("An error occurred while trying to reset location or player do not exist, please see logs");
}
} }
} }

View File

@ -1,12 +1,10 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -21,49 +19,43 @@ import java.util.List;
public class RegisterAdminCommand implements ExecutableCommand { public class RegisterAdminCommand implements ExecutableCommand {
@Override @Override
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(final CommandSender sender, List<String> arguments,
// AuthMe plugin instance final CommandService commandService) {
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
// Get the player name and password // Get the player name and password
final String playerName = arguments.get(0); final String playerName = arguments.get(0).toLowerCase();
final String playerPass = arguments.get(1); final String playerPass = arguments.get(1).toLowerCase();
final String playerNameLowerCase = playerName.toLowerCase(); final String playerNameLowerCase = playerName.toLowerCase();
final String playerPassLowerCase = playerPass.toLowerCase(); final String playerPassLowerCase = playerPass.toLowerCase();
// Command logic // Command logic
// TODO #308: Remove the check for SQL keywords
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|| !playerPassLowerCase.matches(Settings.getPassRegex)) { || !playerPassLowerCase.matches(Settings.getPassRegex)) {
m.send(sender, MessageKey.PASSWORD_MATCH_ERROR); commandService.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
return; return;
} }
if (playerPassLowerCase.equalsIgnoreCase(playerName)) { if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR); commandService.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
return; return;
} }
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) { if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH); commandService.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
return; return;
} }
if (!Settings.unsafePasswords.isEmpty()) { if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
if (Settings.unsafePasswords.contains(playerPassLowerCase)) { commandService.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
return; return;
} }
} commandService.runTaskAsynchronously(new Runnable() {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@SuppressWarnings("deprecation")
@Override @Override
public void run() { public void run() {
try { try {
if (plugin.database.isAuthAvailable(playerNameLowerCase)) { if (commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
m.send(sender, MessageKey.NAME_ALREADY_REGISTERED); commandService.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
return; return;
} }
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase); String hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
@ -71,18 +63,18 @@ public class RegisterAdminCommand implements ExecutableCommand {
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase) && PasswordSecurity.userSalt.get(playerNameLowerCase) != null) if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase) && PasswordSecurity.userSalt.get(playerNameLowerCase) != null)
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase)); auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
else auth.setSalt(""); else auth.setSalt("");
if (!plugin.database.saveAuth(auth)) { if (!commandService.getDataSource().saveAuth(auth)) {
m.send(sender, MessageKey.ERROR); commandService.send(sender, MessageKey.ERROR);
return; return;
} }
plugin.database.setUnlogged(playerNameLowerCase); commandService.getDataSource().setUnlogged(playerNameLowerCase);
if (Bukkit.getPlayerExact(playerName) != null) if (Bukkit.getPlayerExact(playerName) != null)
Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again"); Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again");
m.send(sender, MessageKey.REGISTER_SUCCESS); commandService.send(sender, MessageKey.REGISTER_SUCCESS);
ConsoleLogger.info(playerNameLowerCase + " registered"); ConsoleLogger.info(playerNameLowerCase + " registered");
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
m.send(sender, MessageKey.ERROR); commandService.send(sender, MessageKey.ERROR);
} }
} }

View File

@ -16,34 +16,21 @@ public class ReloadCommand implements ExecutableCommand {
@Override @Override
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
// Profile the reload process
Profiler p = new Profiler(true);
// AuthMe plugin instance // AuthMe plugin instance
AuthMe plugin = AuthMe.getInstance(); AuthMe plugin = AuthMe.getInstance();
// Messages instance
Messages m = plugin.getMessages();
// Show a status message
// sender.sendMessage(ChatColor.YELLOW + "Reloading AuthMeReloaded...");
try { try {
Settings.reload(); Settings.reload();
Messages.getInstance().reloadManager(); Messages.getInstance().reloadManager();
plugin.getModuleManager().reloadModules(); plugin.getModuleManager().reloadModules();
plugin.setupDatabase(); plugin.setupDatabase();
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage("Error occurred during reload of AuthMe: aborting");
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!"); ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
ConsoleLogger.writeStackTrace(e); ConsoleLogger.writeStackTrace(e);
plugin.stopOrUnload(); plugin.stopOrUnload();
} }
// Show a status message commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
// TODO: add the profiler result
m.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
// AuthMeReloaded reloaded, show a status message
// sender.sendMessage(ChatColor.GREEN + "AuthMeReloaded has been reloaded successfully, took " + p.getTimeFormatted() + "!");
} }
} }

View File

@ -1,12 +1,10 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -15,38 +13,32 @@ import java.util.List;
public class SetEmailCommand implements ExecutableCommand { public class SetEmailCommand implements ExecutableCommand {
@Override @Override
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(final CommandSender sender, List<String> arguments,
// AuthMe plugin instance final CommandService commandService) {
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
// Get the player name and email address // Get the player name and email address
final String playerName = arguments.get(0); final String playerName = arguments.get(0);
final String playerEmail = arguments.get(1); final String playerEmail = arguments.get(1);
// Validate the email address // Validate the email address
if (!Settings.isEmailCorrect(playerEmail)) { if (!Settings.isEmailCorrect(playerEmail)) {
m.send(sender, MessageKey.INVALID_EMAIL); commandService.send(sender, MessageKey.INVALID_EMAIL);
return; return;
} }
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { commandService.runTaskAsynchronously(new Runnable() {
@Override @Override
public void run() { public void run() {
// Validate the user // Validate the user
PlayerAuth auth = plugin.database.getAuth(playerName); PlayerAuth auth = commandService.getDataSource().getAuth(playerName);
if (auth == null) { if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER); commandService.send(sender, MessageKey.UNKNOWN_USER);
return; return;
} }
// Set the email address // Set the email address
auth.setEmail(playerEmail); auth.setEmail(playerEmail);
if (!plugin.database.updateEmail(auth)) { if (!commandService.getDataSource().updateEmail(auth)) {
m.send(sender, MessageKey.ERROR); commandService.send(sender, MessageKey.ERROR);
return; return;
} }
@ -56,7 +48,7 @@ public class SetEmailCommand implements ExecutableCommand {
} }
// Show a status message // Show a status message
m.send(sender, MessageKey.EMAIL_CHANGED_SUCCESS); commandService.send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
} }
}); });

View File

@ -32,22 +32,19 @@ public class UnregisterAdminCommand implements ExecutableCommand {
// AuthMe plugin instance // AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance(); final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
// Get the player name // Get the player name
String playerName = arguments.get(0); String playerName = arguments.get(0);
String playerNameLowerCase = playerName.toLowerCase(); String playerNameLowerCase = playerName.toLowerCase();
// Make sure the user is valid // Make sure the user is valid
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) { if (!commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
m.send(sender, MessageKey.UNKNOWN_USER); commandService.send(sender, MessageKey.UNKNOWN_USER);
return; return;
} }
// Remove the player // Remove the player
if (!plugin.database.removeAuth(playerNameLowerCase)) { if (!commandService.getDataSource().removeAuth(playerNameLowerCase)) {
m.send(sender, MessageKey.ERROR); commandService.send(sender, MessageKey.ERROR);
return; return;
} }
@ -67,17 +64,16 @@ public class UnregisterAdminCommand implements ExecutableCommand {
} }
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId( LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
scheduler.runTaskAsynchronously(plugin, scheduler.runTaskAsynchronously(plugin,
new MessageTask(plugin, playerNameLowerCase, m.retrieve(MessageKey.REGISTER_MESSAGE), interval))); new MessageTask(plugin, playerNameLowerCase, commandService.retrieveMessage(MessageKey.REGISTER_MESSAGE), interval)));
if (Settings.applyBlindEffect) { if (Settings.applyBlindEffect) {
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,
Settings.getRegistrationTimeout * 20, 2)); Settings.getRegistrationTimeout * 20, 2));
} }
m.send(target, MessageKey.UNREGISTERED_SUCCESS); commandService.send(target, MessageKey.UNREGISTERED_SUCCESS);
} }
// Show a status message // Show a status message
m.send(sender, MessageKey.UNREGISTERED_SUCCESS); commandService.send(sender, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(playerName + " unregistered"); ConsoleLogger.info(playerName + " unregistered");
} }
} }

View File

@ -16,17 +16,21 @@ public class VersionCommand implements ExecutableCommand {
@Override @Override
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
// Show some version info // Show some version info
sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader.toUpperCase() + " ABOUT ]=========="); sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader + " ABOUT ]==========");
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName() + " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")"); sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName()
+ " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
sender.sendMessage(ChatColor.GOLD + "Developers:"); sender.sendMessage(ChatColor.GOLD + "Developers:");
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer"); printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
printDeveloper(sender, "DNx5", "DNx5", "Developer"); printDeveloper(sender, "DNx5", "DNx5", "Developer");
printDeveloper(sender, "games647", "games647", "Developer"); printDeveloper(sender, "games647", "games647", "Developer");
printDeveloper(sender, "Tim Visee", "timvisee", "Developer"); printDeveloper(sender, "Tim Visee", "timvisee", "Developer");
printDeveloper(sender, "Sgdc3", "sgdc3", "Project manager, Contributor"); printDeveloper(sender, "Sgdc3", "sgdc3", "Project manager, Contributor");
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE + "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/"); sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE +
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0" + ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)"); "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE + "Copyright (c) Xephi 2015. All rights reserved."); sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0"
+ ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE
+ "Copyright (c) Xephi 2015. All rights reserved.");
} }
/** /**
@ -37,22 +41,21 @@ public class VersionCommand implements ExecutableCommand {
* @param minecraftName The Minecraft username of the developer, if available. * @param minecraftName The Minecraft username of the developer, if available.
* @param function The function of the developer. * @param function The function of the developer.
*/ */
@SuppressWarnings("StringConcatenationInsideStringBufferAppend") private static void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
// Print the name // Print the name
StringBuilder msg = new StringBuilder(); StringBuilder msg = new StringBuilder();
msg.append(" " + ChatColor.WHITE); msg.append(" ")
msg.append(name); .append(ChatColor.WHITE)
.append(name);
// Append the Minecraft name, if available // Append the Minecraft name
if (minecraftName.length() != 0) msg.append(ChatColor.GRAY).append(" // ").append(ChatColor.WHITE).append(minecraftName);
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName); msg.append(ChatColor.GRAY).append(ChatColor.ITALIC).append(" (").append(function).append(")");
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
// Show the online status // Show the online status
if (minecraftName.length() != 0) if (isPlayerOnline(minecraftName)) {
if (isPlayerOnline(minecraftName)) msg.append(ChatColor.GREEN).append(ChatColor.ITALIC).append(" (In-Game)");
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)"); }
// Print the message // Print the message
sender.sendMessage(msg.toString()); sender.sendMessage(msg.toString());
@ -65,7 +68,7 @@ public class VersionCommand implements ExecutableCommand {
* *
* @return True if the player is online, false otherwise. * @return True if the player is online, false otherwise.
*/ */
private boolean isPlayerOnline(String minecraftName) { private static boolean isPlayerOnline(String minecraftName) {
// Note ljacqu 20151121: Generally you should use Utils#getOnlinePlayers to retrieve the list of online players. // Note ljacqu 20151121: Generally you should use Utils#getOnlinePlayers to retrieve the list of online players.
// If it's only used in a for-each loop such as here, it's fine. For other purposes, go through the Utils class. // If it's only used in a for-each loop such as here, it's fine. For other purposes, go through the Utils class.
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -247,14 +247,14 @@ public final class Utils {
} }
} }
@SuppressWarnings("deprecation")
public static Player getPlayer(String name) { public static Player getPlayer(String name) {
name = name.toLowerCase(); name = name.toLowerCase();
return wrapper.getServer().getPlayer(name); return wrapper.getServer().getPlayer(name);
} }
public static boolean isNPC(Player player) { public static boolean isNPC(Player player) {
return player.hasMetadata("NPC") || plugin.combatTagPlus != null && plugin.combatTagPlus.getNpcPlayerHelper().isNpc(player); return player.hasMetadata("NPC") || plugin.combatTagPlus != null
&& plugin.combatTagPlus.getNpcPlayerHelper().isNpc(player);
} }
public static void teleportToSpawn(Player player) { public static void teleportToSpawn(Player player) {

View File

@ -25,7 +25,7 @@ public class CommandPageCreater implements ToolTask {
@Override @Override
public void execute(Scanner scanner) { public void execute(Scanner scanner) {
final Set<CommandDescription> baseCommands = CommandInitializer.getBaseCommands(); final Set<CommandDescription> baseCommands = CommandInitializer.buildCommands();
final String template = FileUtils.readFromFile(ToolsConstants.TOOLS_SOURCE_ROOT final String template = FileUtils.readFromFile(ToolsConstants.TOOLS_SOURCE_ROOT
+ "commands/command_entry.tpl.md"); + "commands/command_entry.tpl.md");