Revise converter architecture + add integration test for CrazyLogin converter

This commit is contained in:
ljacqu
2016-05-27 23:00:44 +02:00
parent 67511e3b45
commit 87331d116c
13 changed files with 217 additions and 102 deletions
@@ -10,6 +10,7 @@ import fr.xephi.authme.converter.RoyalAuthConverter;
import fr.xephi.authme.converter.SqliteToSql;
import fr.xephi.authme.converter.vAuthConverter;
import fr.xephi.authme.converter.xAuthConverter;
import fr.xephi.authme.initialization.AuthMeServiceInitializer;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.util.BukkitService;
import org.bukkit.command.CommandSender;
@@ -17,6 +18,9 @@ import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import java.util.List;
/**
* Converter command: launches conversion based on its parameters.
*/
public class ConverterCommand implements ExecutableCommand {
@Inject
@@ -25,8 +29,11 @@ public class ConverterCommand implements ExecutableCommand {
@Inject
private BukkitService bukkitService;
@Inject
private AuthMeServiceInitializer initializer;
@Override
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
// Get the conversion job
String job = arguments.get(0);
@@ -38,49 +45,34 @@ public class ConverterCommand implements ExecutableCommand {
}
// Get the proper converter instance
Converter converter = null;
switch (jobType) {
case XAUTH:
converter = new xAuthConverter(authMe, sender);
break;
case CRAZYLOGIN:
converter = new CrazyLoginConverter(authMe, sender);
break;
case RAKAMAK:
converter = new RakamakConverter(authMe, sender);
break;
case ROYALAUTH:
converter = new RoyalAuthConverter(authMe);
break;
case VAUTH:
converter = new vAuthConverter(authMe, sender);
break;
case SQLITETOSQL:
converter = new SqliteToSql(authMe, sender, commandService.getSettings());
break;
default:
break;
}
final Converter converter = initializer.newInstance(jobType.getConverterClass());
// Run the convert job
bukkitService.runTaskAsynchronously(converter);
bukkitService.runTaskAsynchronously(new Runnable() {
@Override
public void run() {
converter.execute(sender);
}
});
// Show a status message
sender.sendMessage("[AuthMe] Successfully converted from " + jobType.getName());
}
public enum ConvertType {
XAUTH("xauth"),
CRAZYLOGIN("crazylogin"),
RAKAMAK("rakamak"),
ROYALAUTH("royalauth"),
VAUTH("vauth"),
SQLITETOSQL("sqlitetosql");
private enum ConvertType {
XAUTH("xauth", xAuthConverter.class),
CRAZYLOGIN("crazylogin", CrazyLoginConverter.class),
RAKAMAK("rakamak", RakamakConverter.class),
ROYALAUTH("royalauth", RoyalAuthConverter.class),
VAUTH("vauth", vAuthConverter.class),
SQLITETOSQL("sqlitetosql", SqliteToSql.class);
final String name;
private final String name;
private final Class<? extends Converter> converterClass;
ConvertType(String name) {
ConvertType(String name, Class<? extends Converter> converterClass) {
this.name = name;
this.converterClass = converterClass;
}
public static ConvertType fromName(String name) {
@@ -92,8 +84,12 @@ public class ConverterCommand implements ExecutableCommand {
return null;
}
String getName() {
public String getName() {
return this.name;
}
public Class<? extends Converter> getConverterClass() {
return converterClass;
}
}
}