Search in sources :

Example 86 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncAddEmail method addEmail.

/**
     * Handles the request to add the given email to the player's account.
     *
     * @param player the player to add the email to
     * @param email the email to add
     */
public void addEmail(Player player, String email) {
    String playerName = player.getName().toLowerCase();
    if (playerCache.isAuthenticated(playerName)) {
        PlayerAuth auth = playerCache.getAuth(playerName);
        final String currentEmail = auth.getEmail();
        if (!Utils.isEmailEmpty(currentEmail)) {
            service.send(player, MessageKey.USAGE_CHANGE_EMAIL);
        } else if (!validationService.validateEmail(email)) {
            service.send(player, MessageKey.INVALID_EMAIL);
        } else if (!validationService.isEmailFreeForRegistration(email, player)) {
            service.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
        } else {
            auth.setEmail(email);
            if (dataSource.updateEmail(auth)) {
                playerCache.updatePlayer(auth);
                service.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
            } else {
                ConsoleLogger.warning("Could not save email for player '" + player + "'");
                service.send(player, MessageKey.ERROR);
            }
        }
    } else {
        sendUnloggedMessage(player);
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 87 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncChangeEmail method changeEmail.

/**
     * Handles the request to change the player's email address.
     *
     * @param player the player to change the email for
     * @param oldEmail provided old email
     * @param newEmail provided new email
     */
public void changeEmail(Player player, String oldEmail, String newEmail) {
    String playerName = player.getName().toLowerCase();
    if (playerCache.isAuthenticated(playerName)) {
        PlayerAuth auth = playerCache.getAuth(playerName);
        final String currentEmail = auth.getEmail();
        if (currentEmail == null) {
            service.send(player, MessageKey.USAGE_ADD_EMAIL);
        } else if (newEmail == null || !validationService.validateEmail(newEmail)) {
            service.send(player, MessageKey.INVALID_NEW_EMAIL);
        } else if (!oldEmail.equals(currentEmail)) {
            service.send(player, MessageKey.INVALID_OLD_EMAIL);
        } else if (!validationService.isEmailFreeForRegistration(newEmail, player)) {
            service.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
        } else {
            saveNewEmail(auth, player, newEmail);
        }
    } else {
        outputUnloggedMessage(player);
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 88 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsynchronousJoin method canResumeSession.

private boolean canResumeSession(Player player) {
    final String name = player.getName();
    if (sessionManager.hasSession(name) || database.isLogged(name)) {
        PlayerAuth auth = database.getAuth(name);
        database.setUnlogged(name);
        playerCache.removePlayer(name);
        if (auth != null) {
            if (auth.getIp().equals(PlayerUtils.getPlayerIp(player))) {
                RestoreSessionEvent event = bukkitService.createAndCallEvent(isAsync -> new RestoreSessionEvent(player, isAsync));
                return !event.isCancelled();
            } else {
                service.send(player, MessageKey.SESSION_EXPIRED);
            }
        }
    }
    return false;
}
Also used : RestoreSessionEvent(fr.xephi.authme.events.RestoreSessionEvent) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 89 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class ProcessSyncPlayerLogin method processPlayerLogin.

public void processPlayerLogin(Player player) {
    final String name = player.getName().toLowerCase();
    final LimboPlayer limbo = limboService.getLimboPlayer(name);
    // Limbo contains the State of the Player before /login
    if (limbo != null) {
        limboService.restoreData(player);
    }
    if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
        restoreInventory(player);
    }
    final PlayerAuth auth = dataSource.getAuth(name);
    teleportationService.teleportOnLogin(player, auth, limbo);
    // We can now display the join message (if delayed)
    joinMessageService.sendMessage(name);
    if (commonService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
        player.removePotionEffect(PotionEffectType.BLINDNESS);
    }
    // The Login event now fires (as intended) after everything is processed
    bukkitService.callEvent(new LoginEvent(player));
    player.saveData();
    // Login is done, display welcome message
    List<String> welcomeMessage = welcomeMessageConfiguration.getWelcomeMessage(player);
    if (commonService.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
        if (commonService.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
            welcomeMessage.forEach(bukkitService::broadcastMessage);
        } else {
            welcomeMessage.forEach(player::sendMessage);
        }
    }
    // Login is now finished; we can force all commands
    commandManager.runCommandsOnLogin(player);
    // Send Bungee stuff. The service will check if it is enabled or not.
    bungeeService.connectPlayer(player);
}
Also used : LoginEvent(fr.xephi.authme.events.LoginEvent) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 90 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsynchronousLogout method logout.

/**
     * Handles a player's request to log out.
     *
     * @param player the player wanting to log out
     */
public void logout(Player player) {
    final String name = player.getName().toLowerCase();
    if (!playerCache.isAuthenticated(name)) {
        service.send(player, MessageKey.NOT_LOGGED_IN);
        return;
    }
    PlayerAuth auth = playerCache.getAuth(name);
    database.updateSession(auth);
    if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
        auth.setQuitLocation(player.getLocation());
        database.updateQuitLoc(auth);
    }
    playerCache.removePlayer(name);
    database.setUnlogged(name);
    syncProcessManager.processSyncPlayerLogout(player);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Aggregations

PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)102 Test (org.junit.Test)65 Player (org.bukkit.entity.Player)33 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)21 CommandSender (org.bukkit.command.CommandSender)16 Location (org.bukkit.Location)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)9 IOException (java.io.IOException)7 World (org.bukkit.World)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 ArrayList (java.util.ArrayList)5 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)4 Connection (java.sql.Connection)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)3 File (java.io.File)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3