Misc code householding
- Checkstyle config: allow todo comments with issue number
- Create consistency tests across all classes, ensuring: unique class names, users of expiring collectors implement HasCleanup, non-private fields are only constants
- Fix tag replacement in PlayerListener for {DISPLAYNAME}
This commit is contained in:
+2
-1
@@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.authme.debug;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
@@ -25,7 +26,7 @@ import java.util.function.BiFunction;
|
||||
class HasPermissionChecker implements DebugSection {
|
||||
|
||||
static final List<Class<? extends PermissionNode>> PERMISSION_NODE_CLASSES =
|
||||
Arrays.asList(AdminPermission.class, PlayerPermission.class, PlayerStatePermission.class);
|
||||
ImmutableList.of(AdminPermission.class, PlayerPermission.class, PlayerStatePermission.class);
|
||||
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@@ -175,7 +175,7 @@ public class PlayerListener implements Listener {
|
||||
String customJoinMessage = settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE);
|
||||
if (!customJoinMessage.isEmpty()) {
|
||||
event.setJoinMessage(customJoinMessage.replace("{PLAYERNAME}", player.getName())
|
||||
.replace("{DISPLAYNAME]", player.getDisplayName()));
|
||||
.replace("{DISPLAYNAME}", player.getDisplayName()));
|
||||
}
|
||||
|
||||
if (!settings.getProperty(RegistrationSettings.DELAY_JOIN_MESSAGE)) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.xephi.authme.service;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.HasCleanup;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
@@ -25,7 +26,7 @@ import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWOR
|
||||
/**
|
||||
* Manager for password recovery.
|
||||
*/
|
||||
public class PasswordRecoveryService implements Reloadable {
|
||||
public class PasswordRecoveryService implements Reloadable, HasCleanup {
|
||||
|
||||
@Inject
|
||||
private CommonService commonService;
|
||||
@@ -163,4 +164,10 @@ public class PasswordRecoveryService implements Reloadable {
|
||||
successfulRecovers.setExpiration(
|
||||
commonService.getProperty(SecuritySettings.PASSWORD_CHANGE_TIMEOUT), TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performCleanup() {
|
||||
emailCooldown.removeExpiredEntries();
|
||||
successfulRecovers.removeExpiredEntries();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class ExpiringMap<K, V> {
|
||||
|
||||
protected final Map<K, ExpiringEntry<V>> entries = new ConcurrentHashMap<>();
|
||||
private final Map<K, ExpiringEntry<V>> entries = new ConcurrentHashMap<>();
|
||||
private long expirationMillis;
|
||||
|
||||
/**
|
||||
@@ -105,6 +105,13 @@ public class ExpiringMap<K, V> {
|
||||
return entries.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the internal map
|
||||
*/
|
||||
protected Map<K, ExpiringEntry<V>> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class holding a value paired with an expiration timestamp.
|
||||
*
|
||||
|
||||
@@ -44,13 +44,13 @@ public class TimedCounter<K> extends ExpiringMap<K, Integer> {
|
||||
* @param key the key to increment the counter for
|
||||
*/
|
||||
public void decrement(K key) {
|
||||
ExpiringEntry<Integer> e = entries.get(key);
|
||||
ExpiringEntry<Integer> e = getEntries().get(key);
|
||||
|
||||
if (e != null) {
|
||||
if (e.getValue() <= 0) {
|
||||
remove(key);
|
||||
} else {
|
||||
entries.put(key, new ExpiringEntry<>(e.getValue() - 1, e.getExpiration()));
|
||||
getEntries().put(key, new ExpiringEntry<>(e.getValue() - 1, e.getExpiration()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class TimedCounter<K> extends ExpiringMap<K, Integer> {
|
||||
*/
|
||||
public int total() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
return entries.values().stream()
|
||||
return getEntries().values().stream()
|
||||
.filter(entry -> currentTime <= entry.getExpiration())
|
||||
.map(ExpiringEntry::getValue)
|
||||
.reduce(0, Integer::sum);
|
||||
|
||||
Reference in New Issue
Block a user