#1454 Run other accounts command in sync mode

This commit is contained in:
ljacqu 2018-01-08 23:08:37 +01:00
parent e906a6abfa
commit d9c1af4311
3 changed files with 25 additions and 24 deletions

View File

@ -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<String> authsWithSameIp) {
runTask(() -> processSyncPlayerLogin.processPlayerLogin(player, isFirstLogin, authsWithSameIp));
}
public void processSyncPlayerQuit(Player player, boolean wasLoggedIn) {

View File

@ -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<String> 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<String> 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.
*

View File

@ -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<String> 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<String> 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))
);
}
}
}