Moved blacklist message flood logger to Blacklist.

This commit is contained in:
sk89q 2011-01-16 09:11:42 -08:00
parent 0037a4e83f
commit cb1c1efc35
3 changed files with 27 additions and 26 deletions

View File

@ -28,6 +28,7 @@
import java.io.*; import java.io.*;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.events.BlacklistEvent; import com.sk89q.worldguard.blacklist.events.BlacklistEvent;
/** /**
@ -53,6 +54,11 @@ public abstract class Blacklist {
* Last event. * Last event.
*/ */
private BlacklistEvent lastEvent; private BlacklistEvent lastEvent;
/**
* Used to prevent flooding.
*/
Map<String,BlacklistTrackedEvent> lastAffected =
new HashMap<String,BlacklistTrackedEvent>();
/** /**
* Returns whether the list is empty. * Returns whether the list is empty.
@ -247,6 +253,24 @@ public void notify(BlacklistEvent event, String comment) {
*/ */
public abstract void broadcastNotification(String msg); public abstract void broadcastNotification(String msg);
/**
* Forget a player.
*
* @param player
*/
public void forgetPlayer(LocalPlayer player) {
lastAffected.remove(player.getName());
}
/**
* Forget all players.
*
* @param player
*/
public void forgetAllPlayers() {
lastAffected.clear();
}
/** /**
* Get an item's ID from its name. * Get an item's ID from its name.
* *

View File

@ -40,11 +40,6 @@
* @author sk89q * @author sk89q
*/ */
public class BlacklistEntry { public class BlacklistEntry {
/**
* Used to prevent flooding.
*/
private static Map<String,BlacklistTrackedEvent> lastAffected =
new HashMap<String,BlacklistTrackedEvent>();
/** /**
* Parent blacklist entry. * Parent blacklist entry.
*/ */
@ -290,13 +285,13 @@ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent)
boolean repeating = false; boolean repeating = false;
// Check to see whether this event is being repeated // Check to see whether this event is being repeated
BlacklistTrackedEvent tracked = lastAffected.get(name); BlacklistTrackedEvent tracked = blacklist.lastAffected.get(name);
if (tracked != null) { if (tracked != null) {
if (tracked.matches(event, now)) { if (tracked.matches(event, now)) {
repeating = true; repeating = true;
} }
} else { } else {
lastAffected.put(name, new BlacklistTrackedEvent(event, now)); blacklist.lastAffected.put(name, new BlacklistTrackedEvent(event, now));
} }
String actions[] = getActions(event); String actions[] = getActions(event);
@ -372,24 +367,6 @@ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent)
return ret; return ret;
} }
/**
* Forget a player.
*
* @param player
*/
public static void forgetPlayer(LocalPlayer player) {
lastAffected.remove(player.getName());
}
/**
* Forget all players.
*
* @param player
*/
public static void forgetAllPlayers() {
lastAffected.clear();
}
/** /**
* Get an item's friendly name with its ID. * Get an item's friendly name with its ID.
* *

View File

@ -39,7 +39,6 @@
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.*; import com.sk89q.worldguard.*;
import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
import com.sk89q.worldguard.domains.*; import com.sk89q.worldguard.domains.*;
import com.sk89q.worldguard.protection.*; import com.sk89q.worldguard.protection.*;
@ -102,6 +101,7 @@ public void onPlayerQuit(PlayerEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
plugin.invinciblePlayers.remove(player.getName()); plugin.invinciblePlayers.remove(player.getName());
plugin.amphibiousPlayers.remove(player.getName()); plugin.amphibiousPlayers.remove(player.getName());
plugin.blacklist.forgetPlayer(plugin.wrapPlayer(player));
} }
/** /**