Implemented convert command

This commit is contained in:
Tim Visée 2015-11-01 21:44:13 +01:00
parent bd6a95c3a8
commit dc0129d980
3 changed files with 141 additions and 2 deletions

View File

@ -344,7 +344,7 @@ public class AuthMe extends JavaPlugin {
pm.registerEvents(new AuthMeEntityListener(this), this);
pm.registerEvents(new AuthMeServerListener(this), this);
// TODO: This is moving to AuthMe.onCommand();
// TODO: This is moved to CommandManager.registerCommands() handled by AuthMe.onCommand() -- timvisee
// Register commands
//getCommand("authme").setExecutor(new AdminCommand(this));
//getCommand("register").setExecutor(new RegisterCommand(this));
@ -354,7 +354,7 @@ public class AuthMe extends JavaPlugin {
//getCommand("unregister").setExecutor(new UnregisterCommand(this));
//getCommand("email").setExecutor(new EmailCommand(this));
//getCommand("captcha").setExecutor(new CaptchaCommand(this));
getCommand("converter").setExecutor(new ConverterCommand(this));
//getCommand("converter").setExecutor(new ConverterCommand(this));
// Purge on start if enabled
autoPurge();

View File

@ -575,6 +575,36 @@ public class CommandManager {
captchaHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
captchaHelpCommand.setMaximumArguments(false);
// Register the base converter command
CommandDescription converterBaseCommand = new CommandDescription(
new ChangePasswordCommand(),
new ArrayList<String>() {{
add("convert");
add("converter");
add("conv");
}},
"Convert command",
"Convert command for AuthMeReloaded.", null);
converterBaseCommand.setCommandPermissions("authme.converter", CommandPermissions.DefaultPermission.ALLOWED);
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
converterBaseCommand.setMaximumArguments(false);
// Register the help command
CommandDescription converterHelpCommand = new CommandDescription(
new HelpCommand(),
new ArrayList<String>() {{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}},
"View help",
"View detailed help pages about AuthMeReloaded change captcha commands.",
converterBaseCommand);
converterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
converterHelpCommand.setMaximumArguments(false);
// Add the base commands to the commands array
this.commandDescriptions.add(authMeBaseCommand);
this.commandDescriptions.add(loginBaseCommand);
@ -584,6 +614,7 @@ public class CommandManager {
this.commandDescriptions.add(changePasswordBaseCommand);
this.commandDescriptions.add(emailBaseCommand);
this.commandDescriptions.add(captchaBaseCommand);
this.commandDescriptions.add(converterBaseCommand);
}
/**

View File

@ -0,0 +1,108 @@
package fr.xephi.authme.command.executable.converter;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.converter.*;
import fr.xephi.authme.settings.Messages;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ConverterCommand extends ExecutableCommand {
/**
* Execute the command.
*
* @param sender The command sender.
* @param commandReference The command reference.
* @param commandArguments The command arguments.
*
* @return True if the command was executed successfully, false otherwise.
*/
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = Messages.getInstance();
// Get the conversion job
String job = commandArguments.get(0);
// Determine the job type
ConvertType jobType = ConvertType.fromName(job);
if (jobType == null) {
m.send(sender, "error");
return true;
}
// Get the proper converter instance
Converter converter = null;
switch (jobType) {
case ftsql:
converter = new FlatToSql();
break;
case ftsqlite:
converter = new FlatToSqlite(sender);
break;
case xauth:
converter = new xAuthConverter(plugin, sender);
break;
case crazylogin:
converter = new CrazyLoginConverter(plugin, sender);
break;
case rakamak:
converter = new RakamakConverter(plugin, sender);
break;
case royalauth:
converter = new RoyalAuthConverter(plugin);
break;
case vauth:
converter = new vAuthConverter(plugin, sender);
break;
case sqltoflat:
converter = new SqlToFlat(plugin, sender);
break;
default:
break;
}
// Run the convert job
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
// Show a status message
sender.sendMessage("[AuthMe] Successfully converted from " + jobType.getName());
return true;
}
public enum ConvertType {
ftsql("flattosql"),
ftsqlite("flattosqlite"),
xauth("xauth"),
crazylogin("crazylogin"),
rakamak("rakamak"),
royalauth("royalauth"),
vauth("vauth"),
sqltoflat("sqltoflat");
String name;
ConvertType(String name) {
this.name = name;
}
String getName() {
return this.name;
}
public static ConvertType fromName(String name) {
for (ConvertType type : ConvertType.values()) {
if (type.getName().equalsIgnoreCase(name))
return type;
}
return null;
}
}
}