diff --git a/src/main/java/fr/xephi/authme/process/SyncProcessManager.java b/src/main/java/fr/xephi/authme/process/SyncProcessManager.java index 136c6b353..0fdfdde3d 100644 --- a/src/main/java/fr/xephi/authme/process/SyncProcessManager.java +++ b/src/main/java/fr/xephi/authme/process/SyncProcessManager.java @@ -9,6 +9,7 @@ import fr.xephi.authme.service.BukkitService; import org.bukkit.entity.Player; import javax.inject.Inject; +import java.util.List; /** * Manager for scheduling synchronous processes internally from the asynchronous processes. @@ -47,8 +48,8 @@ public class SyncProcessManager { runTask(() -> processSyncPlayerLogout.processSyncLogout(player)); } - public void processSyncPlayerLogin(Player player, boolean isFirstLogin) { - runTask(() -> processSyncPlayerLogin.processPlayerLogin(player, isFirstLogin)); + public void processSyncPlayerLogin(Player player, boolean isFirstLogin, List authsWithSameIp) { + runTask(() -> processSyncPlayerLogin.processPlayerLogin(player, isFirstLogin, authsWithSameIp)); } public void processSyncPlayerQuit(Player player, boolean wasLoggedIn) { 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 5dacba5a4..c52202ef4 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -2,10 +2,10 @@ package fr.xephi.authme.process.login; import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.data.captcha.LoginCaptchaManager; import fr.xephi.authme.data.TempbanManager; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; +import fr.xephi.authme.data.captcha.LoginCaptchaManager; import fr.xephi.authme.data.limbo.LimboService; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; @@ -240,7 +240,6 @@ public class AsynchronousLogin implements AsynchronousProcess { // Other auths List auths = dataSource.getAllAuthsByIp(auth.getLastIp()); - runCommandOtherAccounts(auths, player, auth.getLastIp()); displayOtherAccounts(auths, player); final String email = auth.getEmail(); @@ -260,30 +259,12 @@ public class AsynchronousLogin implements AsynchronousProcess { // task, we schedule it in the end // so that we can be sure, and have not to care if it might be // processed in other order. - syncProcessManager.processSyncPlayerLogin(player, isFirstLogin); + syncProcessManager.processSyncPlayerLogin(player, isFirstLogin, auths); } else { ConsoleLogger.warning("Player '" + player.getName() + "' wasn't online during login process, aborted..."); } } - private void runCommandOtherAccounts(List auths, Player player, String ip) { - int threshold = service.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD_THRESHOLD); - String command = service.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD); - - if (threshold < 2 || command.isEmpty()) { - return; - } - - if (auths.size() < threshold) { - return; - } - - bukkitService.dispatchConsoleCommand(command - .replace("%playername%", player.getName()) - .replace("%playerip%", ip) - ); - } - /** * Sends info about the other accounts owned by the given player to the configured users. * 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 f47ccdbff..bd06dd6b3 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -15,10 +15,13 @@ import fr.xephi.authme.service.bungeecord.BungeeSender; import fr.xephi.authme.settings.WelcomeMessageConfiguration; import fr.xephi.authme.settings.commandconfig.CommandManager; import fr.xephi.authme.settings.properties.RegistrationSettings; +import fr.xephi.authme.settings.properties.RestrictionSettings; +import fr.xephi.authme.util.PlayerUtils; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import javax.inject.Inject; +import java.util.List; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; @@ -67,8 +70,9 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { * * @param player the player that was logged in * @param isFirstLogin true if this is the first time the player logged in + * @param authsWithSameIp registered names with the same IP address as the player's */ - public void processPlayerLogin(Player player, boolean isFirstLogin) { + public void processPlayerLogin(Player player, boolean isFirstLogin, List authsWithSameIp) { final String name = player.getName().toLowerCase(); final LimboPlayer limbo = limboService.getLimboPlayer(name); @@ -95,6 +99,9 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { bukkitService.callEvent(new LoginEvent(player)); player.saveData(); + // Run command if player has other accounts + runCommandOtherAccounts(authsWithSameIp, player); + // Login is done, display welcome message welcomeMessageConfiguration.sendWelcomeMessage(player); @@ -107,4 +114,16 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { // Send Bungee stuff. The service will check if it is enabled or not. bungeeSender.connectPlayerOnLogin(player); } + + private void runCommandOtherAccounts(List auths, Player player) { + int threshold = commonService.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD_THRESHOLD); + String command = commonService.getProperty(RestrictionSettings.OTHER_ACCOUNTS_CMD); + + if (threshold >= 2 && !command.isEmpty() && auths.size() >= threshold) { + bukkitService.dispatchConsoleCommand(command + .replace("%playername%", player.getName()) + .replace("%playerip%", PlayerUtils.getPlayerIp(player)) + ); + } + } }