Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into configme-integration
Conflicts: pom.xml
This commit is contained in:
@@ -151,7 +151,7 @@ public class AuthMe extends JavaPlugin {
|
||||
ConsoleLogger.info("Do you want a good game server? Look at our sponsor GameHosting.it leader in Italy as Game Server Provider!");
|
||||
|
||||
// Successful message
|
||||
ConsoleLogger.info("AuthMe " + getPluginVersion() + " build n°" + getPluginBuildNumber() + " correctly enabled!");
|
||||
ConsoleLogger.info("AuthMe " + getPluginVersion() + " build n." + getPluginBuildNumber() + " correctly enabled!");
|
||||
|
||||
// Purge on start if enabled
|
||||
PurgeService purgeService = injector.getSingleton(PurgeService.class);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Converts from one AuthMe data source type to another.
|
||||
*
|
||||
* @param <S> the source type to convert from
|
||||
*/
|
||||
public abstract class AbstractDataSourceConverter<S extends DataSource> implements Converter {
|
||||
|
||||
private DataSource destination;
|
||||
private DataSourceType destinationType;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param destination the data source to convert to
|
||||
* @param destinationType the data source type of the destination. The given data source is checked that its
|
||||
* type corresponds to this type before the conversion is started, enabling us to just pass
|
||||
* the current data source and letting this class check that the types correspond.
|
||||
*/
|
||||
public AbstractDataSourceConverter(DataSource destination, DataSourceType destinationType) {
|
||||
this.destination = destination;
|
||||
this.destinationType = destinationType;
|
||||
}
|
||||
|
||||
// Implementation note: Because of ForceFlatToSqlite it is possible that the CommandSender is null,
|
||||
// which is never the case when a converter is launched from the /authme converter command.
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
if (!destinationType.equals(destination.getType())) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage("Please configure your connection to "
|
||||
+ destinationType + " and re-run this command");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
S source;
|
||||
try {
|
||||
source = getSource();
|
||||
} catch (Exception e) {
|
||||
logAndSendMessage(sender, "The data source to convert from could not be initialized");
|
||||
ConsoleLogger.logException("Could not initialize source:", e);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> skippedPlayers = new ArrayList<>();
|
||||
for (PlayerAuth auth : source.getAllAuths()) {
|
||||
if (destination.isAuthAvailable(auth.getNickname())) {
|
||||
skippedPlayers.add(auth.getNickname());
|
||||
} else {
|
||||
destination.saveAuth(auth);
|
||||
destination.updateQuitLoc(auth);
|
||||
}
|
||||
}
|
||||
|
||||
if (!skippedPlayers.isEmpty()) {
|
||||
logAndSendMessage(sender, "Skipped conversion for players which were already in "
|
||||
+ destinationType + ": " + StringUtils.join(", ", skippedPlayers));
|
||||
}
|
||||
logAndSendMessage(sender, "Database successfully converted from " + source.getType()
|
||||
+ " to " + destinationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the data source to convert from
|
||||
* @throws Exception during initialization of source
|
||||
*/
|
||||
protected abstract S getSource() throws Exception;
|
||||
|
||||
private static void logAndSendMessage(CommandSender sender, String message) {
|
||||
ConsoleLogger.info(message);
|
||||
// Make sure sender is not console user, which will see the message from ConsoleLogger already
|
||||
if (sender != null && !(sender instanceof ConsoleCommandSender)) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,14 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.FlatFile;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mandatory migration from the deprecated flat file datasource to SQLite.
|
||||
*/
|
||||
public class ForceFlatToSqlite {
|
||||
public class ForceFlatToSqlite extends AbstractDataSourceConverter<FlatFile> {
|
||||
|
||||
private final DataSource source;
|
||||
private final DataSource destination;
|
||||
private final FlatFile source;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -24,29 +17,12 @@ public class ForceFlatToSqlite {
|
||||
* @param destination The datasource to copy the data to (sqlite)
|
||||
*/
|
||||
public ForceFlatToSqlite(FlatFile source, DataSource destination) {
|
||||
super(destination, destination.getType());
|
||||
this.source = source;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the conversion.
|
||||
*/
|
||||
public void run() {
|
||||
List<String> skippedPlayers = new ArrayList<>();
|
||||
for (PlayerAuth auth : source.getAllAuths()) {
|
||||
if (destination.isAuthAvailable(auth.getNickname())) {
|
||||
skippedPlayers.add(auth.getNickname());
|
||||
} else {
|
||||
destination.saveAuth(auth);
|
||||
destination.updateQuitLoc(auth);
|
||||
}
|
||||
}
|
||||
|
||||
if (!skippedPlayers.isEmpty()) {
|
||||
ConsoleLogger.warning("Warning: skipped conversion for players which were already in SQLite: "
|
||||
+ StringUtils.join(", ", skippedPlayers));
|
||||
}
|
||||
ConsoleLogger.info("Database successfully converted from " + source.getClass().getSimpleName()
|
||||
+ " to " + destination.getClass().getSimpleName());
|
||||
@Override
|
||||
public FlatFile getSource() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Converts from MySQL to SQLite.
|
||||
*/
|
||||
public class MySqlToSqlite extends AbstractDataSourceConverter<MySQL> {
|
||||
|
||||
private final Settings settings;
|
||||
|
||||
@Inject
|
||||
MySqlToSqlite(DataSource dataSource, Settings settings) {
|
||||
super(dataSource, DataSourceType.SQLITE);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MySQL getSource() throws SQLException, ClassNotFoundException {
|
||||
return new MySQL(settings);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,28 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SqliteToSql implements Converter {
|
||||
/**
|
||||
* Converts from SQLite to MySQL.
|
||||
*/
|
||||
public class SqliteToSql extends AbstractDataSourceConverter<SQLite> {
|
||||
|
||||
private final Settings settings;
|
||||
private final DataSource dataSource;
|
||||
private final Messages messages;
|
||||
|
||||
@Inject
|
||||
SqliteToSql(Settings settings, DataSource dataSource, Messages messages) {
|
||||
SqliteToSql(Settings settings, DataSource dataSource) {
|
||||
super(dataSource, DataSourceType.MYSQL);
|
||||
this.settings = settings;
|
||||
this.dataSource = dataSource;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
if (dataSource.getType() != DataSourceType.MYSQL) {
|
||||
sender.sendMessage("Please configure your mySQL connection and re-run this command");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
SQLite data = new SQLite(settings);
|
||||
for (PlayerAuth auth : data.getAllAuths()) {
|
||||
dataSource.saveAuth(auth);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
messages.send(sender, MessageKey.ERROR);
|
||||
ConsoleLogger.logException("Problem during SQLite to SQL conversion:", e);
|
||||
}
|
||||
protected SQLite getSource() throws SQLException, ClassNotFoundException {
|
||||
return new SQLite(settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package fr.xephi.authme.permission;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.permission.handlers.BPermissionsHandler;
|
||||
import fr.xephi.authme.permission.handlers.GroupManagerHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionHandlerException;
|
||||
import fr.xephi.authme.permission.handlers.PermissionsBukkitHandler;
|
||||
@@ -11,7 +10,6 @@ import fr.xephi.authme.permission.handlers.PermissionsExHandler;
|
||||
import fr.xephi.authme.permission.handlers.VaultHandler;
|
||||
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -110,8 +108,6 @@ public class PermissionsManager implements Reloadable {
|
||||
switch (type) {
|
||||
case PERMISSIONS_EX:
|
||||
return new PermissionsExHandler();
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
return new GroupManagerHandler((GroupManager) plugin);
|
||||
case Z_PERMISSIONS:
|
||||
return new ZPermissionsHandler();
|
||||
case VAULT:
|
||||
|
||||
@@ -20,11 +20,6 @@ public enum PermissionsSystemType {
|
||||
*/
|
||||
B_PERMISSIONS("bPermissions", "bPermissions"),
|
||||
|
||||
/**
|
||||
* Essentials Group Manager.
|
||||
*/
|
||||
ESSENTIALS_GROUP_MANAGER("Essentials Group Manager", "GroupManager"),
|
||||
|
||||
/**
|
||||
* zPermissions.
|
||||
*/
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupManagerHandler implements PermissionHandler {
|
||||
|
||||
private GroupManager groupManager;
|
||||
|
||||
public GroupManagerHandler(GroupManager groupManager) {
|
||||
this.groupManager = groupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddsub " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermissionOffline(String name, PermissionNode node) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(name);
|
||||
if(handler == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> perms = handler.getAllPlayersPermissions(name);
|
||||
return perms.contains(node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
return handler != null && handler.inGroup(player.getName(), group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manudelsub " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(Player player, String group) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
for (String groupName : handler.getGroups(player.getName())) {
|
||||
removeFromGroup(player, groupName);
|
||||
}
|
||||
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(Player player) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
if (handler == null)
|
||||
return new ArrayList<>();
|
||||
return Arrays.asList(handler.getGroups(player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
if (handler == null)
|
||||
return null;
|
||||
return handler.getGroup(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsSystemType getPermissionSystem() {
|
||||
return PermissionsSystemType.ESSENTIALS_GROUP_MANAGER;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class SecuritySettings implements SettingsHolder {
|
||||
"- '123456'",
|
||||
"- 'password'"})
|
||||
public static final Property<List<String>> UNSAFE_PASSWORDS =
|
||||
newLowercaseListProperty("settings.security.unsafePasswords", "123456", "password", "qwerty", "12345", "54321");
|
||||
newLowercaseListProperty("settings.security.unsafePasswords", "123456", "password", "qwerty", "12345", "54321", "123456789");
|
||||
|
||||
@Comment("Tempban a user's IP address if they enter the wrong password too many times")
|
||||
public static final Property<Boolean> TEMPBAN_ON_MAX_LOGINS =
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class MigrationService {
|
||||
try {
|
||||
SQLite sqlite = new SQLite(settings);
|
||||
ForceFlatToSqlite converter = new ForceFlatToSqlite(flatFile, sqlite);
|
||||
converter.run();
|
||||
converter.execute(null);
|
||||
settings.setProperty(DatabaseSettings.BACKEND, DataSourceType.SQLITE);
|
||||
settings.save();
|
||||
return sqlite;
|
||||
|
||||
Reference in New Issue
Block a user