54 lines
1.4 KiB
Java
54 lines
1.4 KiB
Java
package eu.oskar3123.spigot2fa.command;
|
|
|
|
import eu.oskar3123.spigot2fa.Main;
|
|
import eu.oskar3123.spigot2fa.handler.TFAHandler;
|
|
import eu.oskar3123.spigot2fa.tfa.TFA;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
public class TFACommand implements CommandExecutor
|
|
{
|
|
|
|
private Main plugin;
|
|
private TFAHandler th;
|
|
|
|
public TFACommand(Main plugin)
|
|
{
|
|
this.plugin = plugin;
|
|
this.th = plugin.tfaHandler;
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
|
{
|
|
Player player = (Player) sender;
|
|
if (!th.isInProcess(player.getUniqueId()))
|
|
{
|
|
th.startCreating(player);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
String secret = th.getKey(player.getUniqueId());
|
|
String code = TFA.getTOTPCode(secret);
|
|
String pCode = StringUtils.join(args);
|
|
if (th.matchCode(code, pCode))
|
|
{
|
|
th.creatingSuccess(player);
|
|
player.sendMessage("Successfully activated 2FA");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
th.creatingFailed(player);
|
|
player.sendMessage("That code is incorrect, aborting");
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|