mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-28 21:25:44 +01:00
Cleanup
This commit is contained in:
parent
3a00e290bb
commit
c95443fda7
@ -31,6 +31,7 @@ import fr.xephi.authme.settings.SettingsWarner;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.CleanupTask;
|
||||
import fr.xephi.authme.task.purge.PurgeService;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.util.ExceptionUtils;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
@ -172,7 +173,9 @@ public class AuthMe extends JavaPlugin {
|
||||
// Successful message
|
||||
logger.info("AuthMe " + getPluginVersion() + " build n." + getPluginBuildNumber() + " successfully enabled!");
|
||||
// Start catching wrong sync/async calls
|
||||
ThreadSafety.setEnabled(true);
|
||||
if(System.getProperty("authme.disableThreadSafetyChecks") == null) {
|
||||
BukkitThreadSafety.setEnabled(true);
|
||||
}
|
||||
|
||||
// Purge on start if enabled
|
||||
PurgeService purgeService = injector.getSingleton(PurgeService.class);
|
||||
|
@ -6,6 +6,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface MightBeAsync {
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ShouldBeAsync {
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.converter.Converter;
|
||||
import fr.xephi.authme.datasource.converter.AbstractConverter;
|
||||
import fr.xephi.authme.datasource.converter.CrazyLoginConverter;
|
||||
import fr.xephi.authme.datasource.converter.LoginSecurityConverter;
|
||||
import fr.xephi.authme.datasource.converter.MySqlToSqlite;
|
||||
@ -30,7 +30,7 @@ import java.util.Map;
|
||||
public class ConverterCommand implements ExecutableCommand {
|
||||
|
||||
@VisibleForTesting
|
||||
static final Map<String, Class<? extends Converter>> CONVERTERS = getConverters();
|
||||
static final Map<String, Class<? extends AbstractConverter>> CONVERTERS = getConverters();
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(ConverterCommand.class);
|
||||
|
||||
@ -41,18 +41,18 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private Factory<Converter> converterFactory;
|
||||
private Factory<AbstractConverter> converterFactory;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
Class<? extends Converter> converterClass = getConverterClassFromArgs(arguments);
|
||||
Class<? extends AbstractConverter> converterClass = getConverterClassFromArgs(arguments);
|
||||
if (converterClass == null) {
|
||||
sender.sendMessage("Converters: " + String.join(", ", CONVERTERS.keySet()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the proper converter instance
|
||||
final Converter converter = converterFactory.newInstance(converterClass);
|
||||
final AbstractConverter converter = converterFactory.newInstance(converterClass);
|
||||
|
||||
// Run the convert job
|
||||
bukkitService.runTaskAsynchronously(() -> {
|
||||
@ -68,7 +68,7 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
sender.sendMessage("[AuthMe] Successfully started " + arguments.get(0));
|
||||
}
|
||||
|
||||
private static Class<? extends Converter> getConverterClassFromArgs(List<String> arguments) {
|
||||
private static Class<? extends AbstractConverter> getConverterClassFromArgs(List<String> arguments) {
|
||||
return arguments.isEmpty()
|
||||
? null
|
||||
: CONVERTERS.get(arguments.get(0).toLowerCase());
|
||||
@ -79,8 +79,8 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
*
|
||||
* @return map with all available converters
|
||||
*/
|
||||
private static Map<String, Class<? extends Converter>> getConverters() {
|
||||
return ImmutableSortedMap.<String, Class<? extends Converter>>naturalOrder()
|
||||
private static Map<String, Class<? extends AbstractConverter>> getConverters() {
|
||||
return ImmutableSortedMap.<String, Class<? extends AbstractConverter>>naturalOrder()
|
||||
.put("xauth", XAuthConverter.class)
|
||||
.put("crazylogin", CrazyLoginConverter.class)
|
||||
.put("rakamak", RakamakConverter.class)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.annotation.MightBeAsync;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
@ -4,7 +4,7 @@ import ch.jalu.datasourcecolumns.data.DataSourceValue;
|
||||
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
|
||||
import ch.jalu.datasourcecolumns.data.DataSourceValues;
|
||||
import ch.jalu.datasourcecolumns.predicate.AlwaysTruePredicate;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.columnshandler.AuthMeColumns;
|
||||
@ -31,7 +31,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean isAuthAvailable(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
try {
|
||||
return columnsHandler.retrieve(user, AuthMeColumns.NAME).rowExists();
|
||||
} catch (SQLException e) {
|
||||
@ -43,7 +43,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public HashedPassword getPassword(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
try {
|
||||
DataSourceValues values = columnsHandler.retrieve(user, AuthMeColumns.PASSWORD, AuthMeColumns.SALT);
|
||||
if (values.rowExists()) {
|
||||
@ -58,7 +58,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean saveAuth(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.insert(auth,
|
||||
AuthMeColumns.NAME, AuthMeColumns.NICK_NAME, AuthMeColumns.PASSWORD, AuthMeColumns.SALT,
|
||||
AuthMeColumns.EMAIL, AuthMeColumns.REGISTRATION_DATE, AuthMeColumns.REGISTRATION_IP,
|
||||
@ -68,7 +68,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean hasSession(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
try {
|
||||
DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.HAS_SESSION);
|
||||
return result.rowExists() && Integer.valueOf(1).equals(result.getValue());
|
||||
@ -81,21 +81,21 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.update(auth, AuthMeColumns.LAST_IP, AuthMeColumns.LAST_LOGIN, AuthMeColumns.NICK_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updatePassword(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return updatePassword(auth.getNickname(), auth.getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updatePassword(String user, HashedPassword password) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.update(user,
|
||||
with(AuthMeColumns.PASSWORD, password.getHash())
|
||||
.and(AuthMeColumns.SALT, password.getSalt()).build());
|
||||
@ -104,7 +104,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.update(auth,
|
||||
AuthMeColumns.LOCATION_X, AuthMeColumns.LOCATION_Y, AuthMeColumns.LOCATION_Z,
|
||||
AuthMeColumns.LOCATION_WORLD, AuthMeColumns.LOCATION_YAW, AuthMeColumns.LOCATION_PITCH);
|
||||
@ -113,7 +113,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public List<String> getAllAuthsByIp(String ip) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
try {
|
||||
return columnsHandler.retrieve(eq(AuthMeColumns.LAST_IP, ip), AuthMeColumns.NAME);
|
||||
} catch (SQLException e) {
|
||||
@ -125,21 +125,21 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public int countAuthsByEmail(String email) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.count(eqIgnoreCase(AuthMeColumns.EMAIL, email));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateEmail(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.update(auth, AuthMeColumns.EMAIL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean isLogged(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
try {
|
||||
DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.IS_LOGGED);
|
||||
return result.rowExists() && Integer.valueOf(1).equals(result.getValue());
|
||||
@ -152,56 +152,56 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void setLogged(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void setUnlogged(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void grantSession(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void revokeSession(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void purgeLogged() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
columnsHandler.update(eq(AuthMeColumns.IS_LOGGED, 1), AuthMeColumns.IS_LOGGED, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public int getAccountsRegistered() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.count(new AlwaysTruePredicate<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateRealName(String user, String realName) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return columnsHandler.update(user, AuthMeColumns.NICK_NAME, realName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public DataSourceValue<String> getEmail(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
try {
|
||||
return columnsHandler.retrieve(user, AuthMeColumns.EMAIL);
|
||||
} catch (SQLException e) {
|
||||
|
@ -10,7 +10,7 @@ import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
@ -84,14 +84,14 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean isAuthAvailable(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return getAuth(user) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public HashedPassword getPassword(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
user = user.toLowerCase();
|
||||
Optional<PlayerAuth> pAuthOpt = cachedAuths.getIfPresent(user);
|
||||
if (pAuthOpt != null && pAuthOpt.isPresent()) {
|
||||
@ -103,7 +103,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public PlayerAuth getAuth(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
user = user.toLowerCase();
|
||||
return cachedAuths.getUnchecked(user).orElse(null);
|
||||
}
|
||||
@ -111,7 +111,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean saveAuth(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
boolean result = source.saveAuth(auth);
|
||||
if (result) {
|
||||
cachedAuths.refresh(auth.getNickname());
|
||||
@ -122,7 +122,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updatePassword(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
boolean result = source.updatePassword(auth);
|
||||
if (result) {
|
||||
cachedAuths.refresh(auth.getNickname());
|
||||
@ -133,7 +133,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updatePassword(String user, HashedPassword password) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
user = user.toLowerCase();
|
||||
boolean result = source.updatePassword(user, password);
|
||||
if (result) {
|
||||
@ -145,7 +145,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
boolean result = source.updateSession(auth);
|
||||
if (result) {
|
||||
cachedAuths.refresh(auth.getNickname());
|
||||
@ -156,7 +156,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateQuitLoc(final PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
boolean result = source.updateQuitLoc(auth);
|
||||
if (result) {
|
||||
cachedAuths.refresh(auth.getNickname());
|
||||
@ -167,14 +167,14 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.getRecordsToPurge(until);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean removeAuth(String name) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
name = name.toLowerCase();
|
||||
boolean result = source.removeAuth(name);
|
||||
if (result) {
|
||||
@ -198,7 +198,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateEmail(final PlayerAuth auth) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
boolean result = source.updateEmail(auth);
|
||||
if (result) {
|
||||
cachedAuths.refresh(auth.getNickname());
|
||||
@ -209,77 +209,77 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public List<String> getAllAuthsByIp(String ip) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.getAllAuthsByIp(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public int countAuthsByEmail(String email) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.countAuthsByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void purgeRecords(Collection<String> banned) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
source.purgeRecords(banned);
|
||||
cachedAuths.invalidateAll(banned);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean isLogged(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.isLogged(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void setLogged(final String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
source.setLogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void setUnlogged(final String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
source.setUnlogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean hasSession(final String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.hasSession(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void grantSession(final String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
source.grantSession(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void revokeSession(final String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
source.revokeSession(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void purgeLogged() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
source.purgeLogged();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
@ -287,14 +287,14 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public int getAccountsRegistered() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.getAccountsRegistered();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean updateRealName(String user, String realName) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
boolean result = source.updateRealName(user, realName);
|
||||
if (result) {
|
||||
cachedAuths.refresh(user);
|
||||
@ -305,7 +305,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public DataSourceValue<String> getEmail(String user) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return cachedAuths.getUnchecked(user)
|
||||
.map(auth -> DataSourceValueImpl.of(auth.getEmail()))
|
||||
.orElse(DataSourceValueImpl.unknownRow());
|
||||
@ -314,14 +314,14 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public List<PlayerAuth> getAllAuths() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.getAllAuths();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public List<String> getLoggedPlayersWithEmptyMail() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return playerCache.getCache().values().stream()
|
||||
.filter(auth -> Utils.isEmailEmpty(auth.getEmail()))
|
||||
.map(PlayerAuth::getRealName)
|
||||
@ -331,14 +331,14 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public List<PlayerAuth> getRecentlyLoggedInPlayers() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
return source.getRecentlyLoggedInPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public boolean setTotpKey(String user, String totpKey) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
boolean result = source.setTotpKey(user, totpKey);
|
||||
if (result) {
|
||||
cachedAuths.refresh(user);
|
||||
@ -354,7 +354,7 @@ public class CacheDataSource implements DataSource {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void refreshCache(String playerName) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (cachedAuths.getIfPresent(playerName) != null) {
|
||||
cachedAuths.refresh(playerName);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import ch.jalu.datasourcecolumns.data.DataSourceValue;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
@ -313,7 +313,7 @@ public interface DataSource extends Reloadable {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
default void refreshCache(String playerName) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Abstract class for AuthMe converters.
|
||||
*/
|
||||
public abstract class AbstractConverter {
|
||||
|
||||
/**
|
||||
* Execute the conversion.
|
||||
*
|
||||
* @param sender the sender who initialized the conversion
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public void execute(CommandSender sender) {
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
executeInternal(sender);
|
||||
}
|
||||
|
||||
@ShouldBeAsync
|
||||
protected abstract void executeInternal(CommandSender sender);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
@ -17,7 +18,7 @@ import static fr.xephi.authme.util.Utils.logAndSendMessage;
|
||||
*
|
||||
* @param <S> the source type to convert from
|
||||
*/
|
||||
public abstract class AbstractDataSourceConverter<S extends DataSource> implements Converter {
|
||||
public abstract class AbstractDataSourceConverter<S extends DataSource> extends AbstractConverter {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(MySqlToSqlite.class);
|
||||
|
||||
@ -40,7 +41,8 @@ public abstract class AbstractDataSourceConverter<S extends DataSource> implemen
|
||||
// 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) {
|
||||
@ShouldBeAsync
|
||||
public void executeInternal(CommandSender sender) {
|
||||
if (destinationType != destination.getType()) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage("Please configure your connection to "
|
||||
|
@ -1,19 +0,0 @@
|
||||
package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Interface for AuthMe converters.
|
||||
*/
|
||||
public interface Converter {
|
||||
|
||||
/**
|
||||
* Execute the conversion.
|
||||
* TODO: apply the ShouldBeAsync annotation to all the converters
|
||||
*
|
||||
* @param sender the sender who initialized the conversion
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
void execute(CommandSender sender);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
@ -18,7 +19,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* Converter for CrazyLogin to AuthMe.
|
||||
*/
|
||||
public class CrazyLoginConverter implements Converter {
|
||||
public class CrazyLoginConverter extends AbstractConverter {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(CrazyLoginConverter.class);
|
||||
|
||||
@ -34,7 +35,8 @@ public class CrazyLoginConverter implements Converter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
@ShouldBeAsync
|
||||
public void executeInternal(CommandSender sender) {
|
||||
String fileName = settings.getProperty(ConverterSettings.CRAZYLOGIN_FILE_NAME);
|
||||
File source = new File(dataFolder, fileName);
|
||||
if (!source.exists()) {
|
||||
|
@ -2,6 +2,7 @@ package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
@ -30,7 +31,7 @@ import static fr.xephi.authme.util.Utils.logAndSendMessage;
|
||||
/**
|
||||
* Converts data from LoginSecurity to AuthMe.
|
||||
*/
|
||||
public class LoginSecurityConverter implements Converter {
|
||||
public class LoginSecurityConverter extends AbstractConverter {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(LoginSecurityConverter.class);
|
||||
private final File dataFolder;
|
||||
@ -55,7 +56,8 @@ public class LoginSecurityConverter implements Converter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
@ShouldBeAsync
|
||||
public void executeInternal(CommandSender sender) {
|
||||
try (Connection connection = createConnectionOrInformSender(sender)) {
|
||||
if (connection != null) {
|
||||
performConversion(sender, connection);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
@ -24,7 +25,7 @@ import java.util.Map.Entry;
|
||||
/**
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class RakamakConverter implements Converter {
|
||||
public class RakamakConverter extends AbstractConverter {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(RakamakConverter.class);
|
||||
private final DataSource database;
|
||||
@ -41,9 +42,10 @@ public class RakamakConverter implements Converter {
|
||||
this.passwordSecurity = passwordSecurity;
|
||||
}
|
||||
|
||||
@Override
|
||||
//TODO ljacqu 20151229: Restructure this into smaller portions
|
||||
public void execute(CommandSender sender) {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void executeInternal(CommandSender sender) {
|
||||
boolean useIp = settings.getProperty(ConverterSettings.RAKAMAK_USE_IP);
|
||||
String fileName = settings.getProperty(ConverterSettings.RAKAMAK_FILE_NAME);
|
||||
String ipFileName = settings.getProperty(ConverterSettings.RAKAMAK_IP_FILE_NAME);
|
||||
|
@ -2,6 +2,7 @@ package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
@ -15,7 +16,7 @@ import java.io.File;
|
||||
|
||||
import static fr.xephi.authme.util.FileUtils.makePath;
|
||||
|
||||
public class RoyalAuthConverter implements Converter {
|
||||
public class RoyalAuthConverter extends AbstractConverter {
|
||||
|
||||
private static final String LAST_LOGIN_PATH = "timestamps.quit";
|
||||
private static final String PASSWORD_PATH = "login.password";
|
||||
@ -32,7 +33,8 @@ public class RoyalAuthConverter implements Converter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
@ShouldBeAsync
|
||||
public void executeInternal(CommandSender sender) {
|
||||
for (OfflinePlayer player : plugin.getServer().getOfflinePlayers()) {
|
||||
try {
|
||||
String name = player.getName().toLowerCase();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
@ -17,7 +18,7 @@ import java.util.UUID;
|
||||
|
||||
import static fr.xephi.authme.util.FileUtils.makePath;
|
||||
|
||||
public class VAuthConverter implements Converter {
|
||||
public class VAuthConverter extends AbstractConverter {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(VAuthConverter.class);
|
||||
private final DataSource dataSource;
|
||||
@ -30,7 +31,8 @@ public class VAuthConverter implements Converter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
@ShouldBeAsync
|
||||
public void executeInternal(CommandSender sender) {
|
||||
try (Scanner scanner = new Scanner(vAuthPasswordsFile)) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
|
@ -3,6 +3,7 @@ package fr.xephi.authme.datasource.converter;
|
||||
import de.luricos.bukkit.xAuth.database.DatabaseTables;
|
||||
import de.luricos.bukkit.xAuth.utils.xAuthLog;
|
||||
import de.luricos.bukkit.xAuth.xAuth;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
@ -21,7 +22,7 @@ import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.util.FileUtils.makePath;
|
||||
|
||||
public class XAuthConverter implements Converter {
|
||||
public class XAuthConverter extends AbstractConverter {
|
||||
|
||||
@Inject
|
||||
@DataFolder
|
||||
@ -35,7 +36,8 @@ public class XAuthConverter implements Converter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
@ShouldBeAsync
|
||||
public void executeInternal(CommandSender sender) {
|
||||
try {
|
||||
Class.forName("de.luricos.bukkit.xAuth.xAuth");
|
||||
convert(sender);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.MightBeAsync;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
@ -76,7 +76,7 @@ public class OnJoinVerifier implements Reloadable {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public void checkAntibot(String name, boolean isAuthAvailable) throws FailedVerificationException {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (isAuthAvailable || permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_ANTIBOT)) {
|
||||
return;
|
||||
}
|
||||
@ -127,7 +127,7 @@ public class OnJoinVerifier implements Reloadable {
|
||||
* further), false if the player is not refused
|
||||
*/
|
||||
public boolean refusePlayerForFullServer(PlayerLoginEvent event) {
|
||||
ThreadSafety.requireSync();
|
||||
BukkitThreadSafety.requireSync();
|
||||
final Player player = event.getPlayer();
|
||||
if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL) {
|
||||
// Server is not full, no need to do anything
|
||||
@ -165,7 +165,7 @@ public class OnJoinVerifier implements Reloadable {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public void checkNameCasing(String connectingName, PlayerAuth auth) throws FailedVerificationException {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (auth != null && settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE)) {
|
||||
String realName = auth.getRealName(); // might be null or "Player"
|
||||
|
||||
@ -188,7 +188,7 @@ public class OnJoinVerifier implements Reloadable {
|
||||
@ShouldBeAsync
|
||||
public void checkPlayerCountry(String name, String address,
|
||||
boolean isAuthAvailable) throws FailedVerificationException {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if ((!isAuthAvailable || settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED))
|
||||
&& settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)
|
||||
&& !permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_COUNTRY_CHECK)
|
||||
@ -205,7 +205,7 @@ public class OnJoinVerifier implements Reloadable {
|
||||
* @throws FailedVerificationException if the verification fails
|
||||
*/
|
||||
public void checkSingleSession(String name) throws FailedVerificationException {
|
||||
ThreadSafety.requireSync();
|
||||
BukkitThreadSafety.requireSync();
|
||||
if (!settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)) {
|
||||
return;
|
||||
}
|
||||
@ -224,7 +224,7 @@ public class OnJoinVerifier implements Reloadable {
|
||||
* @return the player to kick, or null if none applicable
|
||||
*/
|
||||
private Player generateKickPlayer(Collection<Player> onlinePlayers) {
|
||||
ThreadSafety.requireSync();
|
||||
BukkitThreadSafety.requireSync();
|
||||
for (Player player : onlinePlayers) {
|
||||
if (!permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)) {
|
||||
return player;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.mail;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.MightBeAsync;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
@ -54,7 +54,7 @@ public class EmailService {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public boolean sendPasswordMail(String name, String mailAddress, String newPass) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (!hasAllInformation()) {
|
||||
logger.warning("Cannot perform email registration: not all email settings are complete");
|
||||
return false;
|
||||
@ -96,7 +96,7 @@ public class EmailService {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public boolean sendVerificationMail(String name, String mailAddress, String code) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (!hasAllInformation()) {
|
||||
logger.warning("Cannot send verification email: not all email settings are complete");
|
||||
return false;
|
||||
@ -125,7 +125,7 @@ public class EmailService {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public boolean sendRecoveryCode(String name, String email, String code) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
HtmlEmail htmlEmail;
|
||||
try {
|
||||
htmlEmail = sendMailSsl.initializeMail(email);
|
||||
|
@ -4,7 +4,6 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.MightBeAsync;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
@ -108,7 +108,7 @@ public class AntiBotService implements SettingsDependent {
|
||||
* Transitions the anti bot service from active status back to listening.
|
||||
*/
|
||||
private void stopProtection() {
|
||||
ThreadSafety.requireSync();
|
||||
BukkitThreadSafety.requireSync();
|
||||
if (antiBotStatus != AntiBotStatus.ACTIVE) {
|
||||
return;
|
||||
}
|
||||
@ -144,7 +144,7 @@ public class AntiBotService implements SettingsDependent {
|
||||
* @param started the new protection status
|
||||
*/
|
||||
public void overrideAntiBotStatus(boolean started) {
|
||||
ThreadSafety.requireSync();
|
||||
BukkitThreadSafety.requireSync();
|
||||
if (antiBotStatus != AntiBotStatus.DISABLED) {
|
||||
if (started) {
|
||||
startProtection();
|
||||
@ -161,7 +161,7 @@ public class AntiBotService implements SettingsDependent {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public boolean shouldKick() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (antiBotStatus == AntiBotStatus.DISABLED) {
|
||||
return false;
|
||||
} else if (antiBotStatus == AntiBotStatus.ACTIVE) {
|
||||
|
@ -11,7 +11,7 @@ import com.maxmind.db.cache.CHMCache;
|
||||
import com.maxmind.db.model.Country;
|
||||
import com.maxmind.db.model.CountryResponse;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
@ -132,7 +132,7 @@ public class GeoIpService {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
private void updateDatabase() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
logger.info("Downloading GEO IP database, because the old database is older than "
|
||||
+ UPDATE_INTERVAL_DAYS + " days or doesn't exist");
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.MightBeAsync;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
@ -72,7 +72,7 @@ public class PasswordRecoveryService implements Reloadable, HasCleanup {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public void createAndSendRecoveryCode(Player player, String email) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (!checkEmailCooldown(player)) {
|
||||
return;
|
||||
}
|
||||
@ -96,7 +96,7 @@ public class PasswordRecoveryService implements Reloadable, HasCleanup {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public void generateAndSendNewPassword(Player player, String email) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (!checkEmailCooldown(player)) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.task.purge;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
@ -57,7 +57,7 @@ public class PurgeExecutor {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
public void executePurge(Collection<OfflinePlayer> players, Collection<String> names) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
// Purge other data
|
||||
purgeFromAuthMe(names);
|
||||
purgeEssentials(players);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.task.purge;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
@ -121,7 +121,7 @@ public class PurgeService {
|
||||
*/
|
||||
@ShouldBeAsync
|
||||
void executePurge(Collection<OfflinePlayer> players, Collection<String> names) {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
purgeExecutor.executePurge(players, names);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.task.purge;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.ThreadSafety;
|
||||
import fr.xephi.authme.util.BukkitThreadSafety;
|
||||
import fr.xephi.authme.annotation.ShouldBeAsync;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
@ -61,7 +61,7 @@ class PurgeTask extends BukkitRunnable {
|
||||
@Override
|
||||
@ShouldBeAsync
|
||||
public void run() {
|
||||
ThreadSafety.shouldBeAsync();
|
||||
BukkitThreadSafety.shouldBeAsync();
|
||||
if (toPurge.isEmpty()) {
|
||||
//everything was removed
|
||||
finish();
|
||||
|
@ -1,22 +1,41 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
/**
|
||||
* A thread-safe interval counter, allows to detect if an event happens more than 'threshold' times
|
||||
* in the given 'interval'.
|
||||
*/
|
||||
public class AtomicIntervalCounter {
|
||||
private final int threshold;
|
||||
private final int interval;
|
||||
private int count;
|
||||
private long lastInsert;
|
||||
|
||||
/**
|
||||
* Constructs a new counter.
|
||||
*
|
||||
* @param threshold the threshold value of the counter.
|
||||
* @param interval the counter interval in milliseconds.
|
||||
*/
|
||||
public AtomicIntervalCounter(int threshold, int interval) {
|
||||
this.threshold = threshold;
|
||||
this.interval = interval;
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the counter count.
|
||||
*/
|
||||
public synchronized void reset() {
|
||||
count = 0;
|
||||
lastInsert = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the counter and returns true if the current count has reached the threshold value
|
||||
* in the given interval, this will also reset the count value.
|
||||
*
|
||||
* @return true if the count has reached the threshold value.
|
||||
*/
|
||||
public synchronized boolean handle() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastInsert > interval) {
|
||||
|
@ -1,18 +1,29 @@
|
||||
package fr.xephi.authme;
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public final class ThreadSafety {
|
||||
/**
|
||||
* Utility class that provides static methods to ensure that methods are called from the right thread.
|
||||
*/
|
||||
public final class BukkitThreadSafety {
|
||||
|
||||
private static boolean enabled = false;
|
||||
|
||||
private ThreadSafety() {
|
||||
private BukkitThreadSafety() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/disables the bukkit thread-safety warnings.
|
||||
*
|
||||
* @param enabled true if the warnings should be enabled, false otherwise.
|
||||
*/
|
||||
public static void setEnabled(boolean enabled) {
|
||||
ThreadSafety.enabled = enabled;
|
||||
BukkitThreadSafety.enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning if called by an async thread (not the main server thread).
|
||||
*/
|
||||
public static void requireSync() {
|
||||
if (!enabled || Bukkit.isPrimaryThread()) {
|
||||
return;
|
||||
@ -21,6 +32,9 @@ public final class ThreadSafety {
|
||||
new Throwable().printStackTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning if called by the main server thread.
|
||||
*/
|
||||
public static void shouldBeAsync() {
|
||||
if (!enabled || !Bukkit.isPrimaryThread()) {
|
||||
return;
|
@ -24,7 +24,6 @@ public final class PlayerUtils {
|
||||
|
||||
/**
|
||||
* Returns if the player is an NPC or not.
|
||||
* TODO: is player metadata thread-safe?
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return True if the player is an NPC, false otherwise
|
||||
|
@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import ch.jalu.injector.factory.Factory;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.datasource.converter.Converter;
|
||||
import fr.xephi.authme.datasource.converter.AbstractConverter;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
@ -49,7 +49,7 @@ public class ConverterCommandTest {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private Factory<Converter> converterFactory;
|
||||
private Factory<AbstractConverter> converterFactory;
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
@ -87,10 +87,10 @@ public class ConverterCommandTest {
|
||||
@Test
|
||||
public void shouldHaveUniqueClassForEachConverter() {
|
||||
// given
|
||||
Set<Class<? extends Converter>> classes = new HashSet<>();
|
||||
Set<Class<? extends AbstractConverter>> classes = new HashSet<>();
|
||||
|
||||
// when / then
|
||||
for (Map.Entry<String, Class<? extends Converter>> entry : ConverterCommand.CONVERTERS.entrySet()) {
|
||||
for (Map.Entry<String, Class<? extends AbstractConverter>> entry : ConverterCommand.CONVERTERS.entrySet()) {
|
||||
assertThat("Name is not null or empty",
|
||||
StringUtils.isEmpty(entry.getKey()), equalTo(false));
|
||||
|
||||
@ -103,8 +103,8 @@ public class ConverterCommandTest {
|
||||
public void shouldLaunchConverterForAllTypes() {
|
||||
// given
|
||||
String converterName = "rakamak";
|
||||
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||
Converter converter = createMockReturnedByInjector(converterClass);
|
||||
Class<? extends AbstractConverter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||
AbstractConverter converter = createMockReturnedByInjector(converterClass);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
setBukkitServiceToRunTaskAsynchronously(bukkitService);
|
||||
|
||||
@ -122,8 +122,8 @@ public class ConverterCommandTest {
|
||||
public void shouldCatchExceptionInConverterAndInformSender() {
|
||||
// given
|
||||
String converterName = "vauth";
|
||||
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||
Converter converter = createMockReturnedByInjector(converterClass);
|
||||
Class<? extends AbstractConverter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||
AbstractConverter converter = createMockReturnedByInjector(converterClass);
|
||||
doThrow(IllegalStateException.class).when(converter).execute(any(CommandSender.class));
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
setBukkitServiceToRunTaskAsynchronously(bukkitService);
|
||||
@ -139,7 +139,7 @@ public class ConverterCommandTest {
|
||||
verify(commonService).send(sender, MessageKey.ERROR);
|
||||
}
|
||||
|
||||
private <T extends Converter> T createMockReturnedByInjector(Class<T> clazz) {
|
||||
private <T extends AbstractConverter> T createMockReturnedByInjector(Class<T> clazz) {
|
||||
T converter = mock(clazz);
|
||||
given(converterFactory.newInstance(clazz)).willReturn(converter);
|
||||
return converter;
|
||||
|
@ -42,11 +42,11 @@ public class AbstractDataSourceConverterTest {
|
||||
given(destination.getType()).willReturn(DataSourceType.MYSQL);
|
||||
DataSourceType destinationType = DataSourceType.SQLITE;
|
||||
DataSource source = mock(DataSource.class);
|
||||
Converter converter = new DataSourceConverterTestImpl<>(source, destination, destinationType);
|
||||
AbstractConverter converter = new DataSourceConverterTestImpl<>(source, destination, destinationType);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
converter.execute(sender);
|
||||
converter.executeInternal(sender);
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Please configure your connection to SQLITE")));
|
||||
@ -67,7 +67,7 @@ public class AbstractDataSourceConverterTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
converter.execute(sender);
|
||||
converter.executeInternal(sender);
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage("The data source to convert from could not be initialized");
|
||||
@ -88,11 +88,11 @@ public class AbstractDataSourceConverterTest {
|
||||
given(source.getAllAuths()).willReturn(auths);
|
||||
given(destination.isAuthAvailable(auths.get(0).getNickname())).willReturn(true);
|
||||
|
||||
Converter converter = new DataSourceConverterTestImpl<>(source, destination, destinationType);
|
||||
AbstractConverter converter = new DataSourceConverterTestImpl<>(source, destination, destinationType);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
converter.execute(sender);
|
||||
converter.executeInternal(sender);
|
||||
|
||||
// then
|
||||
verify(destination).getType();
|
||||
|
@ -59,7 +59,7 @@ public class CrazyLoginConverterTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
crazyLoginConverter.execute(sender);
|
||||
crazyLoginConverter.executeInternal(sender);
|
||||
|
||||
// then
|
||||
ArgumentCaptor<PlayerAuth> authCaptor = ArgumentCaptor.forClass(PlayerAuth.class);
|
||||
@ -78,7 +78,7 @@ public class CrazyLoginConverterTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
crazyLoginConverter.execute(sender);
|
||||
crazyLoginConverter.executeInternal(sender);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(dataSource);
|
||||
|
@ -14,7 +14,7 @@ import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.executable.authme.debug.DebugCommand;
|
||||
import fr.xephi.authme.data.limbo.persistence.LimboPersistence;
|
||||
import fr.xephi.authme.datasource.converter.Converter;
|
||||
import fr.xephi.authme.datasource.converter.AbstractConverter;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
@ -204,7 +204,7 @@ public class DrawDependency implements ToolTask {
|
||||
LimboPersistence.class.getPackage().getName() + ".LimboPersistenceHandler");
|
||||
|
||||
return ImmutableList.of(ExecutableCommand.class, SynchronousProcess.class, AsynchronousProcess.class,
|
||||
EncryptionMethod.class, Converter.class, Listener.class, RegistrationExecutor.class, debugSectionClass,
|
||||
EncryptionMethod.class, AbstractConverter.class, Listener.class, RegistrationExecutor.class, debugSectionClass,
|
||||
limboPersistenceClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
Loading…
Reference in New Issue
Block a user