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

View File

@ -166,7 +166,7 @@ public class CommandManager {
// Register the getemail command
CommandDescription getEmailCommand = new CommandDescription(
new RegisterCommand(),
new GetEmailCommand(),
new ArrayList<String>() {{
add("getemail");
add("getmail");
@ -179,6 +179,22 @@ public class CommandManager {
getEmailCommand.setCommandPermissions("authme.admin.getemail", CommandPermissions.DefaultPermission.OP_ONLY);
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
// Register the setemail command
CommandDescription setEmailCommand = new CommandDescription(
new SetEmailCommand(),
new ArrayList<String>() {{
add("chgemail");
add("chgmail");
add("setemail");
add("setmail");
}},
"Change player's email",
"Change the email address of the specified player.",
authMeCommand);
setEmailCommand.setCommandPermissions("authme.admin.chgemail", CommandPermissions.DefaultPermission.OP_ONLY);
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
// Register the purge command
CommandDescription purgeCommand = new CommandDescription(
new PurgeCommand(),

View File

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