Bugfixes. Allowed/blocked commands should now respect global flags. Region invincibility/godmode compatibility should now work instead of throwing NPEs.

This commit is contained in:
Wizjany 2011-08-11 21:48:30 -04:00
parent dec469caef
commit 602b1d8a27
3 changed files with 24 additions and 8 deletions

View File

@ -768,8 +768,8 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
/** /**
* Check if a player is invincible, via either god mode or region flag. If * Check if a player is invincible, via either god mode or region flag. If
* the region denies invincibility, the player must have the another * the region denies invincibility, the player must have an extra permission
* permission to override it. * to override it. (worldguard.god.override-regions)
* *
* @param player * @param player
* @return * @return
@ -779,13 +779,19 @@ private boolean isInvincible(Player player) {
WorldConfiguration wcfg = cfg.get(player.getWorld()); WorldConfiguration wcfg = cfg.get(player.getWorld());
boolean god = cfg.hasGodMode(player); boolean god = cfg.hasGodMode(player);
Boolean allowed = wcfg.useRegions && RegionQueryUtil.isAllowedInvinciblity(plugin, player); if (wcfg.useRegions) {
if (allowed == false && wcfg.useRegions) { Boolean flag = RegionQueryUtil.isAllowedInvinciblity(plugin, player);
return god && plugin.hasPermission(player, "worldguard.god.override-regions"); boolean allowed = flag == null || flag == true;
} else if (allowed == true || !wcfg.useRegions) { boolean invincible = RegionQueryUtil.isInvincible(plugin, player);
return god;
if (allowed) {
return god || invincible;
} else {
return (god && plugin.hasPermission(player, "worldguard.god.override-regions"))
|| invincible;
}
} else { } else {
return RegionQueryUtil.isInvincible(plugin, player); return god;
} }
} }
} }

View File

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

View File

@ -309,9 +309,11 @@ private void clearParents(Set<ProtectedRegion> needsClear,
* @throws IllegalArgumentException if a StateFlag is given * @throws IllegalArgumentException if a StateFlag is given
*/ */
public <T extends Flag<V>, V> V getFlag(T flag) { public <T extends Flag<V>, V> V getFlag(T flag) {
/*
if (flag instanceof StateFlag) { if (flag instanceof StateFlag) {
throw new IllegalArgumentException("Cannot use StateFlag with getFlag()"); throw new IllegalArgumentException("Cannot use StateFlag with getFlag()");
} }
*/
int lastPriority = 0; int lastPriority = 0;
boolean found = false; boolean found = false;