diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java index 3a32c8ee..c18380f4 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java @@ -4,7 +4,9 @@ import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; +import fr.xephi.authme.service.bungeecord.MessageType; import org.bukkit.command.CommandSender; import javax.inject.Inject; @@ -21,6 +23,9 @@ public class PurgeLastPositionCommand implements ExecutableCommand { @Inject private CommonService commonService; + @Inject + private BungeeService bungeeService; + @Override public void executeCommand(final CommandSender sender, List arguments) { String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0); @@ -29,6 +34,7 @@ public class PurgeLastPositionCommand implements ExecutableCommand { for (PlayerAuth auth : dataSource.getAllAuths()) { resetLastPosition(auth); dataSource.updateQuitLoc(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName); } sender.sendMessage("All players last position locations are now reset"); } else { @@ -41,6 +47,7 @@ public class PurgeLastPositionCommand implements ExecutableCommand { resetLastPosition(auth); dataSource.updateQuitLoc(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName); sender.sendMessage(playerName + "'s last position location is now reset"); } } diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 3eaa815c..ac2eaf12 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -262,4 +262,17 @@ public class CacheDataSource implements DataSource { .map(PlayerAuth::getRealName) .collect(Collectors.toList()); } + + @Override + public void invalidateCache(String playerName) { + cachedAuths.invalidate(playerName); + } + + @Override + public void refreshCache(String playerName) { + 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 c040b080..715cb059 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -231,4 +231,20 @@ public interface DataSource extends Reloadable { @Override void reload(); + /** + * Invalidate any cached data related to the specified player name. + * + * @param playerName the player name + */ + default void invalidateCache(String playerName) { + } + + /** + * Refresh any cached data (if present) related to the specified player name. + * + * @param playerName the player name + */ + default void refreshCache(String playerName) { + } + } diff --git a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java index 992483bf..38ef73b2 100644 --- a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java +++ b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java @@ -5,7 +5,9 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.limbo.LimboService; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -34,6 +36,8 @@ public class OnShutdownPlayerSaver { private PlayerCache playerCache; @Inject private LimboService limboService; + @Inject + private BungeeService bungeeService; OnShutdownPlayerSaver() { } @@ -68,6 +72,7 @@ public class OnShutdownPlayerSaver { .realName(player.getName()) .location(loc).build(); dataSource.updateQuitLoc(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, player.getName()); } } } diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 4b2c08f3..c00c8b67 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -8,6 +8,8 @@ import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.process.Management; import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.bungeecord.MessageType; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.JoinMessageService; import fr.xephi.authme.service.TeleportationService; import fr.xephi.authme.service.ValidationService; @@ -83,6 +85,8 @@ public class PlayerListener implements Listener { private JoinMessageService joinMessageService; @Inject private PermissionsManager permissionsManager; + @Inject + private BungeeService bungeeService; private boolean isAsyncPlayerPreLoginEventCalled = false; @@ -426,6 +430,7 @@ public class PlayerListener implements Listener { .location(spawn) .build(); dataSource.updateQuitLoc(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name); } if (spawn != null && spawn.getWorld() != null) { event.setRespawnLocation(spawn); diff --git a/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java b/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java index 27e84d24..a285b768 100644 --- a/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java +++ b/src/main/java/fr/xephi/authme/process/changepassword/AsyncChangePassword.java @@ -6,9 +6,11 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; +import fr.xephi.authme.service.bungeecord.MessageType; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -28,6 +30,9 @@ public class AsyncChangePassword implements AsynchronousProcess { @Inject private PlayerCache playerCache; + @Inject + private BungeeService bungeeService; + AsyncChangePassword() { } @@ -49,6 +54,7 @@ public class AsyncChangePassword implements AsynchronousProcess { commonService.send(player, MessageKey.ERROR); return; } + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, name); playerCache.updatePlayer(auth); commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS); @@ -78,6 +84,7 @@ public class AsyncChangePassword implements AsynchronousProcess { HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, lowerCaseName); if (dataSource.updatePassword(lowerCaseName, hashedPassword)) { + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, lowerCaseName); if (sender != null) { commonService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS); ConsoleLogger.info(sender.getName() + " changed password of " + lowerCaseName); diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java index d2d68ceb..b5b74c43 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java @@ -6,8 +6,10 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.util.Utils; import org.bukkit.entity.Player; @@ -30,6 +32,9 @@ public class AsyncAddEmail implements AsynchronousProcess { @Inject private ValidationService validationService; + @Inject + private BungeeService bungeeService; + AsyncAddEmail() { } /** @@ -55,6 +60,7 @@ public class AsyncAddEmail implements AsynchronousProcess { auth.setEmail(email); if (dataSource.updateEmail(auth)) { playerCache.updatePlayer(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, playerName); service.send(player, MessageKey.EMAIL_ADDED_SUCCESS); } else { ConsoleLogger.warning("Could not save email for player '" + player + "'"); diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java index 1c69c843..237246d7 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -5,8 +5,10 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.bungeecord.MessageType; import org.bukkit.entity.Player; import javax.inject.Inject; @@ -28,6 +30,9 @@ public class AsyncChangeEmail implements AsynchronousProcess { @Inject private ValidationService validationService; + @Inject + private BungeeService bungeeService; + AsyncChangeEmail() { } /** @@ -63,6 +68,7 @@ public class AsyncChangeEmail implements AsynchronousProcess { auth.setEmail(newEmail); if (dataSource.updateEmail(auth)) { playerCache.updatePlayer(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, player.getName()); service.send(player, MessageKey.EMAIL_CHANGED_SUCCESS); } else { service.send(player, MessageKey.ERROR); diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index a32a8845..03dc9f46 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -19,8 +19,10 @@ import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.SessionService; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.HooksSettings; @@ -73,6 +75,9 @@ public class AsynchronousLogin implements AsynchronousProcess { @Inject private SessionService sessionService; + @Inject + private BungeeService bungeeService; + AsynchronousLogin() { } @@ -221,6 +226,7 @@ public class AsynchronousLogin implements AsynchronousProcess { auth.setLastLogin(System.currentTimeMillis()); auth.setLastIp(ip); dataSource.updateSession(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, player.getName()); // Successful login, so reset the captcha & temp ban count final String name = player.getName(); @@ -246,6 +252,7 @@ public class AsynchronousLogin implements AsynchronousProcess { playerCache.updatePlayer(auth); dataSource.setLogged(name); sessionService.grantSession(name); + bungeeService.sendAuthMeBungeecordMessage(MessageType.LOGIN, name); // As the scheduling executes the Task most likely after the current // task, we schedule it in the end diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index acfaef42..752b3748 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -8,7 +8,7 @@ import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RestoreInventoryEvent; import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.service.BungeeService; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.JoinMessageService; import fr.xephi.authme.service.TeleportationService; @@ -96,6 +96,6 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { commandManager.runCommandsOnLogin(player); // Send Bungee stuff. The service will check if it is enabled or not. - bungeeService.connectPlayer(player); + bungeeService.connectPlayerOnLogin(player); } } diff --git a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java index 01784b9d..a64b0e5a 100644 --- a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java @@ -7,7 +7,10 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.SyncProcessManager; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; +import fr.xephi.authme.service.SessionService; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.settings.properties.RestrictionSettings; import org.bukkit.entity.Player; @@ -33,6 +36,12 @@ public class AsynchronousLogout implements AsynchronousProcess { @Inject private SyncProcessManager syncProcessManager; + @Inject + private SessionService sessionService; + + @Inject + private BungeeService bungeeService; + AsynchronousLogout() { } @@ -50,15 +59,18 @@ public class AsynchronousLogout implements AsynchronousProcess { PlayerAuth auth = playerCache.getAuth(name); database.updateSession(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, name); if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) { auth.setQuitLocation(player.getLocation()); database.updateQuitLoc(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name); } playerCache.removePlayer(name); codeManager.unverify(name); database.setUnlogged(name); - database.revokeSession(name); + sessionService.revokeSession(name); + bungeeService.sendAuthMeBungeecordMessage(MessageType.LOGOUT, name); syncProcessManager.processSyncPlayerLogout(player); } } diff --git a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java index 58b626a5..66d6938f 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java @@ -4,16 +4,18 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.data.VerificationCodeManager; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; -import fr.xephi.authme.datasource.CacheDataSource; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.process.AsynchronousProcess; -import fr.xephi.authme.service.CommonService; import fr.xephi.authme.process.SyncProcessManager; +import fr.xephi.authme.service.CommonService; +import fr.xephi.authme.service.SessionService; +import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.bungeecord.BungeeService; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.util.PlayerUtils; -import fr.xephi.authme.service.ValidationService; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -48,6 +50,12 @@ public class AsynchronousQuit implements AsynchronousProcess { @Inject private VerificationCodeManager codeManager; + @Inject + private SessionService sessionService; + + @Inject + private BungeeService bungeeService; + AsynchronousQuit() { } @@ -80,6 +88,7 @@ public class AsynchronousQuit implements AsynchronousProcess { .lastLogin(System.currentTimeMillis()) .build(); database.updateSession(auth); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name); } //always unauthenticate the player - use session only for auto logins on the same ip @@ -90,7 +99,7 @@ public class AsynchronousQuit implements AsynchronousProcess { if (wasLoggedIn) { database.setUnlogged(name); if (!service.getProperty(PluginSettings.SESSIONS_ENABLED)) { - database.revokeSession(name); + sessionService.revokeSession(name); } } @@ -99,9 +108,7 @@ public class AsynchronousQuit implements AsynchronousProcess { } // remove player from cache - if (database instanceof CacheDataSource) { - ((CacheDataSource) database).getCachedAuths().invalidate(name); - } + database.invalidateCache(name); } } diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 83e5a82c..a48942fd 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -10,7 +10,9 @@ import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.register.executors.RegistrationExecutor; import fr.xephi.authme.process.register.executors.RegistrationParameters; import fr.xephi.authme.process.register.executors.RegistrationMethod; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.util.PlayerUtils; @@ -36,6 +38,8 @@ public class AsyncRegister implements AsynchronousProcess { private PermissionsManager permissionsManager; @Inject private SingletonStore registrationExecutorFactory; + @Inject + private BungeeService bungeeService; AsyncRegister() { } @@ -84,6 +88,7 @@ public class AsyncRegister implements AsynchronousProcess { PlayerAuth auth = executor.buildPlayerAuth(parameters); if (database.saveAuth(auth)) { executor.executePostPersistAction(parameters); + bungeeService.sendAuthMeBungeecordMessage(MessageType.REGISTER, parameters.getPlayerName()); } else { service.send(parameters.getPlayer(), MessageKey.ERROR); } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index 4a5f42db..a1ac8663 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -4,7 +4,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.data.limbo.LimboService; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.SynchronousProcess; -import fr.xephi.authme.service.BungeeService; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.settings.commandconfig.CommandManager; import fr.xephi.authme.settings.properties.EmailSettings; @@ -72,6 +72,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { } // Send Bungee stuff. The service will check if it is enabled or not. - bungeeService.connectPlayer(player); + bungeeService.connectPlayerOnLogin(player); } } diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index 29f2e7b1..d4845c93 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -11,8 +11,10 @@ import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.TeleportationService; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.settings.commandconfig.CommandManager; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -51,6 +53,9 @@ public class AsynchronousUnregister implements AsynchronousProcess { @Inject private CommandManager commandManager; + @Inject + private BungeeService bungeeService; + AsynchronousUnregister() { } @@ -66,7 +71,7 @@ public class AsynchronousUnregister implements AsynchronousProcess { final PlayerAuth cachedAuth = playerCache.getAuth(name); if (passwordSecurity.comparePassword(password, cachedAuth.getPassword(), name)) { if (dataSource.removeAuth(name)) { - performUnregister(name, player); + performPostUnregisterActions(name, player); ConsoleLogger.info(name + " unregistered himself"); bukkitService.createAndCallEvent(isAsync -> new UnregisterByPlayerEvent(player, isAsync)); } else { @@ -78,7 +83,7 @@ public class AsynchronousUnregister implements AsynchronousProcess { } /** - * Unregisters a player. + * Unregisters a player as administrator or console. * * @param initiator the initiator of this process (nullable) * @param name the name of the player @@ -88,7 +93,7 @@ public class AsynchronousUnregister implements AsynchronousProcess { // we might have some player in the database that has never been online on the server public void adminUnregister(CommandSender initiator, String name, Player player) { if (dataSource.removeAuth(name)) { - performUnregister(name, player); + performPostUnregisterActions(name, player); bukkitService.createAndCallEvent(isAsync -> new UnregisterByAdminEvent(player, name, isAsync, initiator)); if (initiator == null) { @@ -102,8 +107,16 @@ public class AsynchronousUnregister implements AsynchronousProcess { } } - private void performUnregister(String name, Player player) { + /** + * Process the post unregister actions. Makes the user status consistent. + * + * @param name the name of the player + * @param player the according Player object (nullable) + */ + private void performPostUnregisterActions(String name, Player player) { playerCache.removePlayer(name); + bungeeService.sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name); + if (player == null || !player.isOnline()) { return; } @@ -127,4 +140,5 @@ public class AsynchronousUnregister implements AsynchronousProcess { player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2)); } } + } diff --git a/src/main/java/fr/xephi/authme/service/BukkitService.java b/src/main/java/fr/xephi/authme/service/BukkitService.java index f5b03348..eac2229c 100644 --- a/src/main/java/fr/xephi/authme/service/BukkitService.java +++ b/src/main/java/fr/xephi/authme/service/BukkitService.java @@ -363,4 +363,8 @@ public class BukkitService implements SettingsDependent { public BanEntry banIp(String ip, String reason, Date expires, String source) { return Bukkit.getServer().getBanList(BanList.Type.IP).addBan(ip, reason, expires, source); } + + public void sendPluginMessage(String channel, byte[] data) { + Bukkit.getServer().sendPluginMessage(authMe, channel, data); + } } diff --git a/src/main/java/fr/xephi/authme/service/BungeeService.java b/src/main/java/fr/xephi/authme/service/BungeeService.java deleted file mode 100644 index 9739cb17..00000000 --- a/src/main/java/fr/xephi/authme/service/BungeeService.java +++ /dev/null @@ -1,69 +0,0 @@ -package fr.xephi.authme.service; - -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; -import fr.xephi.authme.AuthMe; -import fr.xephi.authme.initialization.SettingsDependent; -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.settings.properties.HooksSettings; -import org.bukkit.entity.Player; -import org.bukkit.plugin.messaging.Messenger; - -import javax.inject.Inject; - -/** - * Class to manage all BungeeCord related processes. - */ -public class BungeeService implements SettingsDependent { - - private AuthMe plugin; - private BukkitService service; - - private boolean isEnabled; - private String bungeeServer; - - /* - * Constructor. - */ - @Inject - BungeeService(AuthMe plugin, BukkitService service, Settings settings) { - this.plugin = plugin; - this.service = service; - reload(settings); - } - - /** - * Send a player to a specified server. If no server is configured, this will - * do nothing. - * - * @param player The player to send. - */ - public void connectPlayer(Player player) { - if (!isEnabled || bungeeServer.isEmpty()) { - return; - } - - service.scheduleSyncDelayedTask(new Runnable() { - @Override - public void run() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("Connect"); - out.writeUTF(bungeeServer); - player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); - } - }, 20L); - } - - @Override - public void reload(Settings settings) { - this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD); - this.bungeeServer = settings.getProperty(HooksSettings.BUNGEECORD_SERVER); - Messenger messenger = plugin.getServer().getMessenger(); - if (!this.isEnabled) { - return; - } - if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) { - messenger.registerOutgoingPluginChannel(plugin, "BungeeCord"); - } - } -} diff --git a/src/main/java/fr/xephi/authme/service/SessionService.java b/src/main/java/fr/xephi/authme/service/SessionService.java index a4000e91..dd676cc8 100644 --- a/src/main/java/fr/xephi/authme/service/SessionService.java +++ b/src/main/java/fr/xephi/authme/service/SessionService.java @@ -83,6 +83,10 @@ public class SessionService implements Reloadable { } } + public void revokeSession(String name) { + database.revokeSession(name); + } + @Override public void reload() { this.isEnabled = service.getProperty(PluginSettings.SESSIONS_ENABLED); diff --git a/src/main/java/fr/xephi/authme/service/bungeecord/BungeeService.java b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeService.java new file mode 100644 index 00000000..2dbab189 --- /dev/null +++ b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeService.java @@ -0,0 +1,125 @@ +package fr.xephi.authme.service.bungeecord; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.initialization.SettingsDependent; +import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.HooksSettings; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.Messenger; +import org.bukkit.plugin.messaging.PluginMessageListener; + +import javax.inject.Inject; + +/** + * Class to manage all BungeeCord related processes. + */ +public class BungeeService implements SettingsDependent, PluginMessageListener { + + private final AuthMe plugin; + private final BukkitService service; + private final DataSource dataSource; + + private boolean isEnabled; + private String destinationServerOnLogin; + + + /* + * Constructor. + */ + @Inject + BungeeService(AuthMe plugin, BukkitService service, Settings settings, DataSource dataSource) { + this.plugin = plugin; + this.service = service; + this.dataSource = dataSource; + reload(settings); + } + + @Override + public void reload(Settings settings) { + this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD); + this.destinationServerOnLogin = settings.getProperty(HooksSettings.BUNGEECORD_SERVER); + Messenger messenger = plugin.getServer().getMessenger(); + if (!this.isEnabled) { + return; + } + if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) { + messenger.registerOutgoingPluginChannel(plugin, "BungeeCord"); + } + if (!messenger.isIncomingChannelRegistered(plugin, "BungeeCord")) { + messenger.registerIncomingPluginChannel(plugin, "BungeeCord", this); + } + } + + private void sendBungeecordMessage(String... data) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + for (String element : data) { + out.writeUTF(element); + } + service.sendPluginMessage("BungeeCord", out.toByteArray()); + } + + /** + * Send a player to a specified server. If no server is configured, this will + * do nothing. + * + * @param player The player to send. + */ + public void connectPlayerOnLogin(Player player) { + if (!isEnabled || destinationServerOnLogin.isEmpty()) { + return; + } + + service.scheduleSyncDelayedTask(() -> + sendBungeecordMessage("Connect", player.getName(), destinationServerOnLogin), 20L); + } + + /** + * Sends a message to the AuthMe plugin messaging channel, if enabled. + * + * @param type The message type, {@see MessageType} + * @param playerName the player related to the message + */ + public void sendAuthMeBungeecordMessage(String type, String playerName) { + if (isEnabled) { + return; + } + + sendBungeecordMessage("AuthMe", type, playerName.toLowerCase()); + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] data) { + if (!isEnabled) { + return; + } + + ByteArrayDataInput in = ByteStreams.newDataInput(data); + String subchannel = in.readUTF(); + if (!"Authme".equals(subchannel)) { + return; + } + + String type = in.readUTF(); + String name = in.readUTF(); + switch (type) { + case MessageType.UNREGISTER: + dataSource.invalidateCache(name); + break; + case MessageType.REFRESH_PASSWORD: + case MessageType.REFRESH_QUITLOC: + case MessageType.REFRESH_EMAIL: + case MessageType.REFRESH: + dataSource.refreshCache(name); + break; + default: + ConsoleLogger.debug("Received unsupported bungeecord message type! ({0})", type); + } + } + +} diff --git a/src/main/java/fr/xephi/authme/service/bungeecord/MessageType.java b/src/main/java/fr/xephi/authme/service/bungeecord/MessageType.java new file mode 100644 index 00000000..1e692a93 --- /dev/null +++ b/src/main/java/fr/xephi/authme/service/bungeecord/MessageType.java @@ -0,0 +1,18 @@ +package fr.xephi.authme.service.bungeecord; + +public final class MessageType { + + public static final String LOGIN = "login"; + public static final String LOGOUT = "logout"; + public static final String REGISTER = "register"; + public static final String UNREGISTER = "unregister"; + public static final String REFRESH_PASSWORD = "refresh.password"; + public static final String REFRESH_SESSION = "refresh.session"; + public static final String REFRESH_QUITLOC = "refresh.quitloc"; + public static final String REFRESH_EMAIL = "refresh.email"; + public static final String REFRESH = "refresh"; + + private MessageType() { + } + +} diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java index a4880512..0f14a0de 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommandTest.java @@ -3,6 +3,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import org.bukkit.command.CommandSender; import org.junit.Test; @@ -35,6 +36,8 @@ public class PurgeLastPositionCommandTest { @Mock private CommonService service; + @Mock + private BungeeService bungeeService; @Test public void shouldPurgeLastPosOfUser() { diff --git a/src/test/java/fr/xephi/authme/datasource/AbstractSqlDataSourceResourceClosingTest.java b/src/test/java/fr/xephi/authme/datasource/AbstractSqlDataSourceResourceClosingTest.java index edb6d4f6..1827a93a 100644 --- a/src/test/java/fr/xephi/authme/datasource/AbstractSqlDataSourceResourceClosingTest.java +++ b/src/test/java/fr/xephi/authme/datasource/AbstractSqlDataSourceResourceClosingTest.java @@ -66,7 +66,7 @@ public abstract class AbstractSqlDataSourceResourceClosingTest extends AbstractR private static List getDataSourceMethods() { List publicMethods = new ArrayList<>(); for (Method method : DataSource.class.getDeclaredMethods()) { - if (!IGNORED_METHODS.contains(method.getName())) { + if (!IGNORED_METHODS.contains(method.getName()) && !method.isSynthetic()) { publicMethods.add(method); } } diff --git a/src/test/java/fr/xephi/authme/listener/ListenerConsistencyTest.java b/src/test/java/fr/xephi/authme/listener/ListenerConsistencyTest.java index e00d032a..c8d1d804 100644 --- a/src/test/java/fr/xephi/authme/listener/ListenerConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/listener/ListenerConsistencyTest.java @@ -117,12 +117,9 @@ public final class ListenerConsistencyTest { } private static boolean isTestableMethod(Method method) { - // Exclude any methods with "$" in it: jacoco creates a "$jacocoInit" method we want to ignore, and - // methods like "access$000" are created by the compiler when a private member is being accessed by an inner - // class, which is not of interest for us - // Also exclude getters + // Exclude getters and synthetic methods String methodName = method.getName(); - if (Modifier.isPrivate(method.getModifiers()) || methodName.contains("$") || methodName.startsWith("get") || methodName.startsWith("is")) { + if (Modifier.isPrivate(method.getModifiers()) || method.isSynthetic() || methodName.startsWith("get") || methodName.startsWith("is")) { return false; } // Skip reload() method (implementation of Reloadable interface) diff --git a/src/test/java/fr/xephi/authme/process/changepassword/AsyncChangePasswordTest.java b/src/test/java/fr/xephi/authme/process/changepassword/AsyncChangePasswordTest.java index 76633544..1cb9390e 100644 --- a/src/test/java/fr/xephi/authme/process/changepassword/AsyncChangePasswordTest.java +++ b/src/test/java/fr/xephi/authme/process/changepassword/AsyncChangePasswordTest.java @@ -6,6 +6,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import org.bukkit.command.CommandSender; import org.junit.Before; @@ -37,6 +38,8 @@ public class AsyncChangePasswordTest { private PlayerCache playerCache; @Mock private PasswordSecurity passwordSecurity; + @Mock + private BungeeService bungeeService; @Before public void setUpLogger() { diff --git a/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java b/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java index 3966eabf..a982f815 100644 --- a/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java +++ b/src/test/java/fr/xephi/authme/process/email/AsyncAddEmailTest.java @@ -5,6 +5,7 @@ import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.ValidationService; import org.bukkit.entity.Player; @@ -45,6 +46,9 @@ public class AsyncAddEmailTest { @Mock private ValidationService validationService; + @Mock + private BungeeService bungeeService; + @BeforeClass public static void setUp() { TestHelper.setupLogger(); diff --git a/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java b/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java index f45aef91..5f2a9c83 100644 --- a/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java +++ b/src/test/java/fr/xephi/authme/process/email/AsyncChangeEmailTest.java @@ -4,6 +4,7 @@ import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.ValidationService; import org.bukkit.entity.Player; @@ -44,6 +45,9 @@ public class AsyncChangeEmailTest { @Mock private ValidationService validationService; + @Mock + private BungeeService bungeeService; + @Test public void shouldChangeEmail() { // given diff --git a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java index 06e8f002..1cb83605 100644 --- a/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java +++ b/src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java @@ -10,6 +10,7 @@ import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.bungeecord.BungeeService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.TeleportationService; import fr.xephi.authme.settings.commandconfig.CommandManager; @@ -61,6 +62,8 @@ public class AsynchronousUnregisterTest { private TeleportationService teleportationService; @Mock private CommandManager commandManager; + @Mock + private BungeeService bungeeService; @BeforeClass public static void initLogger() {