Added region command whitelisting and the bypass for command checks.

This commit is contained in:
sk89q 2011-06-26 10:45:12 -07:00
parent c9178da608
commit 767c49f9fa
2 changed files with 10 additions and 2 deletions

View File

@ -898,13 +898,20 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (wcfg.useRegions && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
Vector pt = toVector(player.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
String[] parts = event.getMessage().split(" ");
Set<String> allowedCommands = set.getFlag(DefaultFlag.ALLOWED_CMDS);
if (allowedCommands != null && !allowedCommands.contains(parts[0].toLowerCase())) {
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is not allowed in this area.");
event.setCancelled(true);
return;
}
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS);
if (blockedCommands != null && blockedCommands.contains(parts[0].toLowerCase())) {
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is blocked in this area.");

View File

@ -63,6 +63,7 @@ public final class DefaultFlag {
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
public static final DoubleFlag PRICE = new DoubleFlag("price");
public static final SetFlag<String> BLOCKED_CMDS = new SetFlag<String>("blocked-cmds", new CommandStringFlag(null));
public static final SetFlag<String> ALLOWED_CMDS = new SetFlag<String>("allowed-cmds", new CommandStringFlag(null));
public static final Flag<?>[] flagsList = new Flag<?>[] {
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, MOB_SPAWNING, CREEPER_EXPLOSION, SLEEP,
@ -70,7 +71,7 @@ public final class DefaultFlag {
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER,
NOTIFY_LEAVE, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE, SNOW_FALL, LEAF_DECAY,
GHAST_FIREBALL, BLOCKED_CMDS
GHAST_FIREBALL, BLOCKED_CMDS, ALLOWED_CMDS
};
private DefaultFlag() {