From ac7bb5c0f6ff9e541b81367e798b24ecdf9b5b34 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 5 Oct 2016 22:08:29 +0200 Subject: [PATCH] Configurable antibot delay + delay only on startup #970 --- .../xephi/authme/service/AntiBotService.java | 18 +++++++++++++++--- .../properties/ProtectionSettings.java | 4 ++++ src/main/resources/config.yml | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/service/AntiBotService.java b/src/main/java/fr/xephi/authme/service/AntiBotService.java index be1eb8da..24118d40 100644 --- a/src/main/java/fr/xephi/authme/service/AntiBotService.java +++ b/src/main/java/fr/xephi/authme/service/AntiBotService.java @@ -29,9 +29,11 @@ public class AntiBotService implements SettingsDependent { // Settings private int duration; private int sensibility; + private int delay; // Service status private AntiBotStatus antiBotStatus; + private boolean startup; private BukkitTask disableTask; private int antibotPlayers; private final CopyOnWriteArrayList antibotKicked = new CopyOnWriteArrayList<>(); @@ -47,6 +49,7 @@ public class AntiBotService implements SettingsDependent { disableTask = null; antibotPlayers = 0; antiBotStatus = AntiBotStatus.DISABLED; + startup = true; // Load settings and start if required reload(settings); } @@ -56,6 +59,7 @@ public class AntiBotService implements SettingsDependent { // Load settings duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); sensibility = settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY); + delay = settings.getProperty(ProtectionSettings.ANTIBOT_DELAY); // Stop existing protection stopProtection(); @@ -66,13 +70,21 @@ public class AntiBotService implements SettingsDependent { return; } - // Schedule the bot activation - bukkitService.scheduleSyncDelayedTask(new Runnable() { + // Bot activation task + Runnable enableTask = new Runnable() { @Override public void run() { antiBotStatus = AntiBotStatus.LISTENING; } - }, 90 * TICKS_PER_SECOND); + }; + + // Delay the schedule on first start + if(startup) { + bukkitService.scheduleSyncDelayedTask(enableTask, delay * TICKS_PER_SECOND); + startup = false; + } else { + enableTask.run(); + } } private void startProtection() { diff --git a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java index 5198a0cc..cdd760bd 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java @@ -42,6 +42,10 @@ public class ProtectionSettings implements SettingsHolder { public static final Property ANTIBOT_DURATION = newProperty("Protection.antiBotDuration", 10); + @Comment("Delay in seconds before the antibot activation") + public static final Property ANTIBOT_DELAY = + newProperty("Protection.antiBotDelay", 60); + private ProtectionSettings() { } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7516890a..2dc4bb00 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -435,6 +435,8 @@ Protection: antiBotSensibility: 10 # Duration in minutes of the antibot automatic system antiBotDuration: 10 + # Delay in seconds before the antibot activation + antiBotDelay: 60 GroupOptions: # Registered permission group RegisteredPlayerGroup: ''