#347 Add NewSetting to command service

- Adjust NewSetting constructor to match needs in AuthMe
- Add NewSetting to the command service
- See CaptchaCommand for a sample replacement from Settings to NewSetting
This commit is contained in:
ljacqu
2016-01-09 12:45:58 +01:00
parent 88629702f5
commit 3845c1e0eb
12 changed files with 107 additions and 60 deletions
@@ -2,6 +2,8 @@ package fr.xephi.authme.command;
import java.util.List;
import fr.xephi.authme.settings.custom.NewSetting;
import fr.xephi.authme.settings.domain.Property;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe;
@@ -24,6 +26,7 @@ public class CommandService {
private final HelpProvider helpProvider;
private final CommandMapper commandMapper;
private final PasswordSecurity passwordSecurity;
private final NewSetting settings;
/**
* Constructor.
@@ -35,12 +38,13 @@ public class CommandService {
* @param passwordSecurity The Password Security instance
*/
public CommandService(AuthMe authMe, CommandMapper commandMapper, HelpProvider helpProvider, Messages messages,
PasswordSecurity passwordSecurity) {
PasswordSecurity passwordSecurity, NewSetting settings) {
this.authMe = authMe;
this.messages = messages;
this.helpProvider = helpProvider;
this.commandMapper = commandMapper;
this.passwordSecurity = passwordSecurity;
this.settings = settings;
}
/**
@@ -156,4 +160,15 @@ public class CommandService {
return messages.retrieve(key);
}
/**
* Retrieve the given property's value.
*
* @param property The property to retrieve
* @param <T> The type of the property
* @return The property's value
*/
public <T> T getProperty(Property<T> property) {
return settings.getProperty(property);
}
}
@@ -6,7 +6,7 @@ import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.custom.SecuritySettings;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.entity.Player;
@@ -28,20 +28,20 @@ public class CaptchaCommand extends PlayerCommand {
return;
}
if (!Settings.useCaptcha) {
if (!commandService.getProperty(SecuritySettings.USE_CAPTCHA)) {
commandService.send(player, MessageKey.USAGE_LOGIN);
return;
}
if (!plugin.cap.containsKey(playerNameLowerCase)) {
commandService.send(player, MessageKey.USAGE_LOGIN);
return;
}
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
if (!captcha.equals(plugin.cap.get(playerNameLowerCase))) {
plugin.cap.remove(playerNameLowerCase);
String randStr = RandomString.generate(Settings.captchaLength);
int captchaLength = commandService.getProperty(SecuritySettings.CAPTCHA_LENGTH);
String randStr = RandomString.generate(captchaLength);
plugin.cap.put(playerNameLowerCase, randStr);
commandService.send(player, MessageKey.CAPTCHA_WRONG_ERROR, plugin.cap.get(playerNameLowerCase));
return;
@@ -43,6 +43,6 @@ public class RegisterCommand extends PlayerCommand {
@Override
public String getAlternativeCommand() {
return "authme register <playername> <password>";
return "/authme register <playername> <password>";
}
}