mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 18:55:11 +01:00
Implemented the email add command
This commit is contained in:
parent
7f63056cc9
commit
4c536a5204
@ -352,7 +352,7 @@ public class AuthMe extends JavaPlugin {
|
||||
//getCommand("changepassword").setExecutor(new ChangePasswordCommand(this));
|
||||
//getCommand("logout").setExecutor(new LogoutCommand(this));
|
||||
//getCommand("unregister").setExecutor(new UnregisterCommand(this));
|
||||
getCommand("email").setExecutor(new EmailCommand(this));
|
||||
//getCommand("email").setExecutor(new EmailCommand(this));
|
||||
getCommand("captcha").setExecutor(new CaptchaCommand(this));
|
||||
getCommand("converter").setExecutor(new ConverterCommand(this));
|
||||
|
||||
|
@ -3,6 +3,7 @@ package fr.xephi.authme.command;
|
||||
import fr.xephi.authme.command.executable.*;
|
||||
import fr.xephi.authme.command.executable.authme.*;
|
||||
import fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand;
|
||||
import fr.xephi.authme.command.executable.email.AddEmailCommand;
|
||||
import fr.xephi.authme.command.executable.login.LoginCommand;
|
||||
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
||||
|
||||
@ -31,7 +32,7 @@ public class CommandManager {
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public void registerCommands() {
|
||||
// Register the base Dungeon Maze command
|
||||
// Register the base AuthMe Reloaded command
|
||||
CommandDescription authMeBaseCommand = new CommandDescription(
|
||||
new AuthMeCommand(),
|
||||
new ArrayList<String>() {{
|
||||
@ -378,7 +379,7 @@ public class CommandManager {
|
||||
add("?");
|
||||
}},
|
||||
"View help",
|
||||
"View detailed help pages about AuthMeReloaded register commands.",
|
||||
"View detailed help pages about AuthMeReloaded logout commands.",
|
||||
logoutBaseCommand);
|
||||
logoutHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||
logoutHelpCommand.setMaximumArguments(false);
|
||||
@ -437,7 +438,7 @@ public class CommandManager {
|
||||
add("?");
|
||||
}},
|
||||
"View help",
|
||||
"View detailed help pages about AuthMeReloaded register commands.",
|
||||
"View detailed help pages about AuthMeReloaded unregister commands.",
|
||||
unregisterBaseCommand);
|
||||
unregisterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||
unregisterHelpCommand.setMaximumArguments(false);
|
||||
@ -467,11 +468,51 @@ public class CommandManager {
|
||||
add("?");
|
||||
}},
|
||||
"View help",
|
||||
"View detailed help pages about AuthMeReloaded register commands.",
|
||||
"View detailed help pages about AuthMeReloaded change password commands.",
|
||||
changePasswordBaseCommand);
|
||||
changePasswordHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||
changePasswordHelpCommand.setMaximumArguments(false);
|
||||
|
||||
// Register the base Dungeon Maze command
|
||||
CommandDescription emailBaseCommand = new CommandDescription(
|
||||
new HelpCommand(),
|
||||
new ArrayList<String>() {{
|
||||
add("email");
|
||||
add("mail");
|
||||
}},
|
||||
"E-mail command",
|
||||
"The AuthMe Reloaded E-mail command. The root for all E-mail commands.", null);
|
||||
|
||||
// Register the help command
|
||||
CommandDescription addEmailCommand = new CommandDescription(
|
||||
new AddEmailCommand(),
|
||||
new ArrayList<String>() {{
|
||||
add("add");
|
||||
add("addemail");
|
||||
add("addmail");
|
||||
}},
|
||||
"Add E-mail",
|
||||
"Add a new E-Mail address to your account.",
|
||||
emailBaseCommand);
|
||||
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
|
||||
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
|
||||
|
||||
// Register the help command
|
||||
CommandDescription emailHelpCommand = new CommandDescription(
|
||||
new HelpCommand(),
|
||||
new ArrayList<String>() {{
|
||||
add("help");
|
||||
add("hlp");
|
||||
add("h");
|
||||
add("sos");
|
||||
add("?");
|
||||
}},
|
||||
"View help",
|
||||
"View detailed help pages about AuthMeReloaded help commands.",
|
||||
emailBaseCommand);
|
||||
emailHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||
emailHelpCommand.setMaximumArguments(false);
|
||||
|
||||
// Add the base commands to the commands array
|
||||
this.commandDescriptions.add(authMeBaseCommand);
|
||||
this.commandDescriptions.add(loginBaseCommand);
|
||||
@ -479,6 +520,7 @@ public class CommandManager {
|
||||
this.commandDescriptions.add(registerBaseCommand);
|
||||
this.commandDescriptions.add(unregisterBaseCommand);
|
||||
this.commandDescriptions.add(changePasswordBaseCommand);
|
||||
this.commandDescriptions.add(emailBaseCommand);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,90 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
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;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AddEmailCommand 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
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = Messages.getInstance();
|
||||
|
||||
// Get the parameter values
|
||||
String playerMail = commandArguments.get(0);
|
||||
String playerMailVerify = commandArguments.get(1);
|
||||
|
||||
// Make sure the current command executor is a player
|
||||
if(!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the player instance and name
|
||||
final Player player = (Player) sender;
|
||||
final String playerName = player.getName();
|
||||
|
||||
// Command logic
|
||||
if (Settings.getmaxRegPerEmail > 0) {
|
||||
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(playerMail).size() >= Settings.getmaxRegPerEmail) {
|
||||
m.send(player, "max_reg");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerMail.equals(playerMailVerify) && PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
|
||||
|
||||
if (auth.getEmail() == null || (!auth.getEmail().equals("your@email.com") && !auth.getEmail().isEmpty())) {
|
||||
m.send(player, "usage_email_change");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Settings.isEmailCorrect(playerMail)) {
|
||||
m.send(player, "email_invalid");
|
||||
return true;
|
||||
}
|
||||
|
||||
auth.setEmail(playerMail);
|
||||
|
||||
if (!plugin.database.updateEmail(auth)) {
|
||||
m.send(player, "error");
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
m.send(player, "email_added");
|
||||
player.sendMessage(auth.getEmail());
|
||||
|
||||
} else if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||
m.send(player, "email_confirm");
|
||||
|
||||
} else {
|
||||
if (!plugin.database.isAuthAvailable(playerName)) {
|
||||
m.send(player, "login_msg");
|
||||
} else {
|
||||
m.send(player, "reg_email_msg");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user