From e3a6c73b587c5273cf48e1bc858acc50ab2a0143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sun, 1 Nov 2015 18:41:03 +0100 Subject: [PATCH] Implemented the switchantibot command --- src/main/java/fr/xephi/authme/AuthMe.java | 4 ++ .../xephi/authme/command/CommandManager.java | 14 ++++++ .../authme/SwitchAntiBotCommand.java | 46 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index f3ff8778..ec141717 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -721,6 +721,10 @@ public class AuthMe extends JavaPlugin { Settings.switchAntiBotMod(mode); } + public boolean getAntiBotModMode() { + return this.antibotMod; + } + private void recallEmail() { if (!Settings.recallEmail) return; diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index 0b600944..61cf6fec 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -317,6 +317,20 @@ public class CommandManager { authMeCommand); purgeBannedPlayersCommand.setCommandPermissions("authme.admin.purgebannedplayers", CommandPermissions.DefaultPermission.OP_ONLY); + // Register the switchantibot command + CommandDescription switchAntiBotCommand = new CommandDescription( + new PurgeLastPositionCommand(), + new ArrayList() {{ + add("switchantibot"); + add("toggleantibot"); + add("antibot"); + }}, + "Switch AntiBot mode", + "Switch or toggle the AntiBot mode to the specified state.", + authMeCommand); + switchAntiBotCommand.setCommandPermissions("authme.admin.switchantibot", CommandPermissions.DefaultPermission.OP_ONLY); + switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true)); + // Register the reload command CommandDescription reloadCommand = new CommandDescription( new ReloadCommand(), diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java new file mode 100644 index 00000000..2b888e7e --- /dev/null +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java @@ -0,0 +1,46 @@ +package fr.xephi.authme.command.executable.authme; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.command.CommandParts; +import fr.xephi.authme.command.ExecutableCommand; +import org.bukkit.command.CommandSender; + +public class SwitchAntiBotCommand extends ExecutableCommand { + + /** + * Execute the command. + * + * @param sender The command sender. + * @param commandReference The command reference. + * @param commandArguments The command arguments. + * + * @return True if the command was executed successfully, false otherwise. + */ + @Override + public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { + // AuthMe plugin instance + final AuthMe plugin = AuthMe.getInstance(); + + // Get the new state + String newState = plugin.getAntiBotModMode() ? "OFF" : "ON"; + if(commandArguments.getCount() >= 1) + newState = commandArguments.get(0); + + // Enable the mod + if(newState.equalsIgnoreCase("ON")) { + plugin.switchAntiBotMod(true); + sender.sendMessage("[AuthMe] AntiBotMod enabled"); + return true; + } + + // Disable the mod + if(newState.equalsIgnoreCase("OFF")) { + plugin.switchAntiBotMod(false); + sender.sendMessage("[AuthMe] AntiBotMod disabled"); + return true; + } + + // Invalid command arguments, return false + return false; + } +}