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

View File

@ -1,46 +1,33 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.permission.PlayerPermission;
import org.bukkit.Bukkit;
import fr.xephi.authme.util.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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 {
@Override
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Get the player query
String playerName = sender.getName();
if (arguments.size() >= 1) {
playerName = arguments.get(0);
}
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Command logic
try {
// TODO ljacqu 20151212: Retrieve player via Utils method instead
Player player = Bukkit.getPlayer(playerName);
if (player == null || !player.isOnline()) {
sender.sendMessage("Player needs to be online!");
return;
}
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
sender.sendMessage("You cannot force login for the player " + playerName + "!");
return;
}
plugin.getManagement().performLogin(player, "dontneed", true);
Player player = Utils.getPlayer(playerName);
if (player == null || !player.isOnline()) {
sender.sendMessage("Player needs to be online!");
} else if (!commandService.getPermissionsManager()
.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
sender.sendMessage("You cannot force login for the player " + playerName + "!");
} else {
commandService.getManagement().performLogin(player, "dontneed", true);
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;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender;
import java.util.List;
@ -16,16 +14,11 @@ public class GetEmailCommand implements ExecutableCommand {
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Get the authenticated user
AuthMe plugin = AuthMe.getInstance();
Messages m = plugin.getMessages();
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER);
return;
commandService.send(sender, MessageKey.UNKNOWN_USER);
} else {
sender.sendMessage("[AuthMe] " + playerName + "'s email: " + auth.getEmail());
}
// Show the email address
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.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -18,8 +19,7 @@ public class GetIpCommand implements ExecutableCommand {
// Get the player query
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
// TODO ljacqu 20151212: Use the Utils function instead
Player player = Bukkit.getPlayer(playerName);
Player player = Utils.getPlayer(playerName);
if (player == null) {
sender.sendMessage("The player is not online");
return;

View File

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

View File

@ -1,14 +1,10 @@
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.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
@ -16,38 +12,24 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
@Override
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);
// Get the player
String playerNameLowerCase = playerName.toLowerCase();
// Purge the last position of the player
try {
// Get the user auth and make sure the user exists
PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase);
if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER);
return;
}
// Set the last position
auth.setQuitLocX(0D);
auth.setQuitLocY(0D);
auth.setQuitLocZ(0D);
auth.setWorld("world");
plugin.database.updateQuitLoc(auth);
// Show a status message
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");
// Get the user auth and make sure the user exists
PlayerAuth auth = commandService.getDataSource().getAuth(playerNameLowerCase);
if (auth == null) {
commandService.send(sender, MessageKey.UNKNOWN_USER);
return;
}
// Set the last position
auth.setQuitLocX(0D);
auth.setQuitLocY(0D);
auth.setQuitLocZ(0D);
auth.setWorld("world");
commandService.getDataSource().updateQuitLoc(auth);
// Show a status message
sender.sendMessage(playerNameLowerCase + "'s last position location is now reset");
}
}

View File

