diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index d2185491..29e98333 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -15,6 +15,7 @@ import fr.xephi.authme.process.register.executors.PasswordRegisterParams; import fr.xephi.authme.process.register.executors.RegistrationMethod; import fr.xephi.authme.process.register.executors.TwoFactorRegisterParams; import fr.xephi.authme.security.HashAlgorithm; +import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.settings.properties.EmailSettings; @@ -24,8 +25,6 @@ import org.bukkit.entity.Player; import javax.inject.Inject; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; import static fr.xephi.authme.process.register.RegisterSecondaryArgument.CONFIRMATION; import static fr.xephi.authme.process.register.RegisterSecondaryArgument.EMAIL_MANDATORY; @@ -46,6 +45,9 @@ public class RegisterCommand extends PlayerCommand { @Inject private CommonService commonService; + @Inject + private BukkitService bukkitService; + @Inject private DataSource dataSource; @@ -175,20 +177,15 @@ public class RegisterCommand extends PlayerCommand { } else if (isSecondArgValidForEmailRegistration(player, arguments)) { management.performRegister(RegistrationMethod.EMAIL_REGISTRATION, EmailRegisterParams.of(player, email)); - Timer timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { + if (commonService.getProperty(RegistrationSettings.UNREGISTER_ON_EMAIL_VERIFICATION_FAILURE) && commonService.getProperty(RegistrationSettings.UNREGISTER_AFTER_MINUTES) > 0) { + bukkitService.runTaskLater(player, () -> { if (dataSource.getAuth(player.getName()) != null) { if (dataSource.getAuth(player.getName()).getLastLogin() == null) { management.performUnregisterByAdmin(null, player.getName(), player); - timer.cancel(); } - } else { - timer.cancel(); } - } - }, 600000); + }, 60 * 20 * commonService.getProperty(RegistrationSettings.UNREGISTER_AFTER_MINUTES)); + } } } diff --git a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java index ccf83cda..b15132d5 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java @@ -46,6 +46,16 @@ public final class RegistrationSettings implements SettingsHolder { newProperty(RegisterSecondaryArgument.class, "settings.registration.secondArg", RegisterSecondaryArgument.CONFIRMATION); + @Comment({ + "Should we unregister the player when he didn't verify the email?", + "This only works if you enabled email registration."}) + public static final Property UNREGISTER_ON_EMAIL_VERIFICATION_FAILURE = + newProperty("settings.registration.email.unregisterOnEmailVerificationFailure", false); + + @Comment({"How many minutes should we wait before unregister the player", + "when he didn't verify the email?"}) + public static final Property UNREGISTER_AFTER_MINUTES = + newProperty("settings.registration.email.unregisterAfterMinutes", 10L); @Comment({ "Do we force kick a player after a successful registration?", "Do not use with login feature below"})