blacklist can now be used as whitelist

This commit is contained in:
Redecouverte 2011-02-27 17:48:07 +01:00
parent d6adea447e
commit 06173a446a
6 changed files with 31 additions and 7 deletions

View File

@ -37,7 +37,8 @@
# - on-acquire (an item enters a player's inventory via some method) # - on-acquire (an item enters a player's inventory via some method)
# #
# Actions (for events): # Actions (for events):
# - deny (deny completely) # - deny (deny completely, used blacklist mode)
# - allow (used in whitelist mode)
# - notify (notify admins) # - notify (notify admins)
# - log (log to console/file/database) # - log (log to console/file/database)
# - tell (tell a player that that's not allowed) # - tell (tell a player that that's not allowed)

View File

@ -91,6 +91,7 @@ iconomy:
buy-on-claim-price: 2 buy-on-claim-price: 2
blacklist: blacklist:
use-as-whitelist: off
logging: logging:
console: console:
enable: on enable: on

View File

@ -60,6 +60,14 @@ public abstract class Blacklist {
Map<String,BlacklistTrackedEvent> lastAffected = Map<String,BlacklistTrackedEvent> lastAffected =
new HashMap<String,BlacklistTrackedEvent>(); new HashMap<String,BlacklistTrackedEvent>();
private boolean useAsWhitelist;
public Blacklist(Boolean useAsWhitelist)
{
this.useAsWhitelist = useAsWhitelist;
}
/** /**
* Returns whether the list is empty. * Returns whether the list is empty.
* *
@ -100,7 +108,7 @@ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent)
} }
boolean ret = true; boolean ret = true;
for (BlacklistEntry entry : entries) { for (BlacklistEntry entry : entries) {
if (!entry.check(event, forceRepeat, silent)) { if (!entry.check(useAsWhitelist, event, forceRepeat, silent)) {
ret = false; ret = false;
} }
} }

View File

@ -271,7 +271,7 @@ private String[] getActions(BlacklistEvent event) {
* @param silent * @param silent
* @return * @return
*/ */
public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent) { public boolean check(Boolean useAsWhitelist, BlacklistEvent event, boolean forceRepeat, boolean silent) {
LocalPlayer player = event.getPlayer(); LocalPlayer player = event.getPlayer();
if (shouldIgnore(player)) { if (shouldIgnore(player)) {
@ -293,11 +293,13 @@ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent)
} }
String actions[] = getActions(event); String actions[] = getActions(event);
boolean ret = true;
boolean ret = useAsWhitelist ? false : true;
// Nothing to do // Nothing to do
if (actions == null) { if (actions == null) {
return true; return useAsWhitelist ? false : true;
} }
for (String action : actions) { for (String action : actions) {
@ -309,6 +311,14 @@ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent)
ret = false; ret = false;
// Allow
} else if (action.equalsIgnoreCase("allow")) {
if (silent) {
return true;
}
ret = true;
// Kick // Kick
} else if (action.equalsIgnoreCase("kick")) { } else if (action.equalsIgnoreCase("kick")) {
if (silent) { if (silent) {

View File

@ -25,7 +25,8 @@
public class BukkitBlacklist extends Blacklist { public class BukkitBlacklist extends Blacklist {
private WorldGuardPlugin plugin; private WorldGuardPlugin plugin;
public BukkitBlacklist(WorldGuardPlugin plugin) { public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
super(useAsWhitelist);
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -227,6 +227,9 @@ private void loadConfiguration() {
wp.getGlobalRegionManager().setGlobalFlags(worldName, globalFlags); wp.getGlobalRegionManager().setGlobalFlags(worldName, globalFlags);
boolean useBlacklistAsWhitelist = config.getBoolean("blacklist.use-as-whitelist", false);
// Console log configuration // Console log configuration
boolean logConsole = config.getBoolean("blacklist.logging.console.enable", true); boolean logConsole = config.getBoolean("blacklist.logging.console.enable", true);
@ -250,7 +253,7 @@ private void loadConfiguration() {
} }
// First load the blacklist data from worldguard-blacklist.txt // First load the blacklist data from worldguard-blacklist.txt
Blacklist blist = new BukkitBlacklist(wp); Blacklist blist = new BukkitBlacklist(useBlacklistAsWhitelist, wp);
blist.load(blacklistFile); blist.load(blacklistFile);
// If the blacklist is empty, then set the field to null // If the blacklist is empty, then set the field to null