Change AntiBot from static to instance

- Convert static methods in AntiBot
- Create BukkitService for operations requiring calls to static methods on the Bukkit class
This commit is contained in:
ljacqu
2016-03-24 20:58:18 +01:00
parent 881a192413
commit 351b24fd14
8 changed files with 161 additions and 107 deletions
@@ -1,5 +1,6 @@
package fr.xephi.authme.command;
import fr.xephi.authme.AntiBot;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.help.HelpProvider;
@@ -34,6 +35,7 @@ public class CommandService {
private final IpAddressManager ipAddressManager;
private final PluginHooks pluginHooks;
private final SpawnLoader spawnLoader;
private final AntiBot antiBot;
/**
* Constructor.
@@ -51,7 +53,8 @@ public class CommandService {
*/
public CommandService(AuthMe authMe, CommandMapper commandMapper, HelpProvider helpProvider, Messages messages,
PasswordSecurity passwordSecurity, PermissionsManager permissionsManager, NewSetting settings,
IpAddressManager ipAddressManager, PluginHooks pluginHooks, SpawnLoader spawnLoader) {
IpAddressManager ipAddressManager, PluginHooks pluginHooks, SpawnLoader spawnLoader,
AntiBot antiBot) {
this.authMe = authMe;
this.messages = messages;
this.helpProvider = helpProvider;
@@ -62,6 +65,7 @@ public class CommandService {
this.ipAddressManager = ipAddressManager;
this.pluginHooks = pluginHooks;
this.spawnLoader = spawnLoader;
this.antiBot = antiBot;
}
/**
@@ -211,4 +215,8 @@ public class CommandService {
return spawnLoader;
}
public AntiBot getAntiBot() {
return antiBot;
}
}
@@ -18,8 +18,9 @@ public class SwitchAntiBotCommand implements ExecutableCommand {
@Override
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
AntiBot antiBot = commandService.getAntiBot();
if (arguments.isEmpty()) {
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
sender.sendMessage("[AuthMe] AntiBot status: " + antiBot.getAntiBotStatus().name());
return;
}
@@ -27,10 +28,10 @@ public class SwitchAntiBotCommand implements ExecutableCommand {
// Enable or disable the mod
if ("ON".equalsIgnoreCase(newState)) {
AntiBot.overrideAntiBotStatus(true);
antiBot.overrideAntiBotStatus(true);
sender.sendMessage("[AuthMe] AntiBot Manual Override: enabled!");
} else if ("OFF".equalsIgnoreCase(newState)) {
AntiBot.overrideAntiBotStatus(false);
antiBot.overrideAntiBotStatus(false);
sender.sendMessage("[AuthMe] AntiBot Manual Override: disabled!");
} else {
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");