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);
}
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations