Implemented the setmail command
This commit is contained in:
parent
19f4af3e85
commit
bc0f1b4bb9
@ -166,7 +166,7 @@ public class CommandManager {
|
|||||||
|
|
||||||
// Register the getemail command
|
// Register the getemail command
|
||||||
CommandDescription getEmailCommand = new CommandDescription(
|
CommandDescription getEmailCommand = new CommandDescription(
|
||||||
new RegisterCommand(),
|
new GetEmailCommand(),
|
||||||
new ArrayList<String>() {{
|
new ArrayList<String>() {{
|
||||||
add("getemail");
|
add("getemail");
|
||||||
add("getmail");
|
add("getmail");
|
||||||
@ -179,6 +179,22 @@ public class CommandManager {
|
|||||||
getEmailCommand.setCommandPermissions("authme.admin.getemail", CommandPermissions.DefaultPermission.OP_ONLY);
|
getEmailCommand.setCommandPermissions("authme.admin.getemail", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
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
|
// Register the purge command
|
||||||
CommandDescription purgeCommand = new CommandDescription(
|
CommandDescription purgeCommand = new CommandDescription(
|
||||||
new PurgeCommand(),
|
new PurgeCommand(),
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user