From 69119e6db7d20d8344979d570eb0de93dde222a8 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Fri, 23 Mar 2012 14:44:58 +0100 Subject: [PATCH] Added ProtectedRegion.isOwner/Member(String playerName). --- .../protection/regions/ProtectedRegion.java | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java index b3100bea..d45fafb0 100644 --- a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java +++ b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java @@ -253,6 +253,29 @@ public boolean isOwner(LocalPlayer player) { return false; } + /** + * Checks whether a player is an owner of region or any of its parents. + * + * @param playerName player name to check + * @return whether an owner + */ + public boolean isOwner(String playerName) { + if (owners.contains(playerName)) { + return true; + } + + ProtectedRegion curParent = getParent(); + while (curParent != null) { + if (curParent.getOwners().contains(playerName)) { + return true; + } + + curParent = curParent.getParent(); + } + + return false; + } + /** * Checks whether a player is a member OR OWNER of the region * or any of its parents. @@ -261,14 +284,45 @@ public boolean isOwner(LocalPlayer player) { * @return whether an owner or member */ public boolean isMember(LocalPlayer player) { - if (owners.contains(player) || members.contains(player)) { + if (isOwner(player)) { + return true; + } + + if (members.contains(player)) { return true; } ProtectedRegion curParent = getParent(); while (curParent != null) { - if (curParent.getOwners().contains(player) - || curParent.getMembers().contains(player)) { + if (curParent.getMembers().contains(player)) { + return true; + } + + curParent = curParent.getParent(); + } + + return false; + } + + /** + * Checks whether a player is a member OR OWNER of the region + * or any of its parents. + * + * @param playerName player name to check + * @return whether an owner or member + */ + public boolean isMember(String playerName) { + if (isOwner(playerName)) { + return true; + } + + if (members.contains(playerName)) { + return true; + } + + ProtectedRegion curParent = getParent(); + while (curParent != null) { + if (curParent.getMembers().contains(playerName)) { return true; }