This commit is contained in:
Gabriele C
2017-09-30 19:57:27 +02:00
parent 351ab684e8
commit 3ea250cb10
3 changed files with 21 additions and 7 deletions
@@ -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
@@ -107,6 +107,11 @@ public final class SecuritySettings implements SettingsHolder {
public static final Property<Integer> 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<String> TEMPBAN_CUSTOM_COMMAND =
newProperty("Security.tempban.customCommand", "");
@Comment("Number of characters a recovery code should have (0 to disable)")
public static final Property<Integer> RECOVERY_CODE_LENGTH =
newProperty("Security.recoveryCode.length", 8);