|
| 1 | +package me.joshb.discordbotapi.server.config.command; |
| 2 | + |
| 3 | +import me.joshb.discordbotapi.server.DiscordBotAPI; |
| 4 | +import me.joshb.discordbotapi.server.assets.Assets; |
| 5 | +import me.joshb.discordbotapi.server.assets.Permission; |
| 6 | +import me.joshb.discordbotapi.server.config.Config; |
| 7 | +import net.dv8tion.jda.api.entities.User; |
| 8 | +import org.bukkit.entity.Player; |
| 9 | + |
| 10 | +import java.util.List; |
| 11 | +import java.util.Random; |
| 12 | + |
| 13 | +public class CommandUnlink extends DiscordCommand { |
| 14 | + |
| 15 | + private final String command = Config.getInstance().getConfig().getString("Bot.Command-Prefix"); |
| 16 | + |
| 17 | + @Override |
| 18 | + public String command() { |
| 19 | + return "unlink"; |
| 20 | + } |
| 21 | + |
| 22 | + @Override |
| 23 | + public void onCommand(Player p, String[] args) { |
| 24 | + if(!p.hasPermission(Permission.GAME_DISCORD_UNLINK.getValue())){ |
| 25 | + p.sendMessage(Assets.format("Game.Discord.Commands.No-Permission")); |
| 26 | + return; |
| 27 | + } |
| 28 | + if(DiscordBotAPI.getAccountManager().getDiscordID(p.getUniqueId()) == null){ |
| 29 | + //Not linked |
| 30 | + List<String> notLinked = Assets.formatStringList("Game.Commands.Discord.Sub-Commands.Unlink.Not-Linked"); |
| 31 | + for(String s : notLinked){ |
| 32 | + p.sendMessage(s |
| 33 | + .replaceAll("%player%", p.getName()) |
| 34 | + .replaceAll("%discord_bot_name%", DiscordBotAPI.getJDA().getSelfUser().getName())); |
| 35 | + } |
| 36 | + } else { |
| 37 | + //Linked |
| 38 | + User u = DiscordBotAPI.getJDA().getUserById(DiscordBotAPI.getAccountManager().getDiscordID(p.getUniqueId())); |
| 39 | + List<String> linked = Assets.formatStringList("Game.Commands.Discord.Sub-Commands.Unlink.Linked"); |
| 40 | + for(String s : linked){ |
| 41 | + p.sendMessage(s |
| 42 | + .replaceAll("%player%", p.getName()) |
| 43 | + .replaceAll("%discord_bot_name%", DiscordBotAPI.getJDA().getSelfUser().getName()) |
| 44 | + .replaceAll("%discord_author_name%", u.getName()) |
| 45 | + .replaceAll("%discord_author_discriminator%", u.getDiscriminator())); |
| 46 | + } |
| 47 | + DiscordBotAPI.getAccountManager().unlinkAccount(p.getUniqueId()); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments