diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 3ccf30aaf..8bef3823f 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -116,7 +116,6 @@ public class AuthMe extends JavaPlugin { */ @Override public void onEnable() { - ThreadSafetyUtils.setEnabled(true); // Load the plugin version data from the plugin description file loadPluginInfo(getDescription().getVersion()); @@ -172,6 +171,8 @@ 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); // Purge on start if enabled PurgeService purgeService = injector.getSingleton(PurgeService.class); diff --git a/src/main/java/fr/xephi/authme/ThreadSafetyUtils.java b/src/main/java/fr/xephi/authme/ThreadSafety.java similarity index 84% rename from src/main/java/fr/xephi/authme/ThreadSafetyUtils.java rename to src/main/java/fr/xephi/authme/ThreadSafety.java index 0d092dd13..386a89b95 100644 --- a/src/main/java/fr/xephi/authme/ThreadSafetyUtils.java +++ b/src/main/java/fr/xephi/authme/ThreadSafety.java @@ -2,15 +2,15 @@ package fr.xephi.authme; import org.bukkit.Bukkit; -public final class ThreadSafetyUtils { +public final class ThreadSafety { private static boolean enabled = false; - private ThreadSafetyUtils() { + private ThreadSafety() { } public static void setEnabled(boolean enabled) { - ThreadSafetyUtils.enabled = enabled; + ThreadSafety.enabled = enabled; } public static void requireSync() { diff --git a/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java b/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java index 1928d1b6d..b79831984 100644 --- a/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/AbstractSqlDataSource.java @@ -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.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); try { DataSourceValue 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return columnsHandler.update(auth, AuthMeColumns.LAST_IP, AuthMeColumns.LAST_LOGIN, AuthMeColumns.NICK_NAME); } @Override @ShouldBeAsync public boolean updatePassword(PlayerAuth auth) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return updatePassword(auth.getNickname(), auth.getPassword()); } @Override @ShouldBeAsync public boolean updatePassword(String user, HashedPassword password) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 getAllAuthsByIp(String ip) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return columnsHandler.count(eqIgnoreCase(AuthMeColumns.EMAIL, email)); } @Override @ShouldBeAsync public boolean updateEmail(PlayerAuth auth) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return columnsHandler.update(auth, AuthMeColumns.EMAIL); } @Override @ShouldBeAsync public boolean isLogged(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); try { DataSourceValue 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 1); } @Override @ShouldBeAsync public void setUnlogged(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 0); } @Override @ShouldBeAsync public void grantSession(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 1); } @Override @ShouldBeAsync public void revokeSession(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 0); } @Override @ShouldBeAsync public void purgeLogged() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); columnsHandler.update(eq(AuthMeColumns.IS_LOGGED, 1), AuthMeColumns.IS_LOGGED, 0); } @Override @ShouldBeAsync public int getAccountsRegistered() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return columnsHandler.count(new AlwaysTruePredicate<>()); } @Override @ShouldBeAsync public boolean updateRealName(String user, String realName) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return columnsHandler.update(user, AuthMeColumns.NICK_NAME, realName); } @Override @ShouldBeAsync public DataSourceValue getEmail(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); try { return columnsHandler.retrieve(user, AuthMeColumns.EMAIL); } catch (SQLException e) { diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 979baa0f7..3c377dc61 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -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.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return getAuth(user) != null; } @Override @ShouldBeAsync public HashedPassword getPassword(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); user = user.toLowerCase(); Optional 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 getRecordsToPurge(long until) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.getRecordsToPurge(until); } @Override @ShouldBeAsync public boolean removeAuth(String name) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 getAllAuthsByIp(String ip) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.getAllAuthsByIp(ip); } @Override @ShouldBeAsync public int countAuthsByEmail(String email) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.countAuthsByEmail(email); } @Override @ShouldBeAsync public void purgeRecords(Collection banned) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); source.purgeRecords(banned); cachedAuths.invalidateAll(banned); } @Override public DataSourceType getType() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.getType(); } @Override @ShouldBeAsync public boolean isLogged(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.isLogged(user); } @Override @ShouldBeAsync public void setLogged(final String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); source.setLogged(user.toLowerCase()); } @Override @ShouldBeAsync public void setUnlogged(final String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); source.setUnlogged(user.toLowerCase()); } @Override @ShouldBeAsync public boolean hasSession(final String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.hasSession(user); } @Override @ShouldBeAsync public void grantSession(final String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); source.grantSession(user); } @Override @ShouldBeAsync public void revokeSession(final String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); source.revokeSession(user); } @Override @ShouldBeAsync public void purgeLogged() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); source.purgeLogged(); cachedAuths.invalidateAll(); } @@ -287,14 +287,14 @@ public class CacheDataSource implements DataSource { @Override @ShouldBeAsync public int getAccountsRegistered() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.getAccountsRegistered(); } @Override @ShouldBeAsync public boolean updateRealName(String user, String realName) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 getEmail(String user) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 getAllAuths() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.getAllAuths(); } @Override @ShouldBeAsync public List getLoggedPlayersWithEmptyMail() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 getRecentlyLoggedInPlayers() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); return source.getRecentlyLoggedInPlayers(); } @Override @ShouldBeAsync public boolean setTotpKey(String user, String totpKey) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); if (cachedAuths.getIfPresent(playerName) != null) { cachedAuths.refresh(playerName); } diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index 26078353d..d699f7588 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -1,7 +1,7 @@ package fr.xephi.authme.datasource; import ch.jalu.datasourcecolumns.data.DataSourceValue; -import fr.xephi.authme.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); } } diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index 5ecb86b1b..8444e518e 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -1,7 +1,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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 { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.requireSync(); + ThreadSafety.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 { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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 { - ThreadSafetyUtils.requireSync(); + ThreadSafety.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 onlinePlayers) { - ThreadSafetyUtils.requireSync(); + ThreadSafety.requireSync(); for (Player player : onlinePlayers) { if (!permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)) { return player; diff --git a/src/main/java/fr/xephi/authme/mail/EmailService.java b/src/main/java/fr/xephi/authme/mail/EmailService.java index fe2452ec0..f25ad9549 100644 --- a/src/main/java/fr/xephi/authme/mail/EmailService.java +++ b/src/main/java/fr/xephi/authme/mail/EmailService.java @@ -1,7 +1,7 @@ package fr.xephi.authme.mail; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); HtmlEmail htmlEmail; try { htmlEmail = sendMailSsl.initializeMail(email); diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java index 3e1ace6cb..5c8fe89dc 100644 --- a/src/main/java/fr/xephi/authme/service/AntiBotService.java +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -1,6 +1,6 @@ package fr.xephi.authme.service; -import fr.xephi.authme.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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() { - ThreadSafetyUtils.requireSync(); + ThreadSafety.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) { - ThreadSafetyUtils.requireSync(); + ThreadSafety.requireSync(); if (antiBotStatus != AntiBotStatus.DISABLED) { if (started) { startProtection(); @@ -161,7 +161,7 @@ public class AntiBotService implements SettingsDependent { */ @ShouldBeAsync public boolean shouldKick() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); if (antiBotStatus == AntiBotStatus.DISABLED) { return false; } else if (antiBotStatus == AntiBotStatus.ACTIVE) { diff --git a/src/main/java/fr/xephi/authme/service/GeoIpService.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java index 59a62d8b5..1d0e9c7bb 100644 --- a/src/main/java/fr/xephi/authme/service/GeoIpService.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -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.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); logger.info("Downloading GEO IP database, because the old database is older than " + UPDATE_INTERVAL_DAYS + " days or doesn't exist"); diff --git a/src/main/java/fr/xephi/authme/service/PasswordRecoveryService.java b/src/main/java/fr/xephi/authme/service/PasswordRecoveryService.java index 4799b3406..d8726f5e5 100644 --- a/src/main/java/fr/xephi/authme/service/PasswordRecoveryService.java +++ b/src/main/java/fr/xephi/authme/service/PasswordRecoveryService.java @@ -1,7 +1,7 @@ package fr.xephi.authme.service; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); if (!checkEmailCooldown(player)) { return; } @@ -96,7 +96,7 @@ public class PasswordRecoveryService implements Reloadable, HasCleanup { */ @ShouldBeAsync public void generateAndSendNewPassword(Player player, String email) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); if (!checkEmailCooldown(player)) { return; } diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java index d0ac1b858..2e795f991 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java @@ -1,8 +1,7 @@ package fr.xephi.authme.task.purge; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.ThreadSafetyUtils; -import fr.xephi.authme.annotation.MightBeAsync; +import fr.xephi.authme.ThreadSafety; import fr.xephi.authme.annotation.ShouldBeAsync; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.ConsoleLoggerFactory; @@ -58,7 +57,7 @@ public class PurgeExecutor { */ @ShouldBeAsync public void executePurge(Collection players, Collection names) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); // Purge other data purgeFromAuthMe(names); purgeEssentials(players); diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeService.java b/src/main/java/fr/xephi/authme/task/purge/PurgeService.java index d7ac7ef5b..3372acfab 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeService.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeService.java @@ -1,7 +1,7 @@ package fr.xephi.authme.task.purge; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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 players, Collection names) { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); purgeExecutor.executePurge(players, names); } } diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java b/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java index cc99e81d8..46942c515 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java @@ -1,7 +1,7 @@ package fr.xephi.authme.task.purge; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.ThreadSafetyUtils; +import fr.xephi.authme.ThreadSafety; 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() { - ThreadSafetyUtils.shouldBeAsync(); + ThreadSafety.shouldBeAsync(); if (toPurge.isEmpty()) { //everything was removed finish();