TotalFreedomMod/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java

60 lines
2.1 KiB
Java
Raw Normal View History

2017-12-29 18:12:47 +00:00
package me.totalfreedom.totalfreedommod.command;
2023-04-10 06:18:06 +00:00
import me.totalfreedom.totalfreedommod.command.handling.*;
2020-06-30 07:25:38 +00:00
import me.totalfreedom.totalfreedommod.player.PlayerData;
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;
@CommandDependencies({"TFD4J"})
2023-03-30 03:00:35 +00:00
@CommandPermissions(permission = "linkdiscord", 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 == null || !plugin.dc.isEnabled())
2017-12-29 18:12:47 +00:00
{
msg("The Discord integration system is currently disabled.", ChatColor.RED);
2017-12-29 18:12:47 +00:00
return true;
}
if (args.length > 1 && plugin.al.isAdmin(playerSender))
{
2020-06-30 07:25:38 +00:00
PlayerData playerData = plugin.pl.getData(args[0]);
if (playerData == null)
{
2020-06-30 07:25:38 +00:00
msg(PLAYER_NOT_FOUND);
return true;
}
2020-06-30 07:25:38 +00:00
playerData.setDiscordID(args[1]);
msg("Linked " + args[0] + "'s Discord account.", ChatColor.GREEN);
2020-06-30 07:25:38 +00:00
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
if (plugin.dc.getLinkCodes().containsValue(data))
2020-06-30 07:25:38 +00:00
{
code = plugin.dc.getCode(data);
} else
2017-12-29 18:12:47 +00:00
{
code = plugin.dc.generateCode(5);
plugin.dc.getLinkCodes().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;
}
}