@ -1,12 +1,10 @@
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.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
@ -21,49 +19,43 @@ import java.util.List;
public class RegisterAdminCommand implements ExecutableCommand {
@Override
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
public void executeCommand(final CommandSender sender, List<String> arguments,
final CommandService commandService) {
// Get the player name and password
final String playerName = arguments.get(0);
final String playerPass = arguments.get(1);
final String playerName = arguments.get(0).toLowerCase();
final String playerPass = arguments.get(1).toLowerCase();
final String playerNameLowerCase = playerName.toLowerCase();
final String playerPassLowerCase = playerPass.toLowerCase();
// Command logic
// TODO #308: Remove the check for SQL keywords
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
m.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
commandService.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
return;
}
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
commandService.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
return;
}
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
commandService.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
return;
}
if (!Settings.unsafePasswords.isEmpty()) {
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
return;
}
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
commandService.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
return;
}
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@SuppressWarnings("deprecation")
commandService.runTaskAsynchronously(new Runnable() {
@Override
public void run() {
try {
if (plugin.database.isAuthAvailable(playerNameLowerCase)) {
m.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
if (commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
commandService.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
return;
}
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)
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
else auth.setSalt("");
if (!plugin.database.saveAuth(auth)) {
m.send(sender, MessageKey.ERROR);
if (!commandService.getDataSource().saveAuth(auth)) {
commandService.send(sender, MessageKey.ERROR);
return;
}
plugin.database.setUnlogged(playerNameLowerCase);
commandService.getDataSource().setUnlogged(playerNameLowerCase);
if (Bukkit.getPlayerExact(playerName) != null)
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");
} catch (NoSuchAlgorithmException ex) {
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
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
// Profile the reload process
Profiler p = new Profiler(true);
// AuthMe plugin instance
AuthMe plugin = AuthMe.getInstance();
// Messages instance
Messages m = plugin.getMessages();
// Show a status message
// sender.sendMessage(ChatColor.YELLOW + "Reloading AuthMeReloaded...");
try {
Settings.reload();
Messages.getInstance().reloadManager();
plugin.getModuleManager().reloadModules();
plugin.setupDatabase();
} catch (Exception e) {
sender.sendMessage("Error occurred during reload of AuthMe: aborting");
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
ConsoleLogger.writeStackTrace(e);
plugin.stopOrUnload();
}
// Show a status message
// 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() + "!");
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
}
}

View File

@ -1,12 +1,10 @@
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.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
@ -15,38 +13,32 @@ import java.util.List;
public class SetEmailCommand implements ExecutableCommand {
@Override
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
public void executeCommand(final CommandSender sender, List<String> arguments,
final CommandService commandService) {
// Get the player name and email address
final String playerName = arguments.get(0);
final String playerEmail = arguments.get(1);
// Validate the email address
if (!Settings.isEmailCorrect(playerEmail)) {
m.send(sender, MessageKey.INVALID_EMAIL);
commandService.send(sender, MessageKey.INVALID_EMAIL);
return;
}
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
commandService.runTaskAsynchronously(new Runnable() {
@Override
public void run() {
// Validate the user
PlayerAuth auth = plugin.database.getAuth(playerName);
PlayerAuth auth = commandService.getDataSource().getAuth(playerName);
if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER);
commandService.send(sender, MessageKey.UNKNOWN_USER);
return;
}
// Set the email address
auth.setEmail(playerEmail);
if (!plugin.database.updateEmail(auth)) {
m.send(sender, MessageKey.ERROR);
if (!commandService.getDataSource().updateEmail(auth)) {
commandService.send(sender, MessageKey.ERROR);
return;
}
@ -56,7 +48,7 @@ public class SetEmailCommand implements ExecutableCommand {
}
// 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
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = plugin.getMessages();
// Get the player name
String playerName = arguments.get(0);
String playerNameLowerCase = playerName.toLowerCase();
// Make sure the user is valid
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
m.send(sender, MessageKey.UNKNOWN_USER);
if (!commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
commandService.send(sender, MessageKey.UNKNOWN_USER);
return;
}
// Remove the player
if (!plugin.database.removeAuth(playerNameLowerCase)) {
m.send(sender, MessageKey.ERROR);
if (!commandService.getDataSource().removeAuth(playerNameLowerCase)) {
commandService.send(sender, MessageKey.ERROR);
return;
}
@ -67,17 +64,16 @@ public class UnregisterAdminCommand implements ExecutableCommand {
}
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
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) {
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,
Settings.getRegistrationTimeout * 20, 2));
}
m.send(target, MessageKey.UNREGISTERED_SUCCESS);
commandService.send(target, MessageKey.UNREGISTERED_SUCCESS);
}
// Show a status message
m.send(sender, MessageKey.UNREGISTERED_SUCCESS);
commandService.send(sender, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(playerName + " unregistered");
}
}

View File

@ -16,17 +16,21 @@ public class VersionCommand implements ExecutableCommand {
@Override
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
// Show some version info
sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader.toUpperCase() + " ABOUT ]==========");
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName() + " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
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 + "Developers:");
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
printDeveloper(sender, "DNx5", "DNx5", "Developer");
printDeveloper(sender, "games647", "games647", "Developer");
printDeveloper(sender, "Tim Visee", "timvisee", "Developer");
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 + "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.");
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE +
"http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
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 function The function of the developer.
*/
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
private static void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
// Print the name
StringBuilder msg = new StringBuilder();
msg.append(" " + ChatColor.WHITE);
msg.append(name);
msg.append(" ")
.append(ChatColor.WHITE)
.append(name);
// Append the Minecraft name, if available
if (minecraftName.length() != 0)
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName);
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
// Append the Minecraft name
msg.append(ChatColor.GRAY).append(" // ").append(ChatColor.WHITE).append(minecraftName);
msg.append(ChatColor.GRAY).append(ChatColor.ITALIC).append(" (").append(function).append(")");
// Show the online status
if (minecraftName.length() != 0)
if (isPlayerOnline(minecraftName))
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)");
if (isPlayerOnline(minecraftName)) {
msg.append(ChatColor.GREEN).append(ChatColor.ITALIC).append(" (In-Game)");
}
// Print the message
sender.sendMessage(msg.toString());
@ -65,7 +68,7 @@ public class VersionCommand implements ExecutableCommand {
*
* @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.
// 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()) {

View File

@ -247,14 +247,14 @@ public final class Utils {
}
}
@SuppressWarnings("deprecation")
public static Player getPlayer(String name) {
name = name.toLowerCase();
return wrapper.getServer().getPlayer(name);
}
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) {

View File

@ -25,7 +25,7 @@ public class CommandPageCreater implements ToolTask {
@Override
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
+ "commands/command_entry.tpl.md");