Add a way to convert SQLite to MySQL (/converter sqlitetosql)

This commit is contained in:
Xephi 2015-12-21 15:43:36 +01:00
parent 8f09893337
commit 37eedfde62
2 changed files with 52 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import fr.xephi.authme.converter.FlatToSqlite;
import fr.xephi.authme.converter.RakamakConverter;
import fr.xephi.authme.converter.RoyalAuthConverter;
import fr.xephi.authme.converter.SqlToFlat;
import fr.xephi.authme.converter.SqliteToSql;
import fr.xephi.authme.converter.vAuthConverter;
import fr.xephi.authme.converter.xAuthConverter;
import fr.xephi.authme.output.MessageKey;
@ -65,6 +66,9 @@ public class ConverterCommand extends ExecutableCommand {
case SQLTOFLAT:
converter = new SqlToFlat(plugin, sender);
break;
case SQLITETOSQL:
converter = new SqliteToSql(plugin, sender);
break;
default:
break;
}
@ -84,7 +88,8 @@ public class ConverterCommand extends ExecutableCommand {
RAKAMAK("rakamak"),
ROYALAUTH("royalauth"),
VAUTH("vauth"),
SQLTOFLAT("sqltoflat");
SQLTOFLAT("sqltoflat"),
SQLITETOSQL("sqlitetosql");
final String name;

View File

@ -0,0 +1,46 @@
package fr.xephi.authme.converter;
import java.sql.SQLException;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource.DataSourceType;
import fr.xephi.authme.datasource.SQLite;
import fr.xephi.authme.output.MessageKey;
public class SqliteToSql implements Converter {
private AuthMe plugin;
private CommandSender sender;
public SqliteToSql(AuthMe plugin, CommandSender sender) {
this.plugin = plugin;
this.sender = sender;
}
@Override
public void run() {
if (plugin.database.getType() != DataSourceType.MYSQL)
{
sender.sendMessage("Please config your mySQL connection and re-run this command");
return;
}
try {
SQLite data = new SQLite();
for (PlayerAuth auth : data.getAllAuths())
{
plugin.database.saveAuth(auth);
}
sender.sendMessage("Convert command has finished !");
} catch (ClassNotFoundException e) {
sender.sendMessage(plugin.getMessages().retrieve(MessageKey.ERROR));
e.printStackTrace();
} catch (SQLException e) {
sender.sendMessage(plugin.getMessages().retrieve(MessageKey.ERROR));
e.printStackTrace();
}
}
}