2017-12-29 18:12:47 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
2018-03-24 15:41:45 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.discord.Discord;
|
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;
|
|
|
|
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;
|
2018-03-24 15:41:45 +00:00
|
|
|
|
2019-11-03 21:40:05 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2020-06-30 07:25:38 +00:00
|
|
|
@CommandParameters(description = "Link your Discord account to your Minecraft account", usage = "/<command> [<name> <id>]")
|
2017-12-29 18:12:47 +00:00
|
|
|
public class Command_linkdiscord extends FreedomCommand
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
if (!plugin.dc.enabled)
|
|
|
|
{
|
2018-07-30 07:23:01 +00:00
|
|
|
msg("The Discord verification system is currently disabled.", ChatColor.RED);
|
2017-12-29 18:12:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-03-24 15:41:45 +00:00
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
if (args.length > 1 && plugin.sl.isStaff(playerSender))
|
2018-06-01 14:13:40 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
PlayerData playerData = plugin.pl.getData(args[0]);
|
|
|
|
if (playerData == null)
|
2018-06-01 14:13:40 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
msg(PLAYER_NOT_FOUND);
|
2018-03-24 15:41:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
playerData.setDiscordID(args[1]);
|
|
|
|
msg("Linked " + args[0] + "'s discord account.", ChatColor.GREEN);
|
|
|
|
return true;
|
2020-01-25 06:27:16 +00:00
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
|
|
|
|
String code;
|
|
|
|
|
|
|
|
PlayerData data = plugin.pl.getData(playerSender);
|
|
|
|
if (data.getDiscordID() != null)
|
2020-01-25 06:27:16 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
msg("Your Minecraft account is already linked to a Discord account.", ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-25 06:27:16 +00:00
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
if (Discord.LINK_CODES.containsValue(data))
|
|
|
|
{
|
2020-08-01 04:10:44 +00:00
|
|
|
code = plugin.dc.getCode(data);
|
2017-12-29 18:12:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
code = plugin.dc.generateCode(5);
|
|
|
|
Discord.LINK_CODES.put(code, data);
|
2017-12-29 18:12:47 +00:00
|
|
|
}
|
2020-01-25 06:27:16 +00:00
|
|
|
msg("Your linking code is " + ChatColor.AQUA + code, ChatColor.GREEN);
|
|
|
|
msg("Take this code and DM the server bot (" + plugin.dc.formatBotTag() + ") the code (do not put anything else in the message, only the code)");
|
2017-12-29 18:12:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|