TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java

93 lines
3.5 KiB
Java
Raw Normal View History

2017-12-29 18:12:47 +00:00
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.FPlayer;
2020-06-30 07:25:38 +00:00
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
2017-12-29 18:12:47 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.BOTH)
2018-08-01 07:08:06 +00:00
@CommandParameters(description = "Sends a verification code to the player, or the player can input the sent code. Admins can manually verify a player impostor.", usage = "/<command> <code | <playername>>")
public class Command_verify extends FreedomCommand
{
2017-12-29 18:12:47 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
2020-06-30 07:25:38 +00:00
if (!plugin.dc.enabled)
{
2020-06-30 07:25:38 +00:00
msg("The Discord verification system is currently disabled", ChatColor.RED);
return true;
}
2020-06-30 07:25:38 +00:00
if (senderIsConsole)
{
2020-06-30 07:25:38 +00:00
msg("/manuallyverify <playername>", ChatColor.WHITE);
return true;
}
2019-11-27 05:39:30 +00:00
2020-06-30 07:25:38 +00:00
if (!plugin.pl.isImposter(playerSender))
{
msg("You are not an impostor, therefore you do not need to verify.", ChatColor.RED);
return true;
}
2018-08-01 07:08:06 +00:00
2020-06-30 07:25:38 +00:00
PlayerData playerData = plugin.pl.getData(playerSender);
String discordId = playerData.getDiscordID();
if (playerData.getDiscordID() == null)
{
msg("You do not have a Discord account linked to your Minecraft account, please verify the manual way.", ChatColor.RED);
return true;
}
if (args.length == 0)
{
String code = plugin.dc.generateCode(10);
plugin.dc.addVerificationCode(code, playerData);
2020-07-01 01:51:06 +00:00
plugin.dc.bot.getUserById(discordId).openPrivateChannel().complete().sendMessage("A user with the IP `" + FUtil.getIp(playerSender) + "` has sent a verification request. Please run the following in-game command: `/verify " + code + "`").complete();
2020-06-30 07:25:38 +00:00
msg("A verification code has been sent to your account, please copy the code and run /verify <code>", ChatColor.GREEN);
return true;
}
2020-06-30 07:25:38 +00:00
String code = args[0];
String backupCode = null;
2020-06-30 07:25:38 +00:00
if (plugin.pl.isImposter(playerSender))
{
PlayerData mapPlayer = plugin.dc.getVerificationCodes().get(code);
if (mapPlayer == null)
2020-01-25 06:27:16 +00:00
{
2020-06-30 07:25:38 +00:00
if (!playerData.getBackupCodes().contains(plugin.dc.getMD5(code)))
2020-01-25 06:27:16 +00:00
{
2020-06-30 07:25:38 +00:00
msg("You have entered an invalid verification code", ChatColor.RED);
2020-01-25 06:27:16 +00:00
return true;
}
2020-06-30 07:25:38 +00:00
else
{
2020-06-30 07:25:38 +00:00
backupCode = plugin.dc.getMD5(code);
}
}
2020-06-30 07:25:38 +00:00
else
{
2020-06-30 07:25:38 +00:00
plugin.dc.removeVerificationCode(code);
}
2020-06-30 07:25:38 +00:00
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
if (fPlayer.getFreezeData().isFrozen())
{
2020-06-30 07:25:38 +00:00
fPlayer.getFreezeData().setFrozen(false);
msg("You have been unfrozen.");
2017-12-29 18:12:47 +00:00
}
2020-06-30 07:25:38 +00:00
FUtil.bcastMsg(playerSender.getName() + " has verified!", ChatColor.GOLD);
playerSender.setOp(true);
plugin.pl.verify(playerSender, backupCode);
return true;
2017-12-29 18:12:47 +00:00
}
return true;
}
}