#642 - Quick Command Protection manager
This commit is contained in:
parent
914c4adc0b
commit
c0e1b8082f
@ -0,0 +1,51 @@
|
|||||||
|
package fr.xephi.authme.data;
|
||||||
|
|
||||||
|
import fr.xephi.authme.initialization.HasCleanup;
|
||||||
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
|
import fr.xephi.authme.permission.PlayerPermission;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||||
|
import fr.xephi.authme.util.expiring.ExpiringSet;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class QuickCommandsProtectionManager implements SettingsDependent, HasCleanup {
|
||||||
|
|
||||||
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
|
private final ExpiringSet<String> latestLogin;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public QuickCommandsProtectionManager(Settings settings, PermissionsManager permissionsManager) {
|
||||||
|
this.permissionsManager = permissionsManager;
|
||||||
|
long countTimeout = settings.getProperty(ProtectionSettings.QUICK_COMMANDS_DENIED_BEFORE_MILLISECONDS);
|
||||||
|
latestLogin = new ExpiringSet<>(countTimeout, TimeUnit.MILLISECONDS);
|
||||||
|
reload(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogin(String name) {
|
||||||
|
latestLogin.add(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldSaveLogin(Player player) {
|
||||||
|
return permissionsManager.hasPermission(player, PlayerPermission.QUICK_COMMANDS_PROTECTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllowed(String name) {
|
||||||
|
return !latestLogin.contains(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload(Settings settings) {
|
||||||
|
long countTimeout = settings.getProperty(ProtectionSettings.QUICK_COMMANDS_DENIED_BEFORE_MILLISECONDS);
|
||||||
|
latestLogin.setExpiration(countTimeout, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performCleanup() {
|
||||||
|
latestLogin.removeExpiredEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -68,7 +68,12 @@ public enum PlayerPermission implements PermissionNode {
|
|||||||
/**
|
/**
|
||||||
* Permission to use the email verification codes feature.
|
* Permission to use the email verification codes feature.
|
||||||
*/
|
*/
|
||||||
VERIFICATION_CODE("authme.player.security.verificationcode");
|
VERIFICATION_CODE("authme.player.security.verificationcode"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission to use the email verification codes feature.
|
||||||
|
*/
|
||||||
|
QUICK_COMMANDS_PROTECTION("authme.player.protection.quickcommandsprotection");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The permission node.
|
* The permission node.
|
||||||
|
|||||||
@ -55,6 +55,10 @@ public final class ProtectionSettings implements SettingsHolder {
|
|||||||
public static final Property<Integer> ANTIBOT_DELAY =
|
public static final Property<Integer> ANTIBOT_DELAY =
|
||||||
newProperty("Protection.antiBotDelay", 60);
|
newProperty("Protection.antiBotDelay", 60);
|
||||||
|
|
||||||
|
@Comment("Kicks the player that issued a command before the defined time after the login process")
|
||||||
|
public static final Property<Integer> QUICK_COMMANDS_DENIED_BEFORE_MILLISECONDS =
|
||||||
|
newProperty("Protection.quickCommands.denyCommandsBeforeSeconds", 1000);
|
||||||
|
|
||||||
private ProtectionSettings() {
|
private ProtectionSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user