Added ability to disable chest protection.

This commit is contained in:
sk89q 2011-01-24 02:35:33 -08:00
parent edc6825f83
commit 772d2cb580
5 changed files with 22 additions and 2 deletions

View File

@ -35,6 +35,7 @@
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.events.*;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.AreaFlags;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
public class WorldGuardBlockListener extends BlockListener {
@ -288,6 +289,7 @@ public void onBlockInteract(BlockInteractEvent event) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.hasPermission(player, "/regionbypass")
&& !plugin.regionManager.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CHEST_ACCESS)
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);

View File

@ -296,6 +296,7 @@ public void loadConfiguration() {
useRegions = config.getBoolean("regions.enable", true);
regionWand = config.getInt("regions.wand", 287);
globalFlags.canBuild = config.getBoolean("regions.default.build", true);
globalFlags.canAccessChests = config.getBoolean("regions.default.chest-access", false);
try {
regionLoader.load();

View File

@ -67,7 +67,13 @@ public boolean canBuild(LocalPlayer player) {
* @return
*/
public boolean allowsFlag(String flag) {
return isFlagAllowed(flag, true, null);
boolean def = true;
if (flag.equals(AreaFlags.FLAG_CHEST_ACCESS)) {
def = global.canAccessChests;
}
return isFlagAllowed(flag, def, null);
}
/**
@ -80,6 +86,9 @@ public boolean allowsFlag(String flag) {
private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
boolean found = false;
boolean allowed = false; // Used for ALLOW override
if (player == null) {
allowed = def;
}
int lastPriority = 0;
// The algorithm is as follows:
@ -120,6 +129,7 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
// default state is now to allow
if (region.getFlags().get(flag) == State.ALLOW) {
allowed = true;
found = true;
continue;
}
@ -145,7 +155,8 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
lastPriority = region.getPriority();
}
return found == false ? def : allowed || needsClear.size() == 0;
return (found == false ? def : allowed)
|| (player != null && needsClear.size() == 0);
}
/**

View File

@ -44,6 +44,7 @@ public enum State {
public static final String FLAG_LIGHTER = "l";
public static final String FLAG_FIRE_SPREAD = "f";
public static final String FLAG_LAVA_FIRE = "F";
public static final String FLAG_CHEST_ACCESS = "c";
/**
* Get the user-friendly name of a flag. If a name isn't known, then
@ -71,6 +72,8 @@ public static String getFlagName(String flag) {
return "fire spread";
} else if (flag.equals(FLAG_LAVA_FIRE)) {
return "lava fire spread";
} else if (flag.equals(FLAG_CHEST_ACCESS)) {
return "chest access";
} else {
return flag;
}
@ -101,6 +104,8 @@ public static String fromAlias(String name) {
return FLAG_FIRE_SPREAD;
} else if (name.equalsIgnoreCase("lavafirespread")) {
return FLAG_LAVA_FIRE;
} else if (name.equalsIgnoreCase("chest")) {
return FLAG_CHEST_ACCESS;
} else {
return null;
}

View File

@ -26,4 +26,5 @@
*/
public class GlobalFlags {
public boolean canBuild = true;
public boolean canAccessChests = false;
}