Test AntiBot + SwitchAntiBotCommand
This commit is contained in:
@@ -4,26 +4,32 @@ import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE;
|
||||
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
|
||||
|
||||
/**
|
||||
* The AntiBot Service Management class.
|
||||
*/
|
||||
public class AntiBot {
|
||||
|
||||
private final NewSetting settings;
|
||||
private final Messages messages;
|
||||
private final PermissionsManager permissionsManager;
|
||||
private final BukkitService bukkitService;
|
||||
private final List<String> antibotPlayers = new ArrayList<>();
|
||||
private AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
|
||||
|
||||
public AntiBot(Messages messages, PermissionsManager permissionsManager, BukkitService bukkitService) {
|
||||
public AntiBot(NewSetting settings, Messages messages, PermissionsManager permissionsManager,
|
||||
BukkitService bukkitService) {
|
||||
this.settings = settings;
|
||||
this.messages = messages;
|
||||
this.permissionsManager = permissionsManager;
|
||||
this.bukkitService = bukkitService;
|
||||
@@ -32,15 +38,14 @@ public class AntiBot {
|
||||
}
|
||||
|
||||
private void setupAntiBotService() {
|
||||
if (!Settings.enableAntiBot) {
|
||||
return;
|
||||
if (settings.getProperty(ProtectionSettings.ENABLE_ANTIBOT)) {
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
antiBotStatus = AntiBotStatus.LISTENING;
|
||||
}
|
||||
}, 2 * TICKS_PER_MINUTE);
|
||||
}
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
antiBotStatus = AntiBotStatus.LISTENING;
|
||||
}
|
||||
}, 2400);
|
||||
}
|
||||
|
||||
public void overrideAntiBotStatus(boolean activated) {
|
||||
@@ -60,9 +65,10 @@ public class AntiBot {
|
||||
public void activateAntiBot() {
|
||||
antiBotStatus = AntiBotStatus.ACTIVE;
|
||||
for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)) {
|
||||
Bukkit.broadcastMessage(s);
|
||||
bukkitService.broadcastMessage(s);
|
||||
}
|
||||
|
||||
final int duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION);
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -70,11 +76,11 @@ public class AntiBot {
|
||||
antiBotStatus = AntiBotStatus.LISTENING;
|
||||
antibotPlayers.clear();
|
||||
for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE)) {
|
||||
bukkitService.broadcastMessage(s.replace("%m", Integer.toString(Settings.antiBotDuration)));
|
||||
bukkitService.broadcastMessage(s.replace("%m", Integer.toString(duration)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Settings.antiBotDuration * 1200);
|
||||
}, duration * TICKS_PER_MINUTE);
|
||||
}
|
||||
|
||||
public void checkAntiBot(final Player player) {
|
||||
@@ -86,7 +92,7 @@ public class AntiBot {
|
||||
}
|
||||
|
||||
antibotPlayers.add(player.getName().toLowerCase());
|
||||
if (antibotPlayers.size() > Settings.antiBotSensibility) {
|
||||
if (antibotPlayers.size() > settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY)) {
|
||||
activateAntiBot();
|
||||
return;
|
||||
}
|
||||
@@ -95,7 +101,7 @@ public class AntiBot {
|
||||
public void run() {
|
||||
antibotPlayers.remove(player.getName().toLowerCase());
|
||||
}
|
||||
}, 300);
|
||||
}, 15 * TICKS_PER_SECOND);
|
||||
}
|
||||
|
||||
public enum AntiBotStatus {
|
||||
|
||||
@@ -258,7 +258,7 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// AntiBot delay
|
||||
BukkitService bukkitService = new BukkitService(this);
|
||||
antiBot = new AntiBot(messages, permsMan, bukkitService);
|
||||
antiBot = new AntiBot(newSettings, messages, permsMan, bukkitService);
|
||||
|
||||
// Set up the permissions manager and command handler
|
||||
permsMan = initializePermissionsManager();
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class Settings {
|
||||
emailRegistration, multiverse, bungee,
|
||||
banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange,
|
||||
disableSocialSpy, useEssentialsMotd,
|
||||
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
|
||||
enableProtection, recallEmail, useWelcomeMessage,
|
||||
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
|
||||
checkVeryGames, removeJoinMessage, removeLeaveMessage, delayJoinMessage,
|
||||
noTeleport, hideTablistBeforeLogin, denyTabcompleteBeforeLogin,
|
||||
@@ -70,9 +70,7 @@ public final class Settings {
|
||||
getPasswordMinLen, getMovementRadius, getmaxRegPerIp,
|
||||
getNonActivatedGroup, passwordMaxLength, getRecoveryPassLength,
|
||||
getMailPort, maxLoginTry, captchaLength, saltLength,
|
||||
getmaxRegPerEmail, bCryptLog2Rounds,
|
||||
antiBotSensibility, antiBotDuration, getMaxLoginPerIp,
|
||||
getMaxJoinPerIp;
|
||||
getmaxRegPerEmail, bCryptLog2Rounds, getMaxLoginPerIp, getMaxJoinPerIp;
|
||||
protected static FileConfiguration configFile;
|
||||
|
||||
/**
|
||||
@@ -172,9 +170,6 @@ public final class Settings {
|
||||
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
|
||||
enableProtection = configFile.getBoolean("Protection.enableProtection", false);
|
||||
countries = configFile.getStringList("Protection.countries");
|
||||
enableAntiBot = configFile.getBoolean("Protection.enableAntiBot", false);
|
||||
antiBotSensibility = configFile.getInt("Protection.antiBotSensibility", 5);
|
||||
antiBotDuration = configFile.getInt("Protection.antiBotDuration", 10);
|
||||
forceCommands = configFile.getStringList("settings.forceCommands");
|
||||
forceCommandsAsConsole = configFile.getStringList("settings.forceCommandsAsConsole");
|
||||
recallEmail = configFile.getBoolean("Email.recallPlayers", false);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ProtectionSettings implements SettingsClass {
|
||||
public static final Property<Boolean> ENABLE_ANTIBOT =
|
||||
newProperty("Protection.enableAntiBot", false);
|
||||
|
||||
@Comment("Max number of player allowed to login in 5 secs before enable AntiBot system automatically")
|
||||
@Comment("Max number of players allowed to login in 5 secs before the AntiBot system is enabled automatically")
|
||||
public static final Property<Integer> ANTIBOT_SENSIBILITY =
|
||||
newProperty("Protection.antiBotSensibility", 5);
|
||||
|
||||
|
||||
@@ -8,6 +8,11 @@ import org.bukkit.Bukkit;
|
||||
*/
|
||||
public class BukkitService {
|
||||
|
||||
/** Number of ticks per second in the Bukkit main thread. */
|
||||
public static final int TICKS_PER_SECOND = 20;
|
||||
/** Number of ticks per minute. */
|
||||
public static final int TICKS_PER_MINUTE = 60 * TICKS_PER_SECOND;
|
||||
|
||||
private final AuthMe authMe;
|
||||
|
||||
public BukkitService(AuthMe authMe) {
|
||||
|
||||
Reference in New Issue
Block a user