diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manuallyverify.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manuallyverify.java index f4983fd1..0c88622e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manuallyverify.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manuallyverify.java @@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -14,13 +15,17 @@ public class Command_manuallyverify extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - + boolean enableBot = (ConfigEntry.DISCORD_VERIFICATION.getBoolean()); if (!plugin.dc.enabled) { msg("The Discord verification system is currently disabled", ChatColor.RED); return true; } - + if (!enableBot) + { + msg("The Discord verification system is currently disabled", ChatColor.RED); + return true; + } if (args.length == 0) { return false; @@ -54,4 +59,4 @@ public class Command_manuallyverify extends FreedomCommand return true; } -} \ No newline at end of file +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java index 89a62a28..ea1a3926 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -20,127 +21,135 @@ public class Command_playerverification extends FreedomCommand public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { PlayerData target = plugin.pl.getData(playerSender); - + boolean enableBot = (ConfigEntry.DISCORD_VERIFICATION.getBoolean()); List ips = new ArrayList<>(); ips.addAll(target.getIps()); - if (args.length == 1) + if(enableBot) { - if (args[0].equalsIgnoreCase("clearips")) + if (args.length == 1) { - int cleared = 0; - for (String ip : ips) + if (args[0].equalsIgnoreCase("clearips")) { - if (!ip.equals(FUtil.getIp(playerSender))) + int cleared = 0; + for (String ip : ips) { - target.removeIp(ip); - cleared++; + if (!ip.equals(FUtil.getIp(playerSender))) + { + target.removeIp(ip); + cleared++; + } } - } - msg("Cleared all IP's except your current IP \"" + FUtil.getIp(playerSender) + "\""); - msg("Cleared " + cleared + " IP's."); - plugin.pl.save(target); - plugin.pl.syncIps(target); - return true; + msg("Cleared all IP's except your current IP \"" + FUtil.getIp(playerSender) + "\""); + msg("Cleared " + cleared + " IP's."); + 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); + return true; + } } - else if (args[0].equalsIgnoreCase("clearip")) + + if (args.length < 1) { - 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); - return true; - } - } - - if (args.length < 1) - { - return false; - } - - PlayerData data = plugin.pl.getData(playerSender); - - switch (args[0].toLowerCase()) - { - case "enable": - { - if (!plugin.dc.enabled) - { - msg("The Discord verification system is currently disabled.", ChatColor.RED); - return true; - } - else if (data.hasVerification()) - { - msg("Discord verification is already enabled for you.", ChatColor.RED); - return true; - } - else if (data.getDiscordID() == null) - { - msg("Please link a discord account with /linkdiscord.", ChatColor.RED); - return true; - } - data.setVerification(true); - plugin.pl.save(data); - msg("Re-enabled Discord verification.", ChatColor.GREEN); - return true; - } - - case "disable": - { - if (!data.hasVerification()) - { - msg("Discord verification is already disabled for you.", ChatColor.RED); - return true; - } - data.setVerification(false); - plugin.pl.save(data); - msg("Disabled Discord verification.", ChatColor.GREEN); - return true; - } - - case "status": - { - boolean enabled = target.hasVerification(); - boolean specified = target.getDiscordID() != null; - msg(ChatColor.GRAY + "Discord Verification Enabled: " + (enabled ? ChatColor.GREEN + "true" : ChatColor.RED + "false")); - msg(ChatColor.GRAY + "Discord ID: " + (specified ? ChatColor.GREEN + target.getDiscordID() : ChatColor.RED + "not set")); - msg(ChatColor.GRAY + "Backup Codes: " + data.getBackupCodes().size() + "/" + "10"); - return true; - } - - case "genbackupcodes": - { - if (!plugin.dc.enabled) - { - msg("The Discord verification system is currently disabled.", ChatColor.RED); - return true; - } - else if (!data.hasVerification()) - { - 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); - } - return true; - } - default: return false; + } + + PlayerData data = plugin.pl.getData(playerSender); + + switch (args[0].toLowerCase()) + { + case "enable": + { + if (!plugin.dc.enabled) + { + msg("The Discord verification system is currently disabled.", ChatColor.RED); + return true; + } + else if (data.hasVerification()) + { + msg("Discord verification is already enabled for you.", ChatColor.RED); + return true; + } + else if (data.getDiscordID() == null) + { + msg("Please link a discord account with /linkdiscord.", ChatColor.RED); + return true; + } + data.setVerification(true); + plugin.pl.save(data); + msg("Re-enabled Discord verification.", ChatColor.GREEN); + return true; + } + + case "disable": + { + if (!data.hasVerification()) + { + msg("Discord verification is already disabled for you.", ChatColor.RED); + return true; + } + data.setVerification(false); + plugin.pl.save(data); + msg("Disabled Discord verification.", ChatColor.GREEN); + return true; + } + + case "status": + { + boolean enabled = target.hasVerification(); + boolean specified = target.getDiscordID() != null; + msg(ChatColor.GRAY + "Discord Verification Enabled: " + (enabled ? ChatColor.GREEN + "true" : ChatColor.RED + "false")); + msg(ChatColor.GRAY + "Discord ID: " + (specified ? ChatColor.GREEN + target.getDiscordID() : ChatColor.RED + "not set")); + msg(ChatColor.GRAY + "Backup Codes: " + data.getBackupCodes().size() + "/" + "10"); + return true; + } + + case "genbackupcodes": + { + if (!plugin.dc.enabled) + { + msg("The Discord verification system is currently disabled.", ChatColor.RED); + return true; + } + else if (!data.hasVerification()) + { + 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); + } + return true; + } + default: + return false; + } } + else + { + msg("The Discord verification system is currently disabled", ChatColor.RED); + } + return true; } @Override @@ -153,4 +162,4 @@ public class Command_playerverification extends FreedomCommand return Collections.emptyList(); } -} \ No newline at end of file +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java index b215a4ef..c0eb9474 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -17,12 +18,17 @@ public class Command_verify extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + boolean enableBot = (ConfigEntry.DISCORD_VERIFICATION.getBoolean()); if (!plugin.dc.enabled) { msg("The Discord verification system is currently disabled", ChatColor.RED); return true; } - + if (!enableBot) + { + msg("The Discord verification system is currently disabled", ChatColor.RED); + return true; + } if (senderIsConsole) { msg("/manuallyverify ", ChatColor.WHITE); @@ -90,4 +96,4 @@ public class Command_verify extends FreedomCommand } return true; } -} \ No newline at end of file +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index bc86279f..578a0731 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -69,6 +69,7 @@ public enum ConfigEntry SERVER_WHITELIST_MOTD(String.class, "server.motds.whitelist"), SERVER_FULL_MOTD(String.class, "server.motds.full"), // + DISCORD_VERIFICATION(Boolean.class, "discord.verification"), DISCORD_TOKEN(String.class, "discord.token"), DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"), DISCORD_CHAT_CHANNEL_ID(String.class, "discord.chat_channel_id"), diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 7f419f51..9aa673bb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -59,9 +59,16 @@ public class Discord extends FreedomService public static JDA bot = null; public Boolean enabled = false; + public Boolean enableBot = false; public void startBot() { + enableBot = (ConfigEntry.DISCORD_VERIFICATION.getBoolean()); + if (!enableBot) + { + FLog.info("Discord Verification has been manually disabled."); + return; + } enabled = !Strings.isNullOrEmpty(ConfigEntry.DISCORD_TOKEN.getString()); if (!enabled) { @@ -501,4 +508,4 @@ public class Discord extends FreedomService } return false; } -} \ No newline at end of file +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e1adeda8..f80bb375 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -53,6 +53,8 @@ server: # Discord discord: + # Do you want to enable the bot? (Disabled by default) + verification: false # If you do not have a token, make a bot account and get one at https://discordapp.com/developers/applications/me token: '' # The official discord server's ID for this server