2018-03-24 15:41:45 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
2020-01-10 04:50:45 +00:00
|
|
|
import java.util.ArrayList;
|
2019-01-29 04:57:41 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2020-06-30 07:25:38 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
2018-03-24 15:41:45 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2020-07-01 01:51:06 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2018-03-24 15:41:45 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2020-06-30 07:25:38 +00:00
|
|
|
@CommandParameters(description = "Manage your verification", usage = "/<command> <enable | disable | clearips | clearip <ip> | status | genbackupcodes>", aliases = "playerverify,pv")
|
|
|
|
public class Command_playerverification extends FreedomCommand
|
2018-03-25 01:41:51 +00:00
|
|
|
{
|
2018-03-24 15:41:45 +00:00
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2018-03-25 01:41:51 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
PlayerData target = plugin.pl.getData(playerSender);
|
2018-03-26 00:12:47 +00:00
|
|
|
|
2020-01-10 04:50:45 +00:00
|
|
|
List<String> ips = new ArrayList<>();
|
|
|
|
ips.addAll(target.getIps());
|
|
|
|
|
2018-03-26 00:12:47 +00:00
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
if (args[0].equalsIgnoreCase("clearips"))
|
|
|
|
{
|
|
|
|
int cleared = 0;
|
2020-01-10 04:50:45 +00:00
|
|
|
for (String ip : ips)
|
2018-03-26 00:12:47 +00:00
|
|
|
{
|
2020-07-01 01:51:06 +00:00
|
|
|
if (!ip.equals(FUtil.getIp(playerSender)))
|
2018-03-26 00:12:47 +00:00
|
|
|
{
|
2018-07-30 07:23:01 +00:00
|
|
|
target.removeIp(ip);
|
2018-03-26 00:12:47 +00:00
|
|
|
cleared++;
|
|
|
|
}
|
|
|
|
}
|
2018-06-01 14:13:40 +00:00
|
|
|
|
2020-07-01 01:51:06 +00:00
|
|
|
msg("Cleared all IP's except your current IP \"" + FUtil.getIp(playerSender) + "\"");
|
2018-03-26 00:12:47 +00:00
|
|
|
msg("Cleared " + cleared + " IP's.");
|
2020-06-30 07:25:38 +00:00
|
|
|
plugin.pl.save(target);
|
|
|
|
plugin.pl.syncIps(target);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("clearip"))
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
target.removeIp(args[1]);
|
|
|
|
msg("Removed" + args[1] + " from your list of IPs");
|
|
|
|
plugin.pl.save(target);
|
|
|
|
plugin.pl.syncIps(target);
|
2018-03-26 00:12:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 07:23:01 +00:00
|
|
|
if (args.length < 1)
|
2018-03-25 01:41:51 +00:00
|
|
|
{
|
2018-03-24 15:41:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-26 00:12:47 +00:00
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
PlayerData data = plugin.pl.getData(playerSender);
|
2018-07-30 07:23:01 +00:00
|
|
|
|
2018-03-25 01:41:51 +00:00
|
|
|
switch (args[0].toLowerCase())
|
|
|
|
{
|
2018-03-24 15:41:45 +00:00
|
|
|
case "enable":
|
2020-12-04 00:28:53 +00:00
|
|
|
{
|
2018-07-31 05:58:50 +00:00
|
|
|
if (!plugin.dc.enabled)
|
2018-03-25 01:41:51 +00:00
|
|
|
{
|
2018-07-31 05:58:50 +00:00
|
|
|
msg("The Discord verification system is currently disabled.", ChatColor.RED);
|
|
|
|
return true;
|
2018-03-24 15:41:45 +00:00
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
else if (data.hasVerification())
|
2018-03-25 01:41:51 +00:00
|
|
|
{
|
2018-07-31 05:58:50 +00:00
|
|
|
msg("Discord verification is already enabled for you.", ChatColor.RED);
|
|
|
|
return true;
|
2018-03-24 15:41:45 +00:00
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
else if (data.getDiscordID() == null)
|
2018-07-31 08:03:12 +00:00
|
|
|
{
|
2020-01-25 06:27:16 +00:00
|
|
|
msg("Please link a discord account with /linkdiscord.", ChatColor.RED);
|
|
|
|
return true;
|
2018-07-31 08:03:12 +00:00
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
data.setVerification(true);
|
|
|
|
plugin.pl.save(data);
|
2020-01-25 06:27:16 +00:00
|
|
|
msg("Re-enabled Discord verification.", ChatColor.GREEN);
|
2018-07-31 05:58:50 +00:00
|
|
|
return true;
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|
2018-07-30 07:23:01 +00:00
|
|
|
|
2018-07-31 05:58:50 +00:00
|
|
|
case "disable":
|
2020-12-04 00:28:53 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
if (!data.hasVerification())
|
2018-03-25 01:41:51 +00:00
|
|
|
{
|
2018-07-31 05:58:50 +00:00
|
|
|
msg("Discord verification is already disabled for you.", ChatColor.RED);
|
|
|
|
return true;
|
2018-03-24 15:41:45 +00:00
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
data.setVerification(false);
|
|
|
|
plugin.pl.save(data);
|
2018-07-31 05:58:50 +00:00
|
|
|
msg("Disabled Discord verification.", ChatColor.GREEN);
|
2018-07-30 07:23:01 +00:00
|
|
|
return true;
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|
2018-07-30 07:23:01 +00:00
|
|
|
|
2018-07-31 05:58:50 +00:00
|
|
|
case "status":
|
2020-12-04 00:28:53 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
boolean enabled = target.hasVerification();
|
|
|
|
boolean specified = target.getDiscordID() != null;
|
2018-07-31 05:58:50 +00:00
|
|
|
msg(ChatColor.GRAY + "Discord Verification Enabled: " + (enabled ? ChatColor.GREEN + "true" : ChatColor.RED + "false"));
|
2020-06-30 07:25:38 +00:00
|
|
|
msg(ChatColor.GRAY + "Discord ID: " + (specified ? ChatColor.GREEN + target.getDiscordID() : ChatColor.RED + "not set"));
|
2020-01-25 06:27:16 +00:00
|
|
|
msg(ChatColor.GRAY + "Backup Codes: " + data.getBackupCodes().size() + "/" + "10");
|
|
|
|
return true;
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|
2020-01-25 06:27:16 +00:00
|
|
|
|
|
|
|
case "genbackupcodes":
|
2020-12-04 00:28:53 +00:00
|
|
|
{
|
2020-01-25 06:27:16 +00:00
|
|
|
if (!plugin.dc.enabled)
|
|
|
|
{
|
|
|
|
msg("The Discord verification system is currently disabled.", ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
else if (!data.hasVerification())
|
2020-01-25 06:27:16 +00:00
|
|
|
{
|
|
|
|
msg("Discord verification is not enabled for you.", ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean generated = plugin.dc.sendBackupCodes(data);
|
|
|
|
|
|
|
|
if (generated)
|
|
|
|
{
|
|
|
|
msg("Your backup codes have been sent to your discord account. They can be re-generated at anytime.", ChatColor.GREEN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg("Failed to generate backup codes, please contact a developer (preferably Seth)", ChatColor.RED);
|
|
|
|
}
|
2018-07-31 05:58:50 +00:00
|
|
|
return true;
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|
2018-03-24 15:41:45 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
|
2019-01-29 04:57:41 +00:00
|
|
|
@Override
|
|
|
|
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
|
|
|
{
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
2020-01-25 06:27:16 +00:00
|
|
|
return Arrays.asList("enable", "disable", "status", "clearips", "genbackupcodes");
|
2019-01-29 04:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|