This commit is contained in:
Gabriele C 2020-01-28 15:08:47 +01:00
parent 5acf9c0d94
commit 81d240f4a4
13 changed files with 85 additions and 85 deletions

View File

@ -116,7 +116,6 @@ public class AuthMe extends JavaPlugin {
*/ */
@Override @Override
public void onEnable() { public void onEnable() {
ThreadSafetyUtils.setEnabled(true);
// Load the plugin version data from the plugin description file // Load the plugin version data from the plugin description file
loadPluginInfo(getDescription().getVersion()); loadPluginInfo(getDescription().getVersion());
@ -172,6 +171,8 @@ public class AuthMe extends JavaPlugin {
// Successful message // Successful message
logger.info("AuthMe " + getPluginVersion() + " build n." + getPluginBuildNumber() + " successfully enabled!"); logger.info("AuthMe " + getPluginVersion() + " build n." + getPluginBuildNumber() + " successfully enabled!");
// Start catching wrong sync/async calls
ThreadSafety.setEnabled(true);
// Purge on start if enabled // Purge on start if enabled
PurgeService purgeService = injector.getSingleton(PurgeService.class); PurgeService purgeService = injector.getSingleton(PurgeService.class);

View File

@ -2,15 +2,15 @@ package fr.xephi.authme;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public final class ThreadSafetyUtils { public final class ThreadSafety {
private static boolean enabled = false; private static boolean enabled = false;
private ThreadSafetyUtils() { private ThreadSafety() {
} }
public static void setEnabled(boolean enabled) { public static void setEnabled(boolean enabled) {
ThreadSafetyUtils.enabled = enabled; ThreadSafety.enabled = enabled;
} }
public static void requireSync() { public static void requireSync() {

View File

@ -4,7 +4,7 @@ import ch.jalu.datasourcecolumns.data.DataSourceValue;
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl; 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 fr.xephi.authme.ThreadSafetyUtils; import fr.xephi.authme.ThreadSafety;
import fr.xephi.authme.annotation.ShouldBeAsync; import fr.xephi.authme.annotation.ShouldBeAsync;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.columnshandler.AuthMeColumns; import fr.xephi.authme.datasource.columnshandler.AuthMeColumns;
@ -31,7 +31,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean isAuthAvailable(String user) { public boolean isAuthAvailable(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
try { try {
return columnsHandler.retrieve(user, AuthMeColumns.NAME).rowExists(); return columnsHandler.retrieve(user, AuthMeColumns.NAME).rowExists();
} catch (SQLException e) { } catch (SQLException e) {
@ -43,7 +43,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public HashedPassword getPassword(String user) { public HashedPassword getPassword(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
try { try {
DataSourceValues values = columnsHandler.retrieve(user, AuthMeColumns.PASSWORD, AuthMeColumns.SALT); DataSourceValues values = columnsHandler.retrieve(user, AuthMeColumns.PASSWORD, AuthMeColumns.SALT);
if (values.rowExists()) { if (values.rowExists()) {
@ -58,7 +58,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean saveAuth(PlayerAuth auth) { public boolean saveAuth(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.insert(auth, return columnsHandler.insert(auth,
AuthMeColumns.NAME, AuthMeColumns.NICK_NAME, AuthMeColumns.PASSWORD, AuthMeColumns.SALT, AuthMeColumns.NAME, AuthMeColumns.NICK_NAME, AuthMeColumns.PASSWORD, AuthMeColumns.SALT,
AuthMeColumns.EMAIL, AuthMeColumns.REGISTRATION_DATE, AuthMeColumns.REGISTRATION_IP, AuthMeColumns.EMAIL, AuthMeColumns.REGISTRATION_DATE, AuthMeColumns.REGISTRATION_IP,
@ -68,7 +68,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean hasSession(String user) { public boolean hasSession(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
try { try {
DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.HAS_SESSION); DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.HAS_SESSION);
return result.rowExists() && Integer.valueOf(1).equals(result.getValue()); return result.rowExists() && Integer.valueOf(1).equals(result.getValue());
@ -81,21 +81,21 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.update(auth, AuthMeColumns.LAST_IP, AuthMeColumns.LAST_LOGIN, AuthMeColumns.NICK_NAME); return columnsHandler.update(auth, AuthMeColumns.LAST_IP, AuthMeColumns.LAST_LOGIN, AuthMeColumns.NICK_NAME);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updatePassword(PlayerAuth auth) { public boolean updatePassword(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return updatePassword(auth.getNickname(), auth.getPassword()); return updatePassword(auth.getNickname(), auth.getPassword());
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updatePassword(String user, HashedPassword password) { public boolean updatePassword(String user, HashedPassword password) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.update(user, return columnsHandler.update(user,
with(AuthMeColumns.PASSWORD, password.getHash()) with(AuthMeColumns.PASSWORD, password.getHash())
.and(AuthMeColumns.SALT, password.getSalt()).build()); .and(AuthMeColumns.SALT, password.getSalt()).build());
@ -104,7 +104,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.update(auth, return columnsHandler.update(auth,
AuthMeColumns.LOCATION_X, AuthMeColumns.LOCATION_Y, AuthMeColumns.LOCATION_Z, AuthMeColumns.LOCATION_X, AuthMeColumns.LOCATION_Y, AuthMeColumns.LOCATION_Z,
AuthMeColumns.LOCATION_WORLD, AuthMeColumns.LOCATION_YAW, AuthMeColumns.LOCATION_PITCH); AuthMeColumns.LOCATION_WORLD, AuthMeColumns.LOCATION_YAW, AuthMeColumns.LOCATION_PITCH);
@ -113,7 +113,7 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public List<String> getAllAuthsByIp(String ip) { public List<String> getAllAuthsByIp(String ip) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
try { try {
return columnsHandler.retrieve(eq(AuthMeColumns.LAST_IP, ip), AuthMeColumns.NAME); return columnsHandler.retrieve(eq(AuthMeColumns.LAST_IP, ip), AuthMeColumns.NAME);
} catch (SQLException e) { } catch (SQLException e) {
@ -125,21 +125,21 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public int countAuthsByEmail(String email) { public int countAuthsByEmail(String email) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.count(eqIgnoreCase(AuthMeColumns.EMAIL, email)); return columnsHandler.count(eqIgnoreCase(AuthMeColumns.EMAIL, email));
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateEmail(PlayerAuth auth) { public boolean updateEmail(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.update(auth, AuthMeColumns.EMAIL); return columnsHandler.update(auth, AuthMeColumns.EMAIL);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean isLogged(String user) { public boolean isLogged(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
try { try {
DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.IS_LOGGED); DataSourceValue<Integer> result = columnsHandler.retrieve(user, AuthMeColumns.IS_LOGGED);
return result.rowExists() && Integer.valueOf(1).equals(result.getValue()); return result.rowExists() && Integer.valueOf(1).equals(result.getValue());
@ -152,56 +152,56 @@ public abstract class AbstractSqlDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void setLogged(String user) { public void setLogged(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 1); columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 1);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void setUnlogged(String user) { public void setUnlogged(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 0); columnsHandler.update(user, AuthMeColumns.IS_LOGGED, 0);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void grantSession(String user) { public void grantSession(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 1); columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 1);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void revokeSession(String user) { public void revokeSession(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 0); columnsHandler.update(user, AuthMeColumns.HAS_SESSION, 0);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void purgeLogged() { public void purgeLogged() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
columnsHandler.update(eq(AuthMeColumns.IS_LOGGED, 1), AuthMeColumns.IS_LOGGED, 0); columnsHandler.update(eq(AuthMeColumns.IS_LOGGED, 1), AuthMeColumns.IS_LOGGED, 0);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public int getAccountsRegistered() { public int getAccountsRegistered() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.count(new AlwaysTruePredicate<>()); return columnsHandler.count(new AlwaysTruePredicate<>());
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateRealName(String user, String realName) { public boolean updateRealName(String user, String realName) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return columnsHandler.update(user, AuthMeColumns.NICK_NAME, realName); return columnsHandler.update(user, AuthMeColumns.NICK_NAME, realName);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public DataSourceValue<String> getEmail(String user) { public DataSourceValue<String> getEmail(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
try { try {
return columnsHandler.retrieve(user, AuthMeColumns.EMAIL); return columnsHandler.retrieve(user, AuthMeColumns.EMAIL);
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -10,7 +10,7 @@ import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import fr.xephi.authme.ConsoleLogger; 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.annotation.ShouldBeAsync;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
@ -84,14 +84,14 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean isAuthAvailable(String user) { public boolean isAuthAvailable(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return getAuth(user) != null; return getAuth(user) != null;
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public HashedPassword getPassword(String user) { public HashedPassword getPassword(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
user = user.toLowerCase(); user = user.toLowerCase();
Optional<PlayerAuth> pAuthOpt = cachedAuths.getIfPresent(user); Optional<PlayerAuth> pAuthOpt = cachedAuths.getIfPresent(user);
if (pAuthOpt != null && pAuthOpt.isPresent()) { if (pAuthOpt != null && pAuthOpt.isPresent()) {
@ -103,7 +103,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public PlayerAuth getAuth(String user) { public PlayerAuth getAuth(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
user = user.toLowerCase(); user = user.toLowerCase();
return cachedAuths.getUnchecked(user).orElse(null); return cachedAuths.getUnchecked(user).orElse(null);
} }
@ -111,7 +111,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean saveAuth(PlayerAuth auth) { public boolean saveAuth(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
boolean result = source.saveAuth(auth); boolean result = source.saveAuth(auth);
if (result) { if (result) {
cachedAuths.refresh(auth.getNickname()); cachedAuths.refresh(auth.getNickname());
@ -122,7 +122,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updatePassword(PlayerAuth auth) { public boolean updatePassword(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
boolean result = source.updatePassword(auth); boolean result = source.updatePassword(auth);
if (result) { if (result) {
cachedAuths.refresh(auth.getNickname()); cachedAuths.refresh(auth.getNickname());
@ -133,7 +133,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updatePassword(String user, HashedPassword password) { public boolean updatePassword(String user, HashedPassword password) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
user = user.toLowerCase(); user = user.toLowerCase();
boolean result = source.updatePassword(user, password); boolean result = source.updatePassword(user, password);
if (result) { if (result) {
@ -145,7 +145,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
boolean result = source.updateSession(auth); boolean result = source.updateSession(auth);
if (result) { if (result) {
cachedAuths.refresh(auth.getNickname()); cachedAuths.refresh(auth.getNickname());
@ -156,7 +156,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateQuitLoc(final PlayerAuth auth) { public boolean updateQuitLoc(final PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
boolean result = source.updateQuitLoc(auth); boolean result = source.updateQuitLoc(auth);
if (result) { if (result) {
cachedAuths.refresh(auth.getNickname()); cachedAuths.refresh(auth.getNickname());
@ -167,14 +167,14 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public Set<String> getRecordsToPurge(long until) { public Set<String> getRecordsToPurge(long until) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.getRecordsToPurge(until); return source.getRecordsToPurge(until);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean removeAuth(String name) { public boolean removeAuth(String name) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
name = name.toLowerCase(); name = name.toLowerCase();
boolean result = source.removeAuth(name); boolean result = source.removeAuth(name);
if (result) { if (result) {
@ -198,7 +198,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateEmail(final PlayerAuth auth) { public boolean updateEmail(final PlayerAuth auth) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
boolean result = source.updateEmail(auth); boolean result = source.updateEmail(auth);
if (result) { if (result) {
cachedAuths.refresh(auth.getNickname()); cachedAuths.refresh(auth.getNickname());
@ -209,77 +209,77 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public List<String> getAllAuthsByIp(String ip) { public List<String> getAllAuthsByIp(String ip) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.getAllAuthsByIp(ip); return source.getAllAuthsByIp(ip);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public int countAuthsByEmail(String email) { public int countAuthsByEmail(String email) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.countAuthsByEmail(email); return source.countAuthsByEmail(email);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void purgeRecords(Collection<String> banned) { public void purgeRecords(Collection<String> banned) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
source.purgeRecords(banned); source.purgeRecords(banned);
cachedAuths.invalidateAll(banned); cachedAuths.invalidateAll(banned);
} }
@Override @Override
public DataSourceType getType() { public DataSourceType getType() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.getType(); return source.getType();
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean isLogged(String user) { public boolean isLogged(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.isLogged(user); return source.isLogged(user);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void setLogged(final String user) { public void setLogged(final String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
source.setLogged(user.toLowerCase()); source.setLogged(user.toLowerCase());
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void setUnlogged(final String user) { public void setUnlogged(final String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
source.setUnlogged(user.toLowerCase()); source.setUnlogged(user.toLowerCase());
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean hasSession(final String user) { public boolean hasSession(final String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.hasSession(user); return source.hasSession(user);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void grantSession(final String user) { public void grantSession(final String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
source.grantSession(user); source.grantSession(user);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void revokeSession(final String user) { public void revokeSession(final String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
source.revokeSession(user); source.revokeSession(user);
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void purgeLogged() { public void purgeLogged() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
source.purgeLogged(); source.purgeLogged();
cachedAuths.invalidateAll(); cachedAuths.invalidateAll();
} }
@ -287,14 +287,14 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public int getAccountsRegistered() { public int getAccountsRegistered() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.getAccountsRegistered(); return source.getAccountsRegistered();
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean updateRealName(String user, String realName) { public boolean updateRealName(String user, String realName) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
boolean result = source.updateRealName(user, realName); boolean result = source.updateRealName(user, realName);
if (result) { if (result) {
cachedAuths.refresh(user); cachedAuths.refresh(user);
@ -305,7 +305,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public DataSourceValue<String> getEmail(String user) { public DataSourceValue<String> getEmail(String user) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return cachedAuths.getUnchecked(user) return cachedAuths.getUnchecked(user)
.map(auth -> DataSourceValueImpl.of(auth.getEmail())) .map(auth -> DataSourceValueImpl.of(auth.getEmail()))
.orElse(DataSourceValueImpl.unknownRow()); .orElse(DataSourceValueImpl.unknownRow());
@ -314,14 +314,14 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.getAllAuths(); return source.getAllAuths();
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public List<String> getLoggedPlayersWithEmptyMail() { public List<String> getLoggedPlayersWithEmptyMail() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return playerCache.getCache().values().stream() return playerCache.getCache().values().stream()
.filter(auth -> Utils.isEmailEmpty(auth.getEmail())) .filter(auth -> Utils.isEmailEmpty(auth.getEmail()))
.map(PlayerAuth::getRealName) .map(PlayerAuth::getRealName)
@ -331,14 +331,14 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public List<PlayerAuth> getRecentlyLoggedInPlayers() { public List<PlayerAuth> getRecentlyLoggedInPlayers() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
return source.getRecentlyLoggedInPlayers(); return source.getRecentlyLoggedInPlayers();
} }
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public boolean setTotpKey(String user, String totpKey) { public boolean setTotpKey(String user, String totpKey) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
boolean result = source.setTotpKey(user, totpKey); boolean result = source.setTotpKey(user, totpKey);
if (result) { if (result) {
cachedAuths.refresh(user); cachedAuths.refresh(user);
@ -354,7 +354,7 @@ public class CacheDataSource implements DataSource {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void refreshCache(String playerName) { public void refreshCache(String playerName) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (cachedAuths.getIfPresent(playerName) != null) { if (cachedAuths.getIfPresent(playerName) != null) {
cachedAuths.refresh(playerName); cachedAuths.refresh(playerName);
} }

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import ch.jalu.datasourcecolumns.data.DataSourceValue; 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.annotation.ShouldBeAsync;
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;
@ -313,7 +313,7 @@ public interface DataSource extends Reloadable {
*/ */
@ShouldBeAsync @ShouldBeAsync
default void refreshCache(String playerName) { default void refreshCache(String playerName) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
} }
} }

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import fr.xephi.authme.ConsoleLogger; 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.MightBeAsync;
import fr.xephi.authme.annotation.ShouldBeAsync; import fr.xephi.authme.annotation.ShouldBeAsync;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
@ -76,7 +76,7 @@ public class OnJoinVerifier implements Reloadable {
*/ */
@ShouldBeAsync @ShouldBeAsync
public void checkAntibot(String name, boolean isAuthAvailable) throws FailedVerificationException { public void checkAntibot(String name, boolean isAuthAvailable) throws FailedVerificationException {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (isAuthAvailable || permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_ANTIBOT)) { if (isAuthAvailable || permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_ANTIBOT)) {
return; return;
} }
@ -127,7 +127,7 @@ public class OnJoinVerifier implements Reloadable {
* further), false if the player is not refused * further), false if the player is not refused
*/ */
public boolean refusePlayerForFullServer(PlayerLoginEvent event) { public boolean refusePlayerForFullServer(PlayerLoginEvent event) {
ThreadSafetyUtils.requireSync(); ThreadSafety.requireSync();
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL) { if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL) {
// Server is not full, no need to do anything // Server is not full, no need to do anything
@ -165,7 +165,7 @@ public class OnJoinVerifier implements Reloadable {
*/ */
@ShouldBeAsync @ShouldBeAsync
public void checkNameCasing(String connectingName, PlayerAuth auth) throws FailedVerificationException { public void checkNameCasing(String connectingName, PlayerAuth auth) throws FailedVerificationException {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (auth != null && settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE)) { if (auth != null && settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE)) {
String realName = auth.getRealName(); // might be null or "Player" String realName = auth.getRealName(); // might be null or "Player"
@ -188,7 +188,7 @@ public class OnJoinVerifier implements Reloadable {
@ShouldBeAsync @ShouldBeAsync
public void checkPlayerCountry(String name, String address, public void checkPlayerCountry(String name, String address,
boolean isAuthAvailable) throws FailedVerificationException { boolean isAuthAvailable) throws FailedVerificationException {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if ((!isAuthAvailable || settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED)) if ((!isAuthAvailable || settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED))
&& settings.getProperty(ProtectionSettings.ENABLE_PROTECTION) && settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)
&& !permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_COUNTRY_CHECK) && !permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_COUNTRY_CHECK)
@ -205,7 +205,7 @@ public class OnJoinVerifier implements Reloadable {
* @throws FailedVerificationException if the verification fails * @throws FailedVerificationException if the verification fails
*/ */
public void checkSingleSession(String name) throws FailedVerificationException { public void checkSingleSession(String name) throws FailedVerificationException {
ThreadSafetyUtils.requireSync(); ThreadSafety.requireSync();
if (!settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)) { if (!settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)) {
return; return;
} }
@ -224,7 +224,7 @@ public class OnJoinVerifier implements Reloadable {
* @return the player to kick, or null if none applicable * @return the player to kick, or null if none applicable
*/ */
private Player generateKickPlayer(Collection<Player> onlinePlayers) { private Player generateKickPlayer(Collection<Player> onlinePlayers) {
ThreadSafetyUtils.requireSync(); ThreadSafety.requireSync();
for (Player player : onlinePlayers) { for (Player player : onlinePlayers) {
if (!permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)) { if (!permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)) {
return player; return player;

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.mail; package fr.xephi.authme.mail;
import fr.xephi.authme.ConsoleLogger; 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.MightBeAsync;
import fr.xephi.authme.annotation.ShouldBeAsync; import fr.xephi.authme.annotation.ShouldBeAsync;
import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.DataFolder;
@ -54,7 +54,7 @@ public class EmailService {
*/ */
@ShouldBeAsync @ShouldBeAsync
public boolean sendPasswordMail(String name, String mailAddress, String newPass) { public boolean sendPasswordMail(String name, String mailAddress, String newPass) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (!hasAllInformation()) { if (!hasAllInformation()) {
logger.warning("Cannot perform email registration: not all email settings are complete"); logger.warning("Cannot perform email registration: not all email settings are complete");
return false; return false;
@ -96,7 +96,7 @@ public class EmailService {
*/ */
@ShouldBeAsync @ShouldBeAsync
public boolean sendVerificationMail(String name, String mailAddress, String code) { public boolean sendVerificationMail(String name, String mailAddress, String code) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (!hasAllInformation()) { if (!hasAllInformation()) {
logger.warning("Cannot send verification email: not all email settings are complete"); logger.warning("Cannot send verification email: not all email settings are complete");
return false; return false;
@ -125,7 +125,7 @@ public class EmailService {
*/ */
@ShouldBeAsync @ShouldBeAsync
public boolean sendRecoveryCode(String name, String email, String code) { public boolean sendRecoveryCode(String name, String email, String code) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
HtmlEmail htmlEmail; HtmlEmail htmlEmail;
try { try {
htmlEmail = sendMailSsl.initializeMail(email); htmlEmail = sendMailSsl.initializeMail(email);

View File

@ -1,6 +1,6 @@
package fr.xephi.authme.service; 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.MightBeAsync;
import fr.xephi.authme.annotation.ShouldBeAsync; import fr.xephi.authme.annotation.ShouldBeAsync;
import fr.xephi.authme.initialization.SettingsDependent; 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. * Transitions the anti bot service from active status back to listening.
*/ */
private void stopProtection() { private void stopProtection() {
ThreadSafetyUtils.requireSync(); ThreadSafety.requireSync();
if (antiBotStatus != AntiBotStatus.ACTIVE) { if (antiBotStatus != AntiBotStatus.ACTIVE) {
return; return;
} }
@ -144,7 +144,7 @@ public class AntiBotService implements SettingsDependent {
* @param started the new protection status * @param started the new protection status
*/ */
public void overrideAntiBotStatus(boolean started) { public void overrideAntiBotStatus(boolean started) {
ThreadSafetyUtils.requireSync(); ThreadSafety.requireSync();
if (antiBotStatus != AntiBotStatus.DISABLED) { if (antiBotStatus != AntiBotStatus.DISABLED) {
if (started) { if (started) {
startProtection(); startProtection();
@ -161,7 +161,7 @@ public class AntiBotService implements SettingsDependent {
*/ */
@ShouldBeAsync @ShouldBeAsync
public boolean shouldKick() { public boolean shouldKick() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (antiBotStatus == AntiBotStatus.DISABLED) { if (antiBotStatus == AntiBotStatus.DISABLED) {
return false; return false;
} else if (antiBotStatus == AntiBotStatus.ACTIVE) { } else if (antiBotStatus == AntiBotStatus.ACTIVE) {

View File

@ -11,7 +11,7 @@ import com.maxmind.db.cache.CHMCache;
import com.maxmind.db.model.Country; import com.maxmind.db.model.Country;
import com.maxmind.db.model.CountryResponse; import com.maxmind.db.model.CountryResponse;
import fr.xephi.authme.ConsoleLogger; 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.annotation.ShouldBeAsync;
import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.output.ConsoleLoggerFactory;
@ -132,7 +132,7 @@ public class GeoIpService {
*/ */
@ShouldBeAsync @ShouldBeAsync
private void updateDatabase() { private void updateDatabase() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
logger.info("Downloading GEO IP database, because the old database is older than " logger.info("Downloading GEO IP database, because the old database is older than "
+ UPDATE_INTERVAL_DAYS + " days or doesn't exist"); + UPDATE_INTERVAL_DAYS + " days or doesn't exist");

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.service; package fr.xephi.authme.service;
import fr.xephi.authme.ConsoleLogger; 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.MightBeAsync;
import fr.xephi.authme.annotation.ShouldBeAsync; import fr.xephi.authme.annotation.ShouldBeAsync;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
@ -72,7 +72,7 @@ public class PasswordRecoveryService implements Reloadable, HasCleanup {
*/ */
@ShouldBeAsync @ShouldBeAsync
public void createAndSendRecoveryCode(Player player, String email) { public void createAndSendRecoveryCode(Player player, String email) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (!checkEmailCooldown(player)) { if (!checkEmailCooldown(player)) {
return; return;
} }
@ -96,7 +96,7 @@ public class PasswordRecoveryService implements Reloadable, HasCleanup {
*/ */
@ShouldBeAsync @ShouldBeAsync
public void generateAndSendNewPassword(Player player, String email) { public void generateAndSendNewPassword(Player player, String email) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (!checkEmailCooldown(player)) { if (!checkEmailCooldown(player)) {
return; return;
} }

View File

@ -1,8 +1,7 @@
package fr.xephi.authme.task.purge; package fr.xephi.authme.task.purge;
import fr.xephi.authme.ConsoleLogger; 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.annotation.ShouldBeAsync;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.output.ConsoleLoggerFactory;
@ -58,7 +57,7 @@ public class PurgeExecutor {
*/ */
@ShouldBeAsync @ShouldBeAsync
public void executePurge(Collection<OfflinePlayer> players, Collection<String> names) { public void executePurge(Collection<OfflinePlayer> players, Collection<String> names) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
// Purge other data // Purge other data
purgeFromAuthMe(names); purgeFromAuthMe(names);
purgeEssentials(players); purgeEssentials(players);

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.task.purge; package fr.xephi.authme.task.purge;
import fr.xephi.authme.ConsoleLogger; 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.annotation.ShouldBeAsync;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.output.ConsoleLoggerFactory;
@ -121,7 +121,7 @@ public class PurgeService {
*/ */
@ShouldBeAsync @ShouldBeAsync
void executePurge(Collection<OfflinePlayer> players, Collection<String> names) { void executePurge(Collection<OfflinePlayer> players, Collection<String> names) {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
purgeExecutor.executePurge(players, names); purgeExecutor.executePurge(players, names);
} }
} }

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.task.purge; package fr.xephi.authme.task.purge;
import fr.xephi.authme.ConsoleLogger; 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.annotation.ShouldBeAsync;
import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
@ -61,7 +61,7 @@ class PurgeTask extends BukkitRunnable {
@Override @Override
@ShouldBeAsync @ShouldBeAsync
public void run() { public void run() {
ThreadSafetyUtils.shouldBeAsync(); ThreadSafety.shouldBeAsync();
if (toPurge.isEmpty()) { if (toPurge.isEmpty()) {
//everything was removed //everything was removed
finish(); finish();