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)
#
# Actions (for events):
# - deny (deny completely)
# - deny (deny completely, used blacklist mode)
# - allow (used in whitelist mode)
# - notify (notify admins)
# - log (log to console/file/database)
# - tell (tell a player that that's not allowed)

View File

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

View File

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

View File

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

View File

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

View File

@ -227,6 +227,9 @@ private void loadConfiguration() {
wp.getGlobalRegionManager().setGlobalFlags(worldName, globalFlags);
boolean useBlacklistAsWhitelist = config.getBoolean("blacklist.use-as-whitelist", false);
// Console log configuration
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
Blacklist blist = new BukkitBlacklist(wp);
Blacklist blist = new BukkitBlacklist(useBlacklistAsWhitelist, wp);
blist.load(blacklistFile);
// If the blacklist is empty, then set the field to null