added async change email process

This commit is contained in:
DNx5 2015-11-03 14:16:57 +07:00
parent 4cbd8aad31
commit f6a91085bd

View File

@ -0,0 +1,83 @@
package fr.xephi.authme.process.email;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player;
import java.util.Arrays;
public class AsyncChangeEmail {
private final Player player;
private final AuthMe plugin;
private final String oldEmail;
private final String newEmail;
private final String newEmailVerify;
private final Messages m;
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, String newEmailVerify) {
this.player = player;
this.plugin = plugin;
this.oldEmail = oldEmail;
this.newEmail = newEmail;
this.newEmailVerify = newEmailVerify;
this.m = Messages.getInstance();
}
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail) {
this(player, plugin, oldEmail, newEmail, newEmail);
}
public void process() {
try {
String playerName = player.getName().toLowerCase();
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.authmePermissible(player, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
m.send(player, "max_reg");
return;
}
}
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
if (!newEmail.equals(newEmailVerify)) {
m.send(player, "email_confirm");
return;
}
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
if (oldEmail != null) {
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
m.send(player, "usage_email_add");
return;
}
if (!oldEmail.equals(auth.getEmail())) {
m.send(player, "old_email_invalid");
return;
}
}
if (!Settings.isEmailCorrect(newEmail)) {
m.send(player, "new_email_invalid");
return;
}
String old = auth.getEmail();
auth.setEmail(newEmail);
if (!plugin.database.updateEmail(auth)) {
m.send(player, "error");
auth.setEmail(old);
return;
}
PlayerCache.getInstance().updatePlayer(auth);
m.send(player, "email_changed");
player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail());
}
} catch (Exception e) {
ConsoleLogger.showError(e.getMessage());
ConsoleLogger.writeStackTrace(e);
m.send(player, "error");
}
}
}