From 3ea250cb10f3f9b6f5071397a1f4e5f726192d6c Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sat, 30 Sep 2017 19:57:27 +0200 Subject: [PATCH] Implement #794 --- docs/config.md | 7 +++++-- .../fr/xephi/authme/data/TempbanManager.java | 16 +++++++++++----- .../settings/properties/SecuritySettings.java | 5 +++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/config.md b/docs/config.md index a3a970d4d..65a23f803 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,5 +1,5 @@ - + ## AuthMe Configuration The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder, @@ -442,6 +442,9 @@ Security: # How many minutes before resetting the count for failed logins by IP and username # Default: 480 minutes (8 hours) minutesBeforeCounterReset: 480 + # If not empty this command will be executed instead of using the internal server ban system. + # Available placeholders: %player%, %ip% + customCommand: '' recoveryCode: # Number of characters a recovery code should have (0 to disable) length: 8 @@ -540,4 +543,4 @@ To change settings on a running server, save your changes to config.yml and use --- -This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sun Sep 17 11:29:06 CEST 2017 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Sep 30 19:52:39 CEST 2017 diff --git a/src/main/java/fr/xephi/authme/data/TempbanManager.java b/src/main/java/fr/xephi/authme/data/TempbanManager.java index 6256fa1eb..f29a16d9f 100644 --- a/src/main/java/fr/xephi/authme/data/TempbanManager.java +++ b/src/main/java/fr/xephi/authme/data/TempbanManager.java @@ -17,7 +17,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -import static fr.xephi.authme.settings.properties.SecuritySettings.TEMPBAN_MINUTES_BEFORE_RESET; import static fr.xephi.authme.util.Utils.MILLIS_PER_MINUTE; /** @@ -33,6 +32,7 @@ public class TempbanManager implements SettingsDependent, HasCleanup { private int threshold; private int length; private long resetThreshold; + private String customCommand; @Inject TempbanManager(BukkitService bukkitService, Messages messages, Settings settings) { @@ -95,6 +95,7 @@ public class TempbanManager implements SettingsDependent, HasCleanup { */ public void tempbanPlayer(final Player player) { if (isEnabled) { + final String name = player.getName(); final String ip = PlayerUtils.getPlayerIp(player); final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS); @@ -102,11 +103,15 @@ public class TempbanManager implements SettingsDependent, HasCleanup { long newTime = expires.getTime() + (length * MILLIS_PER_MINUTE); expires.setTime(newTime); - bukkitService.scheduleSyncDelayedTask(new Runnable() { - @Override - public void run() { + bukkitService.scheduleSyncDelayedTask(() -> { + if(customCommand.isEmpty()) { bukkitService.banIp(ip, reason, expires, "AuthMe"); player.kickPlayer(reason); + } else { + String command = customCommand + .replaceAll("%player%", name) + .replaceAll("%ip%", ip); + bukkitService.dispatchConsoleCommand(command); } }); @@ -119,7 +124,8 @@ public class TempbanManager implements SettingsDependent, HasCleanup { this.isEnabled = settings.getProperty(SecuritySettings.TEMPBAN_ON_MAX_LOGINS); this.threshold = settings.getProperty(SecuritySettings.MAX_LOGIN_TEMPBAN); this.length = settings.getProperty(SecuritySettings.TEMPBAN_LENGTH); - this.resetThreshold = settings.getProperty(TEMPBAN_MINUTES_BEFORE_RESET); + this.resetThreshold = settings.getProperty(SecuritySettings.TEMPBAN_MINUTES_BEFORE_RESET); + this.customCommand = settings.getProperty(SecuritySettings.TEMPBAN_CUSTOM_COMMAND); } @Override diff --git a/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java b/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java index fc67513c3..04af8e4a0 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java @@ -107,6 +107,11 @@ public final class SecuritySettings implements SettingsHolder { public static final Property TEMPBAN_MINUTES_BEFORE_RESET = newProperty("Security.tempban.minutesBeforeCounterReset", 480); + @Comment({"If not empty this command will be executed instead of using the internal server ban system.", + "Available placeholders: %player%, %ip%"}) + public static final Property TEMPBAN_CUSTOM_COMMAND = + newProperty("Security.tempban.customCommand", ""); + @Comment("Number of characters a recovery code should have (0 to disable)") public static final Property RECOVERY_CODE_LENGTH = newProperty("Security.recoveryCode.length", 8);