Change to new HelpProvider, adjust classes to new methods

This commit is contained in:
ljacqu
2015-12-13 10:12:54 +01:00
parent 01cba2a508
commit c48c56f08c
18 changed files with 117 additions and 512 deletions
@@ -1,28 +1,54 @@
package fr.xephi.authme.command.executable;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandHandler;
import fr.xephi.authme.command.CommandUtils;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.command.help.HelpProvider;
import fr.xephi.authme.permission.PermissionsManager;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.List;
/**
*/
import static fr.xephi.authme.command.FoundCommandResult.ResultStatus.*;
public class HelpCommand extends ExecutableCommand {
// Convention: arguments is not the actual invoked arguments but the command that was invoked,
// e.g. "/authme help register" would typically be arguments = [register], but here we pass [authme, register]
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Check whether quick help should be shown
List<String> arguments = commandArguments.getList();
public void executeCommand(CommandSender sender, List<String> arguments) {
// TODO #306 ljacqu 20151213: Get command handler from non-static context
CommandHandler commandHandler = AuthMe.getInstance().getCommandHandler();
FoundCommandResult foundCommandResult = commandHandler.mapPartsToCommand(arguments);
// Set the proper command arguments for the quick help and show it
if (arguments.isEmpty()) {
commandArguments = new CommandParts(commandReference.get(0));
HelpProvider.showHelp(sender, commandReference, commandArguments, false, false, false, false, false, true);
} else {
HelpProvider.showHelp(sender, commandReference, commandArguments);
// TODO ljacqu 20151213: This is essentially the same logic as in CommandHandler and we'd like to have the same
// messages. Maybe we can have another method in CommandHandler where the end command isn't executed upon
// success.
FoundCommandResult.ResultStatus resultStatus = foundCommandResult.getResultStatus();
if (MISSING_BASE_COMMAND.equals(resultStatus)) {
sender.sendMessage(ChatColor.DARK_RED + "Could not get base command");
return;
} else if (INCORRECT_ARGUMENTS.equals(resultStatus) || UNKNOWN_LABEL.equals(resultStatus)) {
if (foundCommandResult.getCommandDescription() != null) {
sender.sendMessage(ChatColor.DARK_RED + "Unknown command");
return;
} else {
sender.sendMessage(ChatColor.GOLD + "Assuming " + ChatColor.WHITE + "/"
+ CommandUtils.labelsToString(foundCommandResult.getCommandDescription().getLabels()));
}
}
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
List<String> lines = arguments.size() == 1
? HelpProvider.printHelp(foundCommandResult, HelpProvider.SHOW_CHILDREN)
: HelpProvider.printHelp(foundCommandResult, sender, permissionsManager, HelpProvider.ALL_OPTIONS);
for (String line : lines) {
sender.sendMessage(line);
}
return true;
}
}
@@ -16,19 +16,14 @@ public class AccountsCommand extends ExecutableCommand {
final AuthMe plugin = AuthMe.getInstance();
final Messages m = plugin.getMessages();
// Get the player query
String playerQuery = sender.getName();
if (commandArguments.getCount() >= 1) {
playerQuery = commandArguments.get(0);
}
final String playerQueryFinal = playerQuery;
final String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
// Command logic
if (!playerQueryFinal.contains(".")) {
if (!playerName.contains(".")) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
PlayerAuth auth = plugin.database.getAuth(playerQueryFinal.toLowerCase());
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
if (auth == null) {
m.send(sender, MessageKey.UNKNOWN_USER);
return;
@@ -40,7 +35,7 @@ public class AccountsCommand extends ExecutableCommand {
return;
}
if (accountList.size() == 1) {
sender.sendMessage("[AuthMe] " + playerQueryFinal + " is a single account player");
sender.sendMessage("[AuthMe] " + playerName + " is a single account player");
return;
}
int i = 0;
@@ -53,7 +48,7 @@ public class AccountsCommand extends ExecutableCommand {
message.append('.');
}
}
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has "
sender.sendMessage("[AuthMe] " + playerName + " has "
+ String.valueOf(accountList.size()) + " accounts.");
sender.sendMessage(message.toString());
}
@@ -63,14 +58,14 @@ public class AccountsCommand extends ExecutableCommand {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
List<String> accountList = plugin.database.getAllAuthsByIp(playerQueryFinal);
List<String> accountList = plugin.database.getAllAuthsByIp(playerName);
StringBuilder message = new StringBuilder("[AuthMe] ");
if (accountList.isEmpty()) {
sender.sendMessage("[AuthMe] This IP does not exist in the database.");
return;
}
if (accountList.size() == 1) {
sender.sendMessage("[AuthMe] " + playerQueryFinal + " is a single account player");
sender.sendMessage("[AuthMe] " + playerName + " is a single account player");
return;
}
int i = 0;
@@ -83,7 +78,7 @@ public class AccountsCommand extends ExecutableCommand {
message.append('.');
}
}
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has "
sender.sendMessage("[AuthMe] " + playerName + " has "
+ String.valueOf(accountList.size()) + " accounts.");
sender.sendMessage(message.toString());
}
@@ -14,7 +14,7 @@ import java.util.List;
public class SetEmailCommand extends ExecutableCommand {
@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
public void executeCommand(final CommandSender sender, List<String> arguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
@@ -59,6 +59,5 @@ public class SetEmailCommand extends ExecutableCommand {
}
});
return true;
}
}
@@ -1,53 +1,43 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AntiBot;
import fr.xephi.authme.command.CommandUtils;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandHandler;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.command.help.HelpProvider;
import fr.xephi.authme.util.CollectionUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.Arrays;
import java.util.List;
public class SwitchAntiBotCommand extends ExecutableCommand {
@Override
public void executeCommand(final CommandSender sender, List<String> arguments) {
// Get the new state
String newState = null;
if (arguments.size() == 1) {
newState = arguments.get(0);
} else if (arguments.size() == 0) {
if (arguments.isEmpty()) {
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
return;
}
// Enable the mod
String newState = arguments.get(0);
// Enable or disable the mod
if ("ON".equalsIgnoreCase(newState)) {
AntiBot.overrideAntiBotStatus(true);
sender.sendMessage("[AuthMe] AntiBot Manual Override: enabled!");
return;
}
// Disable the mod
if ("OFF".equalsIgnoreCase(newState)) {
} else if ("OFF".equalsIgnoreCase(newState)) {
AntiBot.overrideAntiBotStatus(false);
sender.sendMessage("[AuthMe] AntiBotMod Manual Override: disabled!");
return;
} else {
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");
// TODO ljacqu 20151213: Fix static retrieval of command handler
CommandHandler commandHandler = AuthMe.getInstance().getCommandHandler();
FoundCommandResult foundCommandResult =
commandHandler.mapPartsToCommand(Arrays.asList("authme", "antibot"));
HelpProvider.printHelp(foundCommandResult, HelpProvider.SHOW_ARGUMENTS);
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/authme help antibot");
}
// Show the invalid arguments warning
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");
// Show the command argument help
// FIXME fix help reference
HelpProvider.showHelp(sender, commandReference, commandReference, true, false, true, false, false, false);
// Show the command to use for detailed help
List<String> helpCommandReference = CollectionUtils.getRange(commandReference.getList(), 1);
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/"
+ commandReference.get(0) + " help " + CommandUtils.labelsToString(helpCommandReference));
}
}