Prevent commands in the allow commands list from being blocked and vice versa

This commit is contained in:
zml2008 2012-04-12 20:13:16 -07:00
parent f0e6008563
commit 2cc990a530
2 changed files with 11 additions and 21 deletions

View File

@ -1003,27 +1003,22 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Vector pt = toVector(player.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
ProtectedRegion globalRegion = mgr.getRegion("__global__");
String[] parts = event.getMessage().split(" ");
String lowerCommand = parts[0].toLowerCase();
Set<String> allowedCommands = set.getFlag(DefaultFlag.ALLOWED_CMDS, localPlayer);
if (allowedCommands == null && globalRegion != null) {
allowedCommands = globalRegion.getFlag(DefaultFlag.ALLOWED_CMDS);
}
if (allowedCommands != null && !allowedCommands.contains(parts[0].toLowerCase())) {
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS, localPlayer);
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is not allowed in this area.");
if (allowedCommands != null && !allowedCommands.contains(lowerCommand) && (blockedCommands == null || blockedCommands.contains(lowerCommand))) {
player.sendMessage(ChatColor.RED + lowerCommand + " is not allowed in this area.");
event.setCancelled(true);
return;
}
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS, localPlayer);
if (blockedCommands == null && globalRegion != null) {
blockedCommands = globalRegion.getFlag(DefaultFlag.BLOCKED_CMDS);
}
if (blockedCommands != null && blockedCommands.contains(parts[0].toLowerCase())) {
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is blocked in this area.");
if (blockedCommands != null && blockedCommands.contains(lowerCommand)
&& (allowedCommands == null || !allowedCommands.contains(lowerCommand))) {
player.sendMessage(ChatColor.RED + lowerCommand + " is blocked in this area.");
event.setCancelled(true);
return;
}

View File

@ -38,7 +38,7 @@
* @author sk89q
*/
public class LocationFlag extends Flag<Location> {
public LocationFlag(String name, RegionGroup defaultGroup) {
super(name, defaultGroup);
}
@ -139,16 +139,11 @@ public Object marshal(Location o) {
}
private double toNumber(Object o) {
if (o instanceof Integer) {
return (Integer) o;
} else if (o instanceof Long) {
return (Long) o;
} else if (o instanceof Float) {
return (Float) o;
} else if (o instanceof Double) {
return (Double) o;
if (o instanceof Number) {
return ((Number) o).doubleValue();
} else {
return 0;
}
}
}