Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into configme-integration

Conflicts:
	pom.xml
This commit is contained in:
ljacqu
2016-09-04 15:25:18 +02:00
22 changed files with 529 additions and 381 deletions
@@ -282,7 +282,7 @@ public class CommandInitializer {
.description("Converter command")
.detailedDescription("Converter command for AuthMeReloaded.")
.withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " +
"royalauth / vauth / sqlitetosql", false)
"royalauth / vauth / sqliteToSql / mysqlToSqlite", false)
.permission(AdminPermission.CONVERTER)
.executableCommand(ConverterCommand.class)
.build();
@@ -2,11 +2,13 @@ package fr.xephi.authme.command.executable.authme;
import ch.jalu.injector.Injector;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.converter.Converter;
import fr.xephi.authme.converter.CrazyLoginConverter;
import fr.xephi.authme.converter.MySqlToSqlite;
import fr.xephi.authme.converter.RakamakConverter;
import fr.xephi.authme.converter.RoyalAuthConverter;
import fr.xephi.authme.converter.SqliteToSql;
@@ -18,12 +20,16 @@ import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import java.util.List;
import java.util.Map;
/**
* Converter command: launches conversion based on its parameters.
*/
public class ConverterCommand implements ExecutableCommand {
@VisibleForTesting
static final Map<String, Class<? extends Converter>> CONVERTERS = getConverters();
@Inject
private CommandService commandService;
@@ -39,14 +45,14 @@ public class ConverterCommand implements ExecutableCommand {
String job = arguments.get(0);
// Determine the job type
ConvertType jobType = ConvertType.fromName(job);
if (jobType == null) {
commandService.send(sender, MessageKey.ERROR);
Class<? extends Converter> converterClass = CONVERTERS.get(job.toLowerCase());
if (converterClass == null) {
sender.sendMessage("[AuthMe] Converter does not exist!");
return;
}
// Get the proper converter instance
final Converter converter = injector.newInstance(jobType.getConverterClass());
final Converter converter = injector.newInstance(converterClass);
// Run the convert job
bukkitService.runTaskAsynchronously(new Runnable() {
@@ -55,47 +61,31 @@ public class ConverterCommand implements ExecutableCommand {
try {
converter.execute(sender);
} catch (Exception e) {
commandService.send(sender, MessageKey.ERROR);
ConsoleLogger.logException("Error during conversion:", e);
}
}
});
// Show a status message
sender.sendMessage("[AuthMe] Successfully converted from " + jobType.getName());
sender.sendMessage("[AuthMe] Successfully started " + job);
}
@VisibleForTesting
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);
private final String name;
private final Class<? extends Converter> converterClass;
ConvertType(String name, Class<? extends Converter> converterClass) {
this.name = name;
this.converterClass = converterClass;
}
public static ConvertType fromName(String name) {
for (ConvertType type : ConvertType.values()) {
if (type.getName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
public String getName() {
return this.name;
}
public Class<? extends Converter> getConverterClass() {
return converterClass;
}
/**
* Initializes a map with all available converters.
*
* @return map with all available converters
*/
private static Map<String, Class<? extends Converter>> getConverters() {
return ImmutableMap.<String, Class<? extends Converter>>builder()
.put("xauth", xAuthConverter.class)
.put("crazylogin", CrazyLoginConverter.class)
.put("rakamak", RakamakConverter.class)
.put("royalauth", RoyalAuthConverter.class)
.put("vauth", vAuthConverter.class)
.put("sqlitetosql", SqliteToSql.class)
.put("mysqltosqlite", MySqlToSqlite.class)
.build();
}
}