Configurable antibot delay + delay only on startup

#970
This commit is contained in:
Gabriele C 2016-10-05 22:08:29 +02:00
parent 58c42cf300
commit ac7bb5c0f6
3 changed files with 21 additions and 3 deletions

View File

@ -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<String> 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() {

View File

@ -42,6 +42,10 @@ public class ProtectionSettings implements SettingsHolder {
public static final Property<Integer> ANTIBOT_DURATION =
newProperty("Protection.antiBotDuration", 10);
@Comment("Delay in seconds before the antibot activation")
public static final Property<Integer> ANTIBOT_DELAY =
newProperty("Protection.antiBotDelay", 60);
private ProtectionSettings() {
}

View File

@ -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: ''