Move and encapsulate "ignored" collection
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ package client.command.commands.gm3;
|
||||
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import client.autoban.AutobanFactory;
|
||||
import client.command.Command;
|
||||
import net.packet.logging.MonitoredChrLogger;
|
||||
import net.server.Server;
|
||||
import tools.PacketCreator;
|
||||
|
||||
public class IgnoreCommand extends Command {
|
||||
{
|
||||
setDescription("Toggle enable/disable ignore a player in packet logs and autoban.");
|
||||
setDescription("Toggle ignore a character from auto-ban alerts.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,14 +47,10 @@ public class IgnoreCommand extends Command {
|
||||
player.message("Player '" + params[0] + "' could not be found on this world.");
|
||||
return;
|
||||
}
|
||||
boolean monitored_ = MonitoredChrLogger.ignored.contains(victim.getId());
|
||||
if (monitored_) {
|
||||
MonitoredChrLogger.ignored.remove(victim.getId());
|
||||
} else {
|
||||
MonitoredChrLogger.ignored.add(victim.getId());
|
||||
}
|
||||
player.yellowMessage(victim.getName() + " is " + (!monitored_ ? "now being ignored." : "no longer being ignored."));
|
||||
String message_ = player.getName() + (!monitored_ ? " has started ignoring " : " has stopped ignoring ") + victim.getName() + ".";
|
||||
|
||||
boolean ignored = AutobanFactory.toggleIgnored(victim.getId());
|
||||
player.yellowMessage(victim.getName() + " is " + (ignored ? "now being ignored." : "no longer being ignored."));
|
||||
String message_ = player.getName() + (ignored ? " has started ignoring " : " has stopped ignoring ") + victim.getName() + ".";
|
||||
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(5, message_));
|
||||
|
||||
}
|
||||
|
||||
@@ -25,19 +25,19 @@ package client.command.commands.gm3;
|
||||
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import client.autoban.AutobanFactory;
|
||||
import client.command.Command;
|
||||
import net.packet.logging.MonitoredChrLogger;
|
||||
|
||||
public class IgnoredCommand extends Command {
|
||||
{
|
||||
setDescription("Show all players being ignored in logs.");
|
||||
setDescription("Show all characters being ignored in auto-ban alerts.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client c, String[] params) {
|
||||
Character player = c.getPlayer();
|
||||
for (Integer cid : MonitoredChrLogger.ignored) {
|
||||
player.yellowMessage(Character.getNameById(cid) + " is being ignored.");
|
||||
for (int chrId : AutobanFactory.getIgnoredChrIds()) {
|
||||
player.yellowMessage(Character.getNameById(chrId) + " is being ignored.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ import java.util.Set;
|
||||
public class MonitoredChrLogger {
|
||||
private static final Logger log = LoggerFactory.getLogger(MonitoredChrLogger.class);
|
||||
private static final Set<Integer> monitoredChrIds = new HashSet<>();
|
||||
public static final Set<Integer> ignored = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Toggle monitored status for a character id
|
||||
|
||||
Reference in New Issue
Block a user