#1539 Add support for columns that are not on player auth (is_logged, has_session)

This commit is contained in:
ljacqu 2018-03-25 11:52:40 +02:00
parent 137fc3d505
commit 4595a14191
21 changed files with 257 additions and 302 deletions

View File

@ -1,8 +1,8 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSourceResult;
import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.CommonService;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -25,8 +25,8 @@ public class GetEmailCommand implements ExecutableCommand {
public void executeCommand(CommandSender sender, List<String> arguments) { public void executeCommand(CommandSender sender, List<String> arguments) {
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0); String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
DataSourceResult<String> email = dataSource.getEmail(playerName); DataSourceValue<String> email = dataSource.getEmail(playerName);
if (email.playerExists()) { if (email.rowExists()) {
sender.sendMessage("[AuthMe] " + playerName + "'s email: " + email.getValue()); sender.sendMessage("[AuthMe] " + playerName + "'s email: " + email.getValue());
} else { } else {
commonService.send(sender, MessageKey.UNKNOWN_USER); commonService.send(sender, MessageKey.UNKNOWN_USER);

View File

@ -1,8 +1,8 @@
package fr.xephi.authme.command.executable.authme.debug; package fr.xephi.authme.command.executable.authme.debug;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSourceResult;
import fr.xephi.authme.mail.SendMailSsl; import fr.xephi.authme.mail.SendMailSsl;
import fr.xephi.authme.permission.DebugSectionPermissions; import fr.xephi.authme.permission.DebugSectionPermissions;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
@ -82,8 +82,8 @@ class TestEmailSender implements DebugSection {
*/ */
private String getEmail(CommandSender sender, List<String> arguments) { private String getEmail(CommandSender sender, List<String> arguments) {
if (arguments.isEmpty()) { if (arguments.isEmpty()) {
DataSourceResult<String> emailResult = dataSource.getEmail(sender.getName()); DataSourceValue<String> emailResult = dataSource.getEmail(sender.getName());
if (!emailResult.playerExists()) { if (!emailResult.rowExists()) {
sender.sendMessage(ChatColor.RED + "Please provide an email address, " sender.sendMessage(ChatColor.RED + "Please provide an email address, "
+ "e.g. /authme debug mail test@example.com"); + "e.g. /authme debug mail test@example.com");
return null; return null;

View File

@ -1,10 +1,10 @@
package fr.xephi.authme.command.executable.email; package fr.xephi.authme.command.executable.email;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSourceResult;
import fr.xephi.authme.mail.EmailService; import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.BukkitService;
@ -58,8 +58,8 @@ public class RecoverEmailCommand extends PlayerCommand {
return; return;
} }
DataSourceResult<String> emailResult = dataSource.getEmail(playerName); DataSourceValue<String> emailResult = dataSource.getEmail(playerName);
if (!emailResult.playerExists()) { if (!emailResult.rowExists()) {
commonService.send(player, MessageKey.USAGE_REGISTER); commonService.send(player, MessageKey.USAGE_REGISTER);
return; return;
} }

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.data; package fr.xephi.authme.data;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSourceResult;
import fr.xephi.authme.initialization.HasCleanup; import fr.xephi.authme.initialization.HasCleanup;
import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.mail.EmailService; import fr.xephi.authme.mail.EmailService;
@ -103,8 +103,8 @@ public class VerificationCodeManager implements SettingsDependent, HasCleanup {
*/ */
public boolean hasEmail(String name) { public boolean hasEmail(String name) {
boolean result = false; boolean result = false;
DataSourceResult<String> emailResult = dataSource.getEmail(name); DataSourceValue<String> emailResult = dataSource.getEmail(name);
if (emailResult.playerExists()) { if (emailResult.rowExists()) {
final String email = emailResult.getValue(); final String email = emailResult.getValue();
if (!Utils.isEmailEmpty(email)) { if (!Utils.isEmailEmpty(email)) {
result = true; result = true;
@ -130,8 +130,8 @@ public class VerificationCodeManager implements SettingsDependent, HasCleanup {
* @param name the name of the player to generate a code for * @param name the name of the player to generate a code for
*/ */
private void generateCode(String name) { private void generateCode(String name) {
DataSourceResult<String> emailResult = dataSource.getEmail(name); DataSourceValue<String> emailResult = dataSource.getEmail(name);
if (emailResult.playerExists()) { if (emailResult.rowExists()) {
final String email = emailResult.getValue(); final String email = emailResult.getValue();
if (!Utils.isEmailEmpty(email)) { if (!Utils.isEmailEmpty(email)) {
String code = RandomStringUtils.generateNum(6); // 6 digits code String code = RandomStringUtils.generateNum(6); // 6 digits code

View File

@ -1,5 +1,7 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@ -244,10 +246,10 @@ public class CacheDataSource implements DataSource {
} }
@Override @Override
public DataSourceResult<String> getEmail(String user) { public DataSourceValue<String> getEmail(String user) {
return cachedAuths.getUnchecked(user) return cachedAuths.getUnchecked(user)
.map(auth -> DataSourceResult.of(auth.getEmail())) .map(auth -> DataSourceValueImpl.of(auth.getEmail()))
.orElse(DataSourceResult.unknownPlayer()); .orElse(DataSourceValueImpl.unknownRow());
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
@ -216,7 +217,7 @@ public interface DataSource extends Reloadable {
* @param user the user to retrieve an email for * @param user the user to retrieve an email for
* @return the email saved for the user, or null if user or email is not present * @return the email saved for the user, or null if user or email is not present
*/ */
DataSourceResult<String> getEmail(String user); DataSourceValue<String> getEmail(String user);
/** /**
* Return all players of the database. * Return all players of the database.

View File

@ -1,53 +0,0 @@
package fr.xephi.authme.datasource;
/**
* Wraps a value and allows to specify whether a value is missing or the player is not registered.
*/
public final class DataSourceResult<T> {
/** Instance used when a player does not exist. */
private static final DataSourceResult UNKNOWN_PLAYER = new DataSourceResult<>(null);
private final T value;
private DataSourceResult(T value) {
this.value = value;
}
/**
* Returns a {@link DataSourceResult} for the given value.
*
* @param value the value to wrap
* @param <T> the value's type
* @return DataSourceResult object for the given value
*/
public static <T> DataSourceResult<T> of(T value) {
return new DataSourceResult<>(value);
}
/**
* Returns a {@link DataSourceResult} specifying that the player does not exist.
*
* @param <T> the value type
* @return data source result for unknown player
*/
public static <T> DataSourceResult<T> unknownPlayer() {
return UNKNOWN_PLAYER;
}
/**
* @return whether the player of the associated value exists
*/
public boolean playerExists() {
return this != UNKNOWN_PLAYER;
}
/**
* Returns the value. It is {@code null} if the player is unknown. It is also {@code null}
* if the player exists but does not have the value defined.
*
* @return the value, or null
*/
public T getValue() {
return value;
}
}

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
@ -366,7 +367,7 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public DataSourceResult<String> getEmail(String user) { public DataSourceValue<String> getEmail(String user) {
throw new UnsupportedOperationException("Flat file no longer supported"); throw new UnsupportedOperationException("Flat file no longer supported");
} }

View File

@ -1,5 +1,7 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
import ch.jalu.datasourcecolumns.data.DataSourceValues; import ch.jalu.datasourcecolumns.data.DataSourceValues;
import ch.jalu.datasourcecolumns.predicate.AlwaysTruePredicate; import ch.jalu.datasourcecolumns.predicate.AlwaysTruePredicate;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -448,90 +450,49 @@ public class MySQL implements DataSource {
@Override @Override
public boolean isLogged(String user) { public boolean isLogged(String user) {
String sql = "SELECT " + col.IS_LOGGED + " FROM " + tableName + " WHERE " + col.NAME + "=?;"; try {
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.IS_LOGGED);
pst.setString(1, user); return result.rowExists() && Integer.valueOf(1).equals(result.getValue());
try (ResultSet rs = pst.executeQuery()) { } catch (SQLException e) {
return rs.next() && (rs.getInt(col.IS_LOGGED) == 1); logSqlException(e);
} return false;
} catch (SQLException ex) {
logSqlException(ex);
} }
return false;
} }
@Override @Override
public void setLogged(String user) { public void setLogged(String user) {
String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.NAME + "=?;"; columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 1);
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 1);
pst.setString(2, user.toLowerCase());
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(String user) {
String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.NAME + "=?;"; columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 0);
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 0);
pst.setString(2, user.toLowerCase());
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
public boolean hasSession(String user) { public boolean hasSession(String user) {
String sql = "SELECT " + col.HAS_SESSION + " FROM " + tableName + " WHERE " + col.NAME + "=?;"; try {
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.HAS_SESSION);
pst.setString(1, user.toLowerCase()); return result.rowExists() && Integer.valueOf(1).equals(result.getValue());
try (ResultSet rs = pst.executeQuery()) { } catch (SQLException e) {
return rs.next() && (rs.getInt(col.HAS_SESSION) == 1); logSqlException(e);
} return false;
} catch (SQLException ex) {
logSqlException(ex);
} }
return false;
} }
@Override @Override
public void grantSession(String user) { public void grantSession(String user) {
String sql = "UPDATE " + tableName + " SET " + col.HAS_SESSION + "=? WHERE " + col.NAME + "=?;"; columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 1);
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 1);
pst.setString(2, user.toLowerCase());
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
public void revokeSession(String user) { public void revokeSession(String user) {
String sql = "UPDATE " + tableName + " SET " + col.HAS_SESSION + "=? WHERE " + col.NAME + "=?;"; columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 0);
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 0);
pst.setString(2, user.toLowerCase());
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
public void purgeLogged() { public void purgeLogged() {
String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.IS_LOGGED + "=?;"; columnsHandler.update(eq(AuthMeColumns.IS_LOGGED, 1), AuthMeColumns.IS_LOGGED, 0);
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 0);
pst.setInt(2, 1);
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
@ -545,19 +506,13 @@ public class MySQL implements DataSource {
} }
@Override @Override
public DataSourceResult<String> getEmail(String user) { public DataSourceValue<String> getEmail(String user) {
String sql = "SELECT " + col.EMAIL + " FROM " + tableName + " WHERE " + col.NAME + "=?;"; try {
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { return columnsHandler.retrieve(user, AuthMeColumns.EMAIL);
pst.setString(1, user); } catch (SQLException e) {
try (ResultSet rs = pst.executeQuery()) { logSqlException(e);
if (rs.next()) { return DataSourceValueImpl.unknownRow();
return DataSourceResult.of(rs.getString(1));
}
}
} catch (SQLException ex) {
logSqlException(ex);
} }
return DataSourceResult.unknownPlayer();
} }
@Override @Override

View File

@ -1,5 +1,7 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
import ch.jalu.datasourcecolumns.data.DataSourceValues; import ch.jalu.datasourcecolumns.data.DataSourceValues;
import ch.jalu.datasourcecolumns.predicate.AlwaysTruePredicate; import ch.jalu.datasourcecolumns.predicate.AlwaysTruePredicate;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -408,54 +410,28 @@ public class SQLite implements DataSource {
@Override @Override
public boolean hasSession(String user) { public boolean hasSession(String user) {
String sql = "SELECT " + col.HAS_SESSION + " FROM " + tableName + " WHERE LOWER(" + col.NAME + ")=?;"; try {
try (PreparedStatement pst = con.prepareStatement(sql)) { DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.HAS_SESSION);
pst.setString(1, user.toLowerCase()); return result.rowExists() && Integer.valueOf(1).equals(result.getValue());
try (ResultSet rs = pst.executeQuery()) { } catch (SQLException e) {
if (rs.next()) { logSqlException(e);
return rs.getInt(col.HAS_SESSION) == 1; return false;
}
}
} catch (SQLException ex) {
logSqlException(ex);
} }
return false;
} }
@Override @Override
public void grantSession(String user) { public void grantSession(String user) {
String sql = "UPDATE " + tableName + " SET " + col.HAS_SESSION + "=? WHERE LOWER(" + col.NAME + ")=?;"; columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 1);
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 1);
pst.setString(2, user.toLowerCase());
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
public void revokeSession(String user) { public void revokeSession(String user) {
String sql = "UPDATE " + tableName + " SET " + col.HAS_SESSION + "=? WHERE LOWER(" + col.NAME + ")=?;"; columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 0);
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 0);
pst.setString(2, user.toLowerCase());
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
public void purgeLogged() { public void purgeLogged() {
String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.IS_LOGGED + "=?;"; columnsHandler.update(eq(AuthMeColumns.IS_LOGGED, 1), AuthMeColumns.IS_LOGGED, 0);
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, 0);
pst.setInt(2, 1);
pst.executeUpdate();
} catch (SQLException ex) {
logSqlException(ex);
}
} }
@Override @Override
@ -469,19 +445,13 @@ public class SQLite implements DataSource {
} }
@Override @Override
public DataSourceResult<String> getEmail(String user) { public DataSourceValue<String> getEmail(String user) {
String sql = "SELECT " + col.EMAIL + " FROM " + tableName + " WHERE " + col.NAME + "=?;"; try {
try (PreparedStatement pst = con.prepareStatement(sql)) { return columnsHandler.retrieve(user, AuthMeColumns.EMAIL);
pst.setString(1, user); } catch (SQLException e) {
try (ResultSet rs = pst.executeQuery()) { logSqlException(e);
if (rs.next()) { return DataSourceValueImpl.unknownRow();
return DataSourceResult.of(rs.getString(1));
}
}
} catch (SQLException ex) {
logSqlException(ex);
} }
return DataSourceResult.unknownPlayer();
} }
@Override @Override

View File

@ -1,13 +1,8 @@
package fr.xephi.authme.datasource.columnshandler; package fr.xephi.authme.datasource.columnshandler;
import ch.jalu.configme.properties.Property;
import ch.jalu.datasourcecolumns.ColumnType;
import ch.jalu.datasourcecolumns.DependentColumn;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.DatabaseSettings;
import java.util.function.Function;
import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.ColumnOptions.DEFAULT_FOR_NULL; import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.ColumnOptions.DEFAULT_FOR_NULL;
import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.ColumnOptions.OPTIONAL; import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.ColumnOptions.OPTIONAL;
import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.createDouble; import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.createDouble;
@ -17,104 +12,71 @@ import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.cre
import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.createString; import static fr.xephi.authme.datasource.columnshandler.AuthMeColumnsFactory.createString;
/** /**
* Column definitions for the AuthMe table. * Contains column definitions for the AuthMe table.
*
* @param <T> the column type
* @see PlayerAuth
*/ */
public final class AuthMeColumns<T> implements DependentColumn<T, ColumnContext, PlayerAuth> { public final class AuthMeColumns {
public static final AuthMeColumns<String> NAME = createString( public static final PlayerAuthColumn<String> NAME = createString(
DatabaseSettings.MYSQL_COL_NAME, PlayerAuth::getNickname); DatabaseSettings.MYSQL_COL_NAME, PlayerAuth::getNickname);
public static final AuthMeColumns<String> NICK_NAME = createString( public static final PlayerAuthColumn<String> NICK_NAME = createString(
DatabaseSettings.MYSQL_COL_REALNAME, PlayerAuth::getRealName); DatabaseSettings.MYSQL_COL_REALNAME, PlayerAuth::getRealName);
public static final AuthMeColumns<String> PASSWORD = createString( public static final PlayerAuthColumn<String> PASSWORD = createString(
DatabaseSettings.MYSQL_COL_PASSWORD, auth -> auth.getPassword().getHash()); DatabaseSettings.MYSQL_COL_PASSWORD, auth -> auth.getPassword().getHash());
public static final AuthMeColumns<String> SALT = createString( public static final PlayerAuthColumn<String> SALT = createString(
DatabaseSettings.MYSQL_COL_SALT, auth -> auth.getPassword().getSalt(), OPTIONAL); DatabaseSettings.MYSQL_COL_SALT, auth -> auth.getPassword().getSalt(), OPTIONAL);
public static final AuthMeColumns<String> EMAIL = createString( public static final PlayerAuthColumn<String> EMAIL = createString(
DatabaseSettings.MYSQL_COL_EMAIL, PlayerAuth::getEmail, DEFAULT_FOR_NULL); DatabaseSettings.MYSQL_COL_EMAIL, PlayerAuth::getEmail, DEFAULT_FOR_NULL);
public static final AuthMeColumns<String> LAST_IP = createString( public static final PlayerAuthColumn<String> LAST_IP = createString(
DatabaseSettings.MYSQL_COL_LAST_IP, PlayerAuth::getLastIp); DatabaseSettings.MYSQL_COL_LAST_IP, PlayerAuth::getLastIp);
public static final AuthMeColumns<Integer> GROUP_ID = createInteger( public static final PlayerAuthColumn<Integer> GROUP_ID = createInteger(
DatabaseSettings.MYSQL_COL_GROUP, PlayerAuth::getGroupId, OPTIONAL); DatabaseSettings.MYSQL_COL_GROUP, PlayerAuth::getGroupId, OPTIONAL);
public static final AuthMeColumns<Long> LAST_LOGIN = createLong( public static final PlayerAuthColumn<Long> LAST_LOGIN = createLong(
DatabaseSettings.MYSQL_COL_LASTLOGIN, PlayerAuth::getLastLogin); DatabaseSettings.MYSQL_COL_LASTLOGIN, PlayerAuth::getLastLogin);
public static final AuthMeColumns<String> REGISTRATION_IP = createString( public static final PlayerAuthColumn<String> REGISTRATION_IP = createString(
DatabaseSettings.MYSQL_COL_REGISTER_IP, PlayerAuth::getRegistrationIp); DatabaseSettings.MYSQL_COL_REGISTER_IP, PlayerAuth::getRegistrationIp);
public static final AuthMeColumns<Long> REGISTRATION_DATE = createLong( public static final PlayerAuthColumn<Long> REGISTRATION_DATE = createLong(
DatabaseSettings.MYSQL_COL_REGISTER_DATE, PlayerAuth::getRegistrationDate); DatabaseSettings.MYSQL_COL_REGISTER_DATE, PlayerAuth::getRegistrationDate);
public static final AuthMeColumns<Double> LOCATION_X = createDouble( // --------
// Location columns
// --------
public static final PlayerAuthColumn<Double> LOCATION_X = createDouble(
DatabaseSettings.MYSQL_COL_LASTLOC_X, PlayerAuth::getQuitLocX); DatabaseSettings.MYSQL_COL_LASTLOC_X, PlayerAuth::getQuitLocX);
public static final AuthMeColumns<Double> LOCATION_Y = createDouble( public static final PlayerAuthColumn<Double> LOCATION_Y = createDouble(
DatabaseSettings.MYSQL_COL_LASTLOC_Y, PlayerAuth::getQuitLocY); DatabaseSettings.MYSQL_COL_LASTLOC_Y, PlayerAuth::getQuitLocY);
public static final AuthMeColumns<Double> LOCATION_Z = createDouble( public static final PlayerAuthColumn<Double> LOCATION_Z = createDouble(
DatabaseSettings.MYSQL_COL_LASTLOC_Z, PlayerAuth::getQuitLocZ); DatabaseSettings.MYSQL_COL_LASTLOC_Z, PlayerAuth::getQuitLocZ);
public static final AuthMeColumns<String> LOCATION_WORLD = createString( public static final PlayerAuthColumn<String> LOCATION_WORLD = createString(
DatabaseSettings.MYSQL_COL_LASTLOC_WORLD, PlayerAuth::getWorld); DatabaseSettings.MYSQL_COL_LASTLOC_WORLD, PlayerAuth::getWorld);
public static final AuthMeColumns<Float> LOCATION_YAW = createFloat( public static final PlayerAuthColumn<Float> LOCATION_YAW = createFloat(
DatabaseSettings.MYSQL_COL_LASTLOC_YAW, PlayerAuth::getYaw); DatabaseSettings.MYSQL_COL_LASTLOC_YAW, PlayerAuth::getYaw);
public static final AuthMeColumns<Float> LOCATION_PITCH = createFloat( public static final PlayerAuthColumn<Float> LOCATION_PITCH = createFloat(
DatabaseSettings.MYSQL_COL_LASTLOC_PITCH, PlayerAuth::getPitch); DatabaseSettings.MYSQL_COL_LASTLOC_PITCH, PlayerAuth::getPitch);
// --------
// Columns not on PlayerAuth
// --------
public static final DataSourceColumn<Integer> IS_LOGGED = createInteger(
DatabaseSettings.MYSQL_COL_ISLOGGED);
private final ColumnType<T> columnType; public static final DataSourceColumn<Integer> HAS_SESSION = createInteger(
private final Property<String> nameProperty; DatabaseSettings.MYSQL_COL_HASSESSION);
private final Function<PlayerAuth, T> playerAuthGetter;
private final boolean isOptional;
private final boolean useDefaultForNull;
AuthMeColumns(ColumnType<T> type, Property<String> nameProperty, Function<PlayerAuth, T> playerAuthGetter,
boolean isOptional, boolean useDefaultForNull) {
this.columnType = type;
this.nameProperty = nameProperty;
this.playerAuthGetter = playerAuthGetter;
this.isOptional = isOptional;
this.useDefaultForNull = useDefaultForNull;
}
public Property<String> getNameProperty() { private AuthMeColumns() {
return nameProperty;
}
@Override
public T getValueFromDependent(PlayerAuth playerAuth) {
return playerAuthGetter.apply(playerAuth);
}
@Override
public String resolveName(ColumnContext columnContext) {
return columnContext.getName(this);
}
@Override
public ColumnType<T> getType() {
return columnType;
}
@Override
public boolean isColumnUsed(ColumnContext columnContext) {
return !isOptional || !resolveName(columnContext).isEmpty();
}
@Override
public boolean useDefaultForNullValue(ColumnContext columnContext) {
return useDefaultForNull && columnContext.hasDefaultSupport();
} }
} }

View File

@ -8,46 +8,53 @@ import fr.xephi.authme.data.auth.PlayerAuth;
import java.util.function.Function; import java.util.function.Function;
/** /**
* Util class for initializing {@link AuthMeColumns} constants. * Util class for initializing {@link DataSourceColumn} objects.
*/ */
final class AuthMeColumnsFactory { final class AuthMeColumnsFactory {
private AuthMeColumnsFactory() { private AuthMeColumnsFactory() {
} }
static AuthMeColumns<Integer> createInteger(Property<String> nameProperty, static DataSourceColumn<Integer> createInteger(Property<String> nameProperty,
Function<PlayerAuth, Integer> playerAuthGetter, ColumnOptions... options) {
ColumnOptions... options) { return new DataSourceColumn<>(StandardTypes.INTEGER, nameProperty,
isOptional(options), hasDefaultForNull(options));
}
static PlayerAuthColumn<Integer> createInteger(Property<String> nameProperty,
Function<PlayerAuth, Integer> playerAuthGetter,
ColumnOptions... options) {
return createInternal(StandardTypes.INTEGER, nameProperty, playerAuthGetter, options); return createInternal(StandardTypes.INTEGER, nameProperty, playerAuthGetter, options);
} }
static AuthMeColumns<Long> createLong(Property<String> nameProperty, static PlayerAuthColumn<Long> createLong(Property<String> nameProperty,
Function<PlayerAuth, Long> playerAuthGetter, Function<PlayerAuth, Long> playerAuthGetter,
ColumnOptions... options) { ColumnOptions... options) {
return createInternal(StandardTypes.LONG, nameProperty, playerAuthGetter, options); return createInternal(StandardTypes.LONG, nameProperty, playerAuthGetter, options);
} }
static AuthMeColumns<String> createString(Property<String> nameProperty, static PlayerAuthColumn<String> createString(Property<String> nameProperty,
Function<PlayerAuth, String> playerAuthGetter, Function<PlayerAuth, String> playerAuthGetter,
ColumnOptions... options) { ColumnOptions... options) {
return createInternal(StandardTypes.STRING, nameProperty, playerAuthGetter, options); return createInternal(StandardTypes.STRING, nameProperty, playerAuthGetter, options);
} }
static AuthMeColumns<Double> createDouble(Property<String> nameProperty, static PlayerAuthColumn<Double> createDouble(Property<String> nameProperty,
Function<PlayerAuth, Double> playerAuthGetter, Function<PlayerAuth, Double> playerAuthGetter,
ColumnOptions... options) { ColumnOptions... options) {
return createInternal(StandardTypes.DOUBLE, nameProperty, playerAuthGetter, options); return createInternal(StandardTypes.DOUBLE, nameProperty, playerAuthGetter, options);
} }
static AuthMeColumns<Float> createFloat(Property<String> nameProperty, static PlayerAuthColumn<Float> createFloat(Property<String> nameProperty,
Function<PlayerAuth, Float> playerAuthGetter, Function<PlayerAuth, Float> playerAuthGetter,
ColumnOptions... options) { ColumnOptions... options) {
return createInternal(StandardTypes.FLOAT, nameProperty, playerAuthGetter, options); return createInternal(StandardTypes.FLOAT, nameProperty, playerAuthGetter, options);
} }
private static <T> AuthMeColumns<T> createInternal(ColumnType<T> type, Property<String> nameProperty, private static <T> PlayerAuthColumn<T> createInternal(ColumnType<T> type, Property<String> nameProperty,
Function<PlayerAuth, T> authGetter, ColumnOptions... options) { Function<PlayerAuth, T> authGetter,
return new AuthMeColumns<>(type, nameProperty, authGetter, isOptional(options), hasDefaultForNull(options)); ColumnOptions... options) {
return new PlayerAuthColumn<>(type, nameProperty, isOptional(options), hasDefaultForNull(options), authGetter);
} }
private static boolean isOptional(ColumnOptions[] options) { private static boolean isOptional(ColumnOptions[] options) {

View File

@ -75,7 +75,7 @@ public final class AuthMeColumnsHandler {
* @param <T> the column type * @param <T> the column type
* @return true upon success, false otherwise * @return true upon success, false otherwise
*/ */
public <T> boolean update(String name, AuthMeColumns<T> column, T value) { public <T> boolean update(String name, DataSourceColumn<T> column, T value) {
try { try {
return internalHandler.update(name, column, value); return internalHandler.update(name, column, value);
} catch (SQLException e) { } catch (SQLException e) {
@ -91,7 +91,7 @@ public final class AuthMeColumnsHandler {
* @param columns the columns to update in the row * @param columns the columns to update in the row
* @return true upon success, false otherwise * @return true upon success, false otherwise
*/ */
public boolean update(PlayerAuth auth, AuthMeColumns<?>... columns) { public boolean update(PlayerAuth auth, PlayerAuthColumn<?>... columns) {
try { try {
return internalHandler.update(auth.getNickname(), auth, columns); return internalHandler.update(auth.getNickname(), auth, columns);
} catch (SQLException e) { } catch (SQLException e) {
@ -116,6 +116,24 @@ public final class AuthMeColumnsHandler {
} }
} }
/**
* Sets the given value to the provided column for all rows which match the predicate.
*
* @param predicate the predicate to filter rows by
* @param column the column to modify on the matched rows
* @param value the new value to set
* @param <T> the column type
* @return number of modified rows
*/
public <T> int update(Predicate<ColumnContext> predicate, DataSourceColumn<T> column, T value) {
try {
return internalHandler.update(predicate, column, value);
} catch (SQLException e) {
logSqlException(e);
return 0;
}
}
/** /**
* Retrieves the given column from a given row. * Retrieves the given column from a given row.
* *
@ -124,7 +142,7 @@ public final class AuthMeColumnsHandler {
* @param <T> the column type * @param <T> the column type
* @return the result of the lookup * @return the result of the lookup
*/ */
public <T> DataSourceValue<T> retrieve(String name, AuthMeColumns<T> column) throws SQLException { public <T> DataSourceValue<T> retrieve(String name, DataSourceColumn<T> column) throws SQLException {
return internalHandler.retrieve(name.toLowerCase(), column); return internalHandler.retrieve(name.toLowerCase(), column);
} }
@ -135,7 +153,7 @@ public final class AuthMeColumnsHandler {
* @param columns the columns to retrieve * @param columns the columns to retrieve
* @return map-like object with the requested values * @return map-like object with the requested values
*/ */
public DataSourceValues retrieve(String name, AuthMeColumns<?>... columns) throws SQLException { public DataSourceValues retrieve(String name, DataSourceColumn<?>... columns) throws SQLException {
return internalHandler.retrieve(name.toLowerCase(), columns); return internalHandler.retrieve(name.toLowerCase(), columns);
} }
@ -147,7 +165,7 @@ public final class AuthMeColumnsHandler {
* @param <T> the column's value type * @param <T> the column's value type
* @return the values of the matching rows * @return the values of the matching rows
*/ */
public <T> List<T> retrieve(Predicate<ColumnContext> predicate, AuthMeColumns<T> column) throws SQLException { public <T> List<T> retrieve(Predicate<ColumnContext> predicate, DataSourceColumn<T> column) throws SQLException {
return internalHandler.retrieve(predicate, column); return internalHandler.retrieve(predicate, column);
} }
@ -158,7 +176,7 @@ public final class AuthMeColumnsHandler {
* @param columns the columns to insert * @param columns the columns to insert
* @return true upon success, false otherwise * @return true upon success, false otherwise
*/ */
public boolean insert(PlayerAuth auth, AuthMeColumns<?>... columns) { public boolean insert(PlayerAuth auth, PlayerAuthColumn<?>... columns) {
try { try {
return internalHandler.insert(auth, columns); return internalHandler.insert(auth, columns);
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -11,7 +11,7 @@ import java.util.Map;
public class ColumnContext { public class ColumnContext {
private final Settings settings; private final Settings settings;
private final Map<AuthMeColumns<?>, String> columnNames = new HashMap<>(); private final Map<DataSourceColumn<?>, String> columnNames = new HashMap<>();
private final boolean hasDefaultSupport; private final boolean hasDefaultSupport;
/** /**
@ -25,7 +25,7 @@ public class ColumnContext {
this.hasDefaultSupport = hasDefaultSupport; this.hasDefaultSupport = hasDefaultSupport;
} }
public String getName(AuthMeColumns<?> column) { public String getName(DataSourceColumn<?> column) {
return columnNames.computeIfAbsent(column, k -> settings.getProperty(k.getNameProperty())); return columnNames.computeIfAbsent(column, k -> settings.getProperty(k.getNameProperty()));
} }

View File

@ -0,0 +1,57 @@
package fr.xephi.authme.datasource.columnshandler;
import ch.jalu.configme.properties.Property;
import ch.jalu.datasourcecolumns.Column;
import ch.jalu.datasourcecolumns.ColumnType;
/**
* Basic {@link Column} implementation for AuthMe.
*
* @param <T> column type
*/
public class DataSourceColumn<T> implements Column<T, ColumnContext> {
private final ColumnType<T> columnType;
private final Property<String> nameProperty;
private final boolean isOptional;
private final boolean useDefaultForNull;
/**
* Constructor.
*
* @param type type of the column
* @param nameProperty property defining the column name
* @param isOptional whether or not the column can be skipped (if name is configured to empty string)
* @param useDefaultForNull whether SQL DEFAULT should be used for null values (if supported by the database)
*/
DataSourceColumn(ColumnType<T> type, Property<String> nameProperty, boolean isOptional, boolean useDefaultForNull) {
this.columnType = type;
this.nameProperty = nameProperty;
this.isOptional = isOptional;
this.useDefaultForNull = useDefaultForNull;
}
public Property<String> getNameProperty() {
return nameProperty;
}
@Override
public String resolveName(ColumnContext columnContext) {
return columnContext.getName(this);
}
@Override
public ColumnType<T> getType() {
return columnType;
}
@Override
public boolean isColumnUsed(ColumnContext columnContext) {
return !isOptional || !resolveName(columnContext).isEmpty();
}
@Override
public boolean useDefaultForNullValue(ColumnContext columnContext) {
return useDefaultForNull && columnContext.hasDefaultSupport();
}
}

View File

@ -0,0 +1,32 @@
package fr.xephi.authme.datasource.columnshandler;
import ch.jalu.configme.properties.Property;
import ch.jalu.datasourcecolumns.ColumnType;
import ch.jalu.datasourcecolumns.DependentColumn;
import fr.xephi.authme.data.auth.PlayerAuth;
import java.util.function.Function;
/**
* Implementation for columns which can also be retrieved from a {@link PlayerAuth} object.
*
* @param <T> column type
*/
public class PlayerAuthColumn<T> extends DataSourceColumn<T> implements DependentColumn<T, ColumnContext, PlayerAuth> {
private final Function<PlayerAuth, T> playerAuthGetter;
/*
* Constructor. See parent class for details.
*/
PlayerAuthColumn(ColumnType<T> type, Property<String> nameProperty, boolean isOptional, boolean useDefaultForNull,
Function<PlayerAuth, T> playerAuthGetter) {
super(type, nameProperty, isOptional, useDefaultForNull);
this.playerAuthGetter = playerAuthGetter;
}
@Override
public T getValueFromDependent(PlayerAuth auth) {
return playerAuthGetter.apply(auth);
}
}

View File

@ -6,7 +6,8 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import fr.xephi.authme.data.captcha.CaptchaCodeStorage; import fr.xephi.authme.data.captcha.CaptchaCodeStorage;
import fr.xephi.authme.datasource.Columns; import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.datasource.columnshandler.AuthMeColumns; import fr.xephi.authme.datasource.columnshandler.DataSourceColumn;
import fr.xephi.authme.datasource.columnshandler.PlayerAuthColumn;
import fr.xephi.authme.datasource.mysqlextensions.MySqlExtension; import fr.xephi.authme.datasource.mysqlextensions.MySqlExtension;
import fr.xephi.authme.initialization.HasCleanup; import fr.xephi.authme.initialization.HasCleanup;
import fr.xephi.authme.process.register.executors.RegistrationMethod; import fr.xephi.authme.process.register.executors.RegistrationMethod;
@ -53,7 +54,7 @@ public class ClassesConsistencyTest {
int.class, long.class, float.class, String.class, File.class, Enum.class, collectionsUnmodifiableList(), int.class, long.class, float.class, String.class, File.class, Enum.class, collectionsUnmodifiableList(),
Charset.class, Charset.class,
/* AuthMe */ /* AuthMe */
Property.class, RegistrationMethod.class, AuthMeColumns.class, Property.class, RegistrationMethod.class, DataSourceColumn.class, PlayerAuthColumn.class,
/* Guava */ /* Guava */
ImmutableMap.class, ImmutableList.class); ImmutableMap.class, ImmutableList.class);

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSourceResult;
import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.CommonService;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -38,7 +38,7 @@ public class GetEmailCommandTest {
public void shouldReportUnknownUser() { public void shouldReportUnknownUser() {
// given // given
String user = "myTestUser"; String user = "myTestUser";
given(dataSource.getEmail(user)).willReturn(DataSourceResult.unknownPlayer()); given(dataSource.getEmail(user)).willReturn(DataSourceValueImpl.unknownRow());
CommandSender sender = mock(CommandSender.class); CommandSender sender = mock(CommandSender.class);
// when // when
@ -53,7 +53,7 @@ public class GetEmailCommandTest {
// given // given
String user = "userToView"; String user = "userToView";
String email = "user.email@example.org"; String email = "user.email@example.org";
given(dataSource.getEmail(user)).willReturn(DataSourceResult.of(email)); given(dataSource.getEmail(user)).willReturn(DataSourceValueImpl.of(email));
CommandSender sender = mock(CommandSender.class); CommandSender sender = mock(CommandSender.class);
// when // when

View File

@ -1,12 +1,12 @@
package fr.xephi.authme.command.executable.email; package fr.xephi.authme.command.executable.email;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
import ch.jalu.injector.testing.BeforeInjecting; import ch.jalu.injector.testing.BeforeInjecting;
import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.DelayedInjectionRunner;
import ch.jalu.injector.testing.InjectDelayed; import ch.jalu.injector.testing.InjectDelayed;
import fr.xephi.authme.TestHelper; import fr.xephi.authme.TestHelper;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSourceResult;
import fr.xephi.authme.mail.EmailService; import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
@ -118,7 +118,7 @@ public class RecoverEmailCommandTest {
given(sender.getName()).willReturn(name); given(sender.getName()).willReturn(name);
given(emailService.hasAllInformation()).willReturn(true); given(emailService.hasAllInformation()).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false); given(playerCache.isAuthenticated(name)).willReturn(false);
given(dataSource.getEmail(name)).willReturn(DataSourceResult.unknownPlayer()); given(dataSource.getEmail(name)).willReturn(DataSourceValueImpl.unknownRow());
// when // when
command.executeCommand(sender, Collections.singletonList("someone@example.com")); command.executeCommand(sender, Collections.singletonList("someone@example.com"));
@ -138,7 +138,7 @@ public class RecoverEmailCommandTest {
given(sender.getName()).willReturn(name); given(sender.getName()).willReturn(name);
given(emailService.hasAllInformation()).willReturn(true); given(emailService.hasAllInformation()).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false); given(playerCache.isAuthenticated(name)).willReturn(false);
given(dataSource.getEmail(name)).willReturn(DataSourceResult.of(DEFAULT_EMAIL)); given(dataSource.getEmail(name)).willReturn(DataSourceValueImpl.of(DEFAULT_EMAIL));
// when // when
command.executeCommand(sender, Collections.singletonList(DEFAULT_EMAIL)); command.executeCommand(sender, Collections.singletonList(DEFAULT_EMAIL));
@ -158,7 +158,7 @@ public class RecoverEmailCommandTest {
given(sender.getName()).willReturn(name); given(sender.getName()).willReturn(name);
given(emailService.hasAllInformation()).willReturn(true); given(emailService.hasAllInformation()).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false); given(playerCache.isAuthenticated(name)).willReturn(false);
given(dataSource.getEmail(name)).willReturn(DataSourceResult.of("raptor@example.org")); given(dataSource.getEmail(name)).willReturn(DataSourceValueImpl.of("raptor@example.org"));
// when // when
command.executeCommand(sender, Collections.singletonList("wrong-email@example.com")); command.executeCommand(sender, Collections.singletonList("wrong-email@example.com"));
@ -180,7 +180,7 @@ public class RecoverEmailCommandTest {
given(emailService.sendRecoveryCode(anyString(), anyString(), anyString())).willReturn(true); given(emailService.sendRecoveryCode(anyString(), anyString(), anyString())).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false); given(playerCache.isAuthenticated(name)).willReturn(false);
String email = "v@example.com"; String email = "v@example.com";
given(dataSource.getEmail(name)).willReturn(DataSourceResult.of(email)); given(dataSource.getEmail(name)).willReturn(DataSourceValueImpl.of(email));
String code = "a94f37"; String code = "a94f37";
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true); given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeService.generateCode(name)).willReturn(code); given(recoveryCodeService.generateCode(name)).willReturn(code);
@ -205,7 +205,7 @@ public class RecoverEmailCommandTest {
given(emailService.sendPasswordMail(anyString(), anyString(), anyString())).willReturn(true); given(emailService.sendPasswordMail(anyString(), anyString(), anyString())).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false); given(playerCache.isAuthenticated(name)).willReturn(false);
String email = "vulture@example.com"; String email = "vulture@example.com";
given(dataSource.getEmail(name)).willReturn(DataSourceResult.of(email)); given(dataSource.getEmail(name)).willReturn(DataSourceValueImpl.of(email));
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false); given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false);
setBukkitServiceToRunTaskAsynchronously(bukkitService); setBukkitServiceToRunTaskAsynchronously(bukkitService);

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.data; package fr.xephi.authme.data;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSourceResult;
import fr.xephi.authme.mail.EmailService; import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.permission.PlayerPermission;
@ -51,7 +51,7 @@ public class VerificationCodeManagerTest {
// given // given
String name1 = "ILoveTests"; String name1 = "ILoveTests";
Player player1 = mockPlayerWithName(name1); Player player1 = mockPlayerWithName(name1);
given(dataSource.getEmail(name1)).willReturn(DataSourceResult.of("ilovetests@test.com")); given(dataSource.getEmail(name1)).willReturn(DataSourceValueImpl.of("ilovetests@test.com"));
given(permissionsManager.hasPermission(player1, PlayerPermission.VERIFICATION_CODE)).willReturn(true); given(permissionsManager.hasPermission(player1, PlayerPermission.VERIFICATION_CODE)).willReturn(true);
String name2 = "StillLovingTests"; String name2 = "StillLovingTests";
Player player2 = mockPlayerWithName(name2); Player player2 = mockPlayerWithName(name2);
@ -106,7 +106,7 @@ public class VerificationCodeManagerTest {
// given // given
String player = "ILoveTests"; String player = "ILoveTests";
String email = "ilovetests@test.com"; String email = "ilovetests@test.com";
given(dataSource.getEmail(player)).willReturn(DataSourceResult.of(email)); given(dataSource.getEmail(player)).willReturn(DataSourceValueImpl.of(email));
VerificationCodeManager codeManager1 = createCodeManager(); VerificationCodeManager codeManager1 = createCodeManager();
VerificationCodeManager codeManager2 = createCodeManager(); VerificationCodeManager codeManager2 = createCodeManager();
codeManager2.codeExistOrGenerateNew(player); codeManager2.codeExistOrGenerateNew(player);
@ -125,7 +125,7 @@ public class VerificationCodeManagerTest {
// given // given
String player = "ILoveTests"; String player = "ILoveTests";
String email = "ilovetests@test.com"; String email = "ilovetests@test.com";
given(dataSource.getEmail(player)).willReturn(DataSourceResult.of(email)); given(dataSource.getEmail(player)).willReturn(DataSourceValueImpl.of(email));
VerificationCodeManager codeManager1 = createCodeManager(); VerificationCodeManager codeManager1 = createCodeManager();
VerificationCodeManager codeManager2 = createCodeManager(); VerificationCodeManager codeManager2 = createCodeManager();
codeManager2.codeExistOrGenerateNew(player); codeManager2.codeExistOrGenerateNew(player);
@ -145,7 +145,7 @@ public class VerificationCodeManagerTest {
String player = "ILoveTests"; String player = "ILoveTests";
String code = "193458"; String code = "193458";
String email = "ilovetests@test.com"; String email = "ilovetests@test.com";
given(dataSource.getEmail(player)).willReturn(DataSourceResult.of(email)); given(dataSource.getEmail(player)).willReturn(DataSourceValueImpl.of(email));
VerificationCodeManager codeManager1 = createCodeManager(); VerificationCodeManager codeManager1 = createCodeManager();
VerificationCodeManager codeManager2 = createCodeManager(); VerificationCodeManager codeManager2 = createCodeManager();
codeManager1.codeExistOrGenerateNew(player); codeManager1.codeExistOrGenerateNew(player);

View File

@ -1,5 +1,7 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import ch.jalu.datasourcecolumns.data.DataSourceValue;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
@ -420,12 +422,12 @@ public abstract class AbstractDataSourceIntegrationTest {
DataSource dataSource = getDataSource(); DataSource dataSource = getDataSource();
// when // when
DataSourceResult<String> email1 = dataSource.getEmail(user1); DataSourceValue<String> email1 = dataSource.getEmail(user1);
DataSourceResult<String> email2 = dataSource.getEmail(user2); DataSourceValue<String> email2 = dataSource.getEmail(user2);
// then // then
assertThat(email1.getValue(), equalTo("user@example.org")); assertThat(email1.getValue(), equalTo("user@example.org"));
assertThat(email2, is(DataSourceResult.unknownPlayer())); assertThat(email2, is(DataSourceValueImpl.unknownRow()));
} }
@Test @Test