reordering local variable scope in captcha command
This commit is contained in:
parent
d7f9b602c7
commit
b4b92e5a93
@ -25,18 +25,6 @@ public class CaptchaCommand extends ExecutableCommand {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Messages instance
|
|
||||||
final Messages m = Messages.getInstance();
|
|
||||||
|
|
||||||
// Random string instance, for captcha generation (I think) -- timvisee
|
|
||||||
RandomString randStr = new RandomString(Settings.captchaLength);
|
|
||||||
|
|
||||||
// Get the parameter values
|
|
||||||
String captcha = commandArguments.get(0);
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
@ -46,6 +34,12 @@ public class CaptchaCommand extends ExecutableCommand {
|
|||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String captcha = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||||
m.send(player, "logged_in");
|
m.send(player, "logged_in");
|
||||||
@ -57,6 +51,9 @@ public class CaptchaCommand extends ExecutableCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
||||||
m.send(player, "usage_log");
|
m.send(player, "usage_log");
|
||||||
return true;
|
return true;
|
||||||
@ -64,18 +61,16 @@ public class CaptchaCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
||||||
plugin.cap.remove(playerNameLowerCase);
|
plugin.cap.remove(playerNameLowerCase);
|
||||||
plugin.cap.put(playerNameLowerCase, randStr.nextString());
|
String randStr = new RandomString(Settings.captchaLength).nextString();
|
||||||
|
plugin.cap.put(playerNameLowerCase, randStr);
|
||||||
for (String s : m.send("wrong_captcha")) {
|
for (String s : m.send("wrong_captcha")) {
|
||||||
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
plugin.captcha.remove(playerNameLowerCase);
|
||||||
plugin.captcha.remove(playerNameLowerCase);
|
plugin.cap.remove(playerNameLowerCase);
|
||||||
plugin.cap.remove(playerNameLowerCase);
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show a status message
|
// Show a status message
|
||||||
m.send(player, "valid_captcha");
|
m.send(player, "valid_captcha");
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||||||
*/
|
*/
|
||||||
public class Management {
|
public class Management {
|
||||||
|
|
||||||
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final BukkitScheduler sched;
|
private final BukkitScheduler sched;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user