Implemented the setmail command

This commit is contained in:
Tim Visée
2015-11-01 18:06:09 +01:00
parent 19f4af3e85
commit bc0f1b4bb9
2 changed files with 80 additions and 1 deletions
@@ -0,0 +1,63 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
public class SetEmailCommand extends ExecutableCommand {
/**
* Execute the command.
*
* @param sender The command sender.
* @param commandReference The command reference.
* @param commandArguments The command arguments.
*
* @return True if the command was executed successfully, false otherwise.
*/
@Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance
AuthMe plugin = AuthMe.getInstance();
// Messages instance
Messages m = Messages.getInstance();
// Get the player name and email address
String playerName = commandArguments.get(0);
String playerEmail = commandArguments.get(1);
// Validate the email address
if (!Settings.isEmailCorrect(playerEmail)) {
m.send(sender, "email_invalid");
return true;
}
// Validate the user
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
if (auth == null) {
m.send(sender, "unknown_user");
return true;
}
// Set the email address
auth.setEmail(playerEmail);
if (!plugin.database.updateEmail(auth)) {
m.send(sender, "error");
return true;
}
// Update the player cache
if (PlayerCache.getInstance().getAuth(playerName.toLowerCase()) != null)
PlayerCache.getInstance().updatePlayer(auth);
// Show a status message
m.send(sender, "email_changed");
return true;
}
}