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

101 lines
3.8 KiB
Java
Raw Normal View History

2017-12-29 18:12:47 +00:00
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.discord.Discord;
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)
@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
{
2020-08-15 16:35:48 +00:00
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-12-15 00:05:13 +00:00
boolean verificationEnabled = ConfigEntry.DISCORD_VERIFICATION.getBoolean();
2020-06-30 07:25:38 +00:00
if (!plugin.dc.enabled)
{
2020-12-15 00:05:13 +00:00
msg("The Discord verification system is currently disabled.", ChatColor.RED);
return true;
}
2020-12-15 00:05:13 +00:00
if (!verificationEnabled)
{
2020-12-15 00:05:13 +00:00
msg("The Discord verification system is currently disabled.", ChatColor.RED);
return true;
}
2020-12-15 00:05:13 +00:00
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
if (!plugin.pl.IsImpostor(playerSender))
2020-06-30 07:25:38 +00:00
{
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-09-14 09:36:25 +00:00
plugin.dc.getUser(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;
if (plugin.pl.IsImpostor(playerSender))
2020-06-30 07:25:38 +00:00
{
PlayerData mapPlayer = plugin.dc.getVerificationCodes().get(code);
if (mapPlayer == null)
2020-01-25 06:27:16 +00:00
{
if (!playerData.getBackupCodes().contains(Discord.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
{
backupCode = Discord.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;
}
2020-12-15 00:05:13 +00:00
}