Move and encapsulate "ignored" collection

This commit is contained in:
P0nk
2021-12-21 21:42:57 +01:00
parent 75a9a9718d
commit acde0696b1
4 changed files with 41 additions and 17 deletions

View File

@@ -24,11 +24,14 @@ package client.autoban;
import client.Character;
import config.YamlConfig;
import net.packet.logging.MonitoredChrLogger;
import net.server.Server;
import tools.FilePrinter;
import tools.PacketCreator;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -56,6 +59,8 @@ public enum AutobanFactory {
FAST_ATTACK(10, SECONDS.toMillis(30)),
MPCON(25, SECONDS.toMillis(30));
private static final Set<Integer> ignoredChrIds = new HashSet<>();
private final int points;
private final long expiretime;
@@ -87,7 +92,7 @@ public enum AutobanFactory {
public void alert(Character chr, String reason) {
if (YamlConfig.config.server.USE_AUTOBAN) {
if (chr != null && MonitoredChrLogger.ignored.contains(chr.getId())) {
if (chr != null && isIgnored(chr.getId())) {
return;
}
Server.getInstance().broadcastGMMessage((chr != null ? chr.getWorld() : 0), PacketCreator.sendYellowTip((chr != null ? Character.makeMapleReadable(chr.getName()) : "") + " caused " + this.name() + " " + reason));
@@ -103,4 +108,28 @@ public enum AutobanFactory {
//chr.sendPolice("You will be disconnected for (" + this.name() + ": " + value + ")");
}
}
/**
* Toggle ignored status for a character id.
* An ignored character will not trigger GM alerts.
*
* @return new status. true if the chrId is now ignored, otherwise false.
*/
public static boolean toggleIgnored(int chrId) {
if (ignoredChrIds.contains(chrId)) {
ignoredChrIds.remove(chrId);
return false;
} else {
ignoredChrIds.add(chrId);
return true;
}
}
private static boolean isIgnored(int chrId) {
return ignoredChrIds.contains(chrId);
}
public static Collection<Integer> getIgnoredChrIds() {
return ignoredChrIds;
}
}