Typo's and formatting

This commit is contained in:
ElgarL 2011-10-31 09:14:58 +00:00
parent 0f67d42c99
commit 0731de53b4
3 changed files with 2868 additions and 2846 deletions

View file

@ -58,7 +58,8 @@ public class GlobalGroups {
} }
/** /**
* @param haveGroupsChanged the haveGroupsChanged to set * @param haveGroupsChanged
* the haveGroupsChanged to set
*/ */
public void setGroupsChanged(boolean haveGroupsChanged) { public void setGroupsChanged(boolean haveGroupsChanged) {
this.haveGroupsChanged = haveGroupsChanged; this.haveGroupsChanged = haveGroupsChanged;
@ -71,14 +72,12 @@ public class GlobalGroups {
groups = new HashMap<String, Group>(); groups = new HashMap<String, Group>();
// READ globalGroups FILE // READ globalGroups FILE
File GlobalGroupsFile = new File(plugin.getDataFolder(), File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
"globalgroups.yml");
if (!GlobalGroupsFile.exists()) { if (!GlobalGroupsFile.exists()) {
try { try {
// Create a new file if it doesn't exist. // Create a new file if it doesn't exist.
Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"), Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"), GlobalGroupsFile);
GlobalGroupsFile);
} catch (IOException ex) { } catch (IOException ex) {
GroupManager.logger.log(Level.SEVERE, null, ex); GroupManager.logger.log(Level.SEVERE, null, ex);
} }
@ -87,21 +86,17 @@ public class GlobalGroups {
try { try {
GGroups.load(GlobalGroupsFile); GGroups.load(GlobalGroupsFile);
} catch (Exception ex) { } catch (Exception ex) {
throw new IllegalArgumentException( throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + GlobalGroupsFile.getPath(), ex);
"The following file couldn't pass on Parser.\n"
+ GlobalGroupsFile.getPath(), ex);
} }
// Read all global groups // Read all global groups
Map<String, Object> allGroups = (Map<String, Object>) GGroups Map<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
.getConfigurationSection("groups").getValues(false);
// Load each groups permissions list. // Load each groups permissions list.
if (allGroups != null) if (allGroups != null)
for (String groupName : allGroups.keySet()) { for (String groupName : allGroups.keySet()) {
Group newGroup = new Group(groupName.toLowerCase()); Group newGroup = new Group(groupName.toLowerCase());
Object permissions = GGroups.get("groups." + groupName Object permissions = GGroups.get("groups." + groupName + ".permissions");
+ ".permissions");
if (permissions instanceof List) { if (permissions instanceof List) {
for (String permission : (List<String>) permissions) { for (String permission : (List<String>) permissions) {
@ -120,15 +115,12 @@ public class GlobalGroups {
} }
/** /**
* Write a dataHolder in a specified file * Write the globalgroups.yml file
* @param ph
* @param groupsFile
*/ */
public void writeGroups() { public void writeGroups() {
File GlobalGroupsFile = new File(plugin.getDataFolder(), File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
"globalgroups.yml");
Map<String, Object> root = new HashMap<String, Object>(); Map<String, Object> root = new HashMap<String, Object>();
@ -186,7 +178,6 @@ public class GlobalGroups {
return false; return false;
} }
/** /**
* Returns true if the Global Group exists in the globalgroups.yml * Returns true if the Global Group exists in the globalgroups.yml
* *
@ -209,8 +200,7 @@ public class GlobalGroups {
if (!hasGroup(groupName.toLowerCase())) if (!hasGroup(groupName.toLowerCase()))
return false; return false;
return groups.get(groupName.toLowerCase()).hasSamePermissionNode( return groups.get(groupName.toLowerCase()).hasSamePermissionNode(permissionNode);
permissionNode);
} }
@ -222,8 +212,7 @@ public class GlobalGroups {
* @param permissionNode * @param permissionNode
* @return * @return
*/ */
public PermissionCheckResult checkPermission(String groupName, public PermissionCheckResult checkPermission(String groupName, String permissionNode) {
String permissionNode) {
PermissionCheckResult result = new PermissionCheckResult(); PermissionCheckResult result = new PermissionCheckResult();
result.askedPermission = permissionNode; result.askedPermission = permissionNode;

View file

@ -34,6 +34,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* It needs a WorldDataHolder to work with. * It needs a WorldDataHolder to work with.
*
* @param holder * @param holder
*/ */
public AnjoPermissionsHandler(WorldDataHolder holder) { public AnjoPermissionsHandler(WorldDataHolder holder) {
@ -42,6 +43,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* A short name method, for permission method. * A short name method, for permission method.
*
* @param player * @param player
* @param permission * @param permission
* @return * @return
@ -53,6 +55,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Checks if a player can use that permission node. * Checks if a player can use that permission node.
*
* @param player * @param player
* @param permission * @param permission
* @return * @return
@ -64,6 +67,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Checks if a player can use that permission node. * Checks if a player can use that permission node.
*
* @param playerName * @param playerName
* @param permission * @param permission
* @return * @return
@ -74,6 +78,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the name of the group of that player name. * Returns the name of the group of that player name.
*
* @param userName * @param userName
* @return * @return
*/ */
@ -83,7 +88,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns All permissions (including inheritance and sub groups) for the player. * Returns All permissions (including inheritance and sub groups) for the
* player.
* *
* @param userName * @param userName
* @return * @return
@ -96,14 +102,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
for (String group : getGroups(userName)) { for (String group : getGroups(userName)) {
if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) { if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) {
for (String perm : GroupManager.getGlobalGroups().getGroupsPermissions(group)) { for (String perm : GroupManager.getGlobalGroups().getGroupsPermissions(group)) {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) { if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
playerPermArray.add(perm); playerPermArray.add(perm);
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm); Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
if (children != null) { if (children != null) {
for (String child : children.keySet()) { for (String child : children.keySet()) {
if (children.get(child)) if (children.get(child))
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm)))
playerPermArray.add(child); playerPermArray.add(child);
} }
} }
@ -112,14 +118,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} else { } else {
for (String perm : ph.getGroup(group).getPermissionList()) { for (String perm : ph.getGroup(group).getPermissionList()) {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) { if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
playerPermArray.add(perm); playerPermArray.add(perm);
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm); Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
if (children != null) { if (children != null) {
for (String child : children.keySet()) { for (String child : children.keySet()) {
if (children.get(child)) if (children.get(child))
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm)))
playerPermArray.add(child); playerPermArray.add(child);
} }
} }
@ -133,16 +139,15 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Verify if player is in suck group. * Verify if player is in suck group. It will check it's groups inheritance.
* It will check it's groups inheritance.
* *
* So if you have a group Admin > Moderator * So if you have a group Admin > Moderator
* *
* And verify the player 'MyAdmin', which is Admin, it will return true for both * And verify the player 'MyAdmin', which is Admin, it will return true for
* Admin or Moderator groups. * both Admin or Moderator groups.
* *
* Mas if you have a player 'MyModerator', which is Moderator, * Mas if you have a player 'MyModerator', which is Moderator, it will give
* it will give false if you pass Admin in group parameter. * false if you pass Admin in group parameter.
* *
* @param name * @param name
* @param group * @param group
@ -162,11 +167,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Gets the appropriate prefix for the user. * Gets the appropriate prefix for the user. This method is a utility method
* This method is a utility method for chat plugins to get the user's prefix * for chat plugins to get the user's prefix without having to look at every
* without having to look at every one of the user's ancestors. * one of the user's ancestors. Returns an empty string if user has no
* Returns an empty string if user has no parent groups. * parent groups.
* @param user Player's name *
* @param user
* Player's name
* @return Player's prefix * @return Player's prefix
*/ */
@Override @Override
@ -181,11 +188,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Gets the appropriate prefix for the user. * Gets the appropriate prefix for the user. This method is a utility method
* This method is a utility method for chat plugins to get the user's prefix * for chat plugins to get the user's prefix without having to look at every
* without having to look at every one of the user's ancestors. * one of the user's ancestors. Returns an empty string if user has no
* Returns an empty string if user has no parent groups. * parent groups.
* @param user Player's name *
* @param user
* Player's name
* @return Player's prefix * @return Player's prefix
*/ */
@Override @Override
@ -201,10 +210,12 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Gets name of the primary group of the user. * Gets name of the primary group of the user. Returns the name of the
* Returns the name of the default group if user has no parent groups, * default group if user has no parent groups, or "Default" if there is no
* or "Default" if there is no default group for that world. * default group for that world.
* @param user Player's name *
* @param user
* Player's name
* @return Name of player's primary group * @return Name of player's primary group
*/ */
public String getPrimaryGroup(String user) { public String getPrimaryGroup(String user) {
@ -215,8 +226,11 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Check if user can build. * Check if user can build.
* @param world Player's world *
* @param user Player's name * @param world
* Player's world
* @param user
* Player's name
* @return Whether the user can build * @return Whether the user can build
*/ */
public boolean canUserBuild(String user) { public boolean canUserBuild(String user) {
@ -232,6 +246,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the String prefix for the given group * Returns the String prefix for the given group
*
* @param groupName * @param groupName
* @return empty string if found none. * @return empty string if found none.
*/ */
@ -246,6 +261,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Return the suffix for the given group name * Return the suffix for the given group name
*
* @param groupName * @param groupName
* @return * @return
*/ */
@ -273,8 +289,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* It returns a string variable value, set in the INFO node of the group. * It returns a string variable value, set in the INFO node of the group. It
* It will harvest inheritance for value. * will harvest inheritance for value.
*
* @param groupName * @param groupName
* @param variable * @param variable
* @return null if no group with that variable is found. * @return null if no group with that variable is found.
@ -293,8 +310,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* It returns a Integer variable value * It returns a Integer variable value It will harvest inheritance for
* It will harvest inheritance for value. * value.
*
* @param groupName * @param groupName
* @param variable * @param variable
* @return -1 if none found or not parseable. * @return -1 if none found or not parseable.
@ -313,8 +331,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns a boolean for given variable in INFO node. * Returns a boolean for given variable in INFO node. It will harvest
* It will harvest inheritance for value. * inheritance for value.
*
* @param group * @param group
* @param variable * @param variable
* @return false if not found/not parseable. * @return false if not found/not parseable.
@ -333,8 +352,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns a double value for the given variable name in INFO node. * Returns a double value for the given variable name in INFO node. It will
* It will harvest inheritance for value. * harvest inheritance for value.
*
* @param group * @param group
* @param variable * @param variable
* @return -1 if not found / not parseable. * @return -1 if not found / not parseable.
@ -354,6 +374,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -369,6 +390,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -384,6 +406,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -399,6 +422,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -413,9 +437,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return empty string if not found * @return empty string if not found
@ -438,13 +462,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return ""; return "";
} }
return result.getVariables().getVarString(variable); return result.getVariables().getVarString(variable);
//return getUserPermissionString(user, variable); // return getUserPermissionString(user, variable);
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return -1 if not found * @return -1 if not found
@ -467,13 +491,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return -1; return -1;
} }
return result.getVariables().getVarInteger(variable); return result.getVariables().getVarInteger(variable);
//return getUserPermissionInteger(string, string1); // return getUserPermissionInteger(string, string1);
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return false if not found or not parseable to true. * @return false if not found or not parseable to true.
@ -496,13 +520,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return false; return false;
} }
return result.getVariables().getVarBoolean(variable); return result.getVariables().getVarBoolean(variable);
//return getUserPermissionBoolean(user, string1); // return getUserPermissionBoolean(user, string1);
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return -1 if not found. * @return -1 if not found.
@ -525,11 +549,12 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return -1.0D; return -1.0D;
} }
return result.getVariables().getVarDouble(variable); return result.getVariables().getVarDouble(variable);
//return getUserPermissionDouble(string, string1); // return getUserPermissionDouble(string, string1);
} }
/** /**
* Does not include User's group permission * Does not include User's group permission
*
* @param user * @param user
* @param permission * @param permission
* @return * @return
@ -557,8 +582,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns the node responsible for that permission. * Returns the node responsible for that permission. Does not include User's
* Does not include User's group permission. * group permission.
*
* @param group * @param group
* @param permission * @param permission
* @return the node if permission is found. if not found, return null * @return the node if permission is found. if not found, return null
@ -587,14 +613,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Check permissions, including it's group and inheritance. * Check permissions, including it's group and inheritance.
*
* @param user * @param user
* @param permission * @param permission
* @return true if permission was found. false if not, or was negated. * @return true if permission was found. false if not, or was negated.
*/ */
public boolean checkUserPermission(User user, String permission) { public boolean checkUserPermission(User user, String permission) {
PermissionCheckResult result = checkFullUserPermission(user, permission); PermissionCheckResult result = checkFullUserPermission(user, permission);
if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION) if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
|| result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
return true; return true;
} }
if (Bukkit.getPlayer(user.getName()).hasPermission(permission)) if (Bukkit.getPlayer(user.getName()).hasPermission(permission))
@ -604,7 +630,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Do what checkUserPermission did before. But now returning a PermissionCheckResult. * Do what checkUserPermission did before. But now returning a
* PermissionCheckResult.
*
* @param user * @param user
* @param targetPermission * @param targetPermission
* @return * @return
@ -623,13 +651,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return resultUser; return resultUser;
} }
//IT ONLY CHECKS GROUPS PERMISSIONS IF RESULT FOR USER IS NOT FOUND // IT ONLY CHECKS GROUPS PERMISSIONS IF RESULT FOR USER IS NOT FOUND
PermissionCheckResult resultGroup = checkGroupPermissionWithInheritance(user.getGroup(), targetPermission); PermissionCheckResult resultGroup = checkGroupPermissionWithInheritance(user.getGroup(), targetPermission);
if (!resultGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) { if (!resultGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
return resultGroup; return resultGroup;
} }
//SUBGROUPS CHECK // SUBGROUPS CHECK
for (Group subGroup : user.subGroupListCopy()) { for (Group subGroup : user.subGroupListCopy()) {
PermissionCheckResult resultSubGroup = checkGroupPermissionWithInheritance(subGroup, targetPermission); PermissionCheckResult resultSubGroup = checkGroupPermissionWithInheritance(subGroup, targetPermission);
if (!resultSubGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) { if (!resultSubGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
@ -643,7 +671,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return result; return result;
} }
//THEN IT RETURNS A NOT FOUND // THEN IT RETURNS A NOT FOUND
return result; return result;
} }
@ -657,7 +685,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* @param variable * @param variable
* @param alreadyChecked * @param alreadyChecked
* @return returns the closest inherited group with the variable. * @return returns the closest inherited group with the variable.
* @deprecated use now nextGroupWithVariable(Group start, String targetVariable) * @deprecated use now nextGroupWithVariable(Group start, String
* targetVariable)
*/ */
@Deprecated @Deprecated
public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) { public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) {
@ -670,8 +699,10 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* *
* It does Breadth-first search * It does Breadth-first search
* *
* @param start the starting group to look for * @param start
* @param targetVariable the variable name * the starting group to look for
* @param targetVariable
* the variable name
* @return The group if found. Null if not. * @return The group if found. Null if not.
*/ */
public Group nextGroupWithVariable(Group start, String targetVariable) { public Group nextGroupWithVariable(Group start, String targetVariable) {
@ -704,11 +735,15 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* redirected to the other method. this is deprecated now. and will be gone * redirected to the other method. this is deprecated now. and will be gone
* in the future releases. * in the future releases.
* *
* @param start The group to start the search. * @param start
* @param askedGroup Name of the group you're looking for * The group to start the search.
* @param alreadyChecked groups to ignore(pass null on it, please) * @param askedGroup
* Name of the group you're looking for
* @param alreadyChecked
* groups to ignore(pass null on it, please)
* @return true if it inherits the group. * @return true if it inherits the group.
* @deprecated prefer using hasGroupInInheritance(Group start, String askedGroup) * @deprecated prefer using hasGroupInInheritance(Group start, String
* askedGroup)
*/ */
@Deprecated @Deprecated
public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) { public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) {
@ -720,8 +755,10 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* *
* It does Breadth-first search * It does Breadth-first search
* *
* @param start The group to start the search. * @param start
* @param askedGroup Name of the group you're looking for * The group to start the search.
* @param askedGroup
* Name of the group you're looking for
* @return true if it inherits the group. * @return true if it inherits the group.
*/ */
public boolean hasGroupInInheritance(Group start, String askedGroup) { public boolean hasGroupInInheritance(Group start, String askedGroup) {
@ -750,30 +787,30 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Check if the group has given permission. Including it's inheritance * Check if the group has given permission. Including it's inheritance
*
* @param start * @param start
* @param permission * @param permission
* @param alreadyChecked * @param alreadyChecked
* @return true if PermissionCheckResult is EXCEPTION or FOUND * @return true if PermissionCheckResult is EXCEPTION or FOUND
* @deprecated use the other checkGroupPermissionWithInheritance for everything * @deprecated use the other checkGroupPermissionWithInheritance for
* everything
*/ */
@Deprecated @Deprecated
public boolean checkGroupPermissionWithInheritance(Group start, String permission, List<Group> alreadyChecked) { public boolean checkGroupPermissionWithInheritance(Group start, String permission, List<Group> alreadyChecked) {
PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
if (result.resultType.equals(Type.EXCEPTION) if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
|| result.resultType.equals(Type.FOUND)) {
return true; return true;
} }
return false; return false;
} }
/** /**
* Returns the result of permission check. Including inheritance. * Returns the result of permission check. Including inheritance. If found
* If found anything, the PermissionCheckResult that retuns will * anything, the PermissionCheckResult that retuns will include the Group
* include the Group name, and the result type. * name, and the result type. Result types will be EXCEPTION, NEGATION,
* Result types will be EXCEPTION, NEGATION, FOUND. * FOUND.
* *
* If returned type NOTFOUND, the owner will be null, * If returned type NOTFOUND, the owner will be null, and ownerType too.
* and ownerType too.
* *
* It does Breadth-first search * It does Breadth-first search
* *
@ -810,8 +847,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* It uses checkGroupPermissionWithInheritance * It uses checkGroupPermissionWithInheritance and cast the owner to Group
* and cast the owner to Group type if result type was EXCEPTION or FOUND. * type if result type was EXCEPTION or FOUND.
* *
* @param start * @param start
* @param permission * @param permission
@ -822,8 +859,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
@Deprecated @Deprecated
public Group nextGroupWithPermission(Group start, String permission, List<Group> alreadyChecked) { public Group nextGroupWithPermission(Group start, String permission, List<Group> alreadyChecked) {
PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
if (result.resultType.equals(Type.EXCEPTION) if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
|| result.resultType.equals(Type.FOUND)) {
return (Group) checkGroupPermissionWithInheritance(start, permission).owner; return (Group) checkGroupPermissionWithInheritance(start, permission).owner;
} }
return null; return null;
@ -833,8 +869,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* Return whole list of names of groups in a inheritance chain. Including a * Return whole list of names of groups in a inheritance chain. Including a
* starting group. * starting group.
* *
* it now redirects to the other method. but get away from this one, * it now redirects to the other method. but get away from this one, it will
* it will disappear in a future release. * disappear in a future release.
* *
* @param start * @param start
* @param alreadyChecked * @param alreadyChecked
@ -878,17 +914,17 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Compare a user permission like 'myplugin.*' against a full plugin * Compare a user permission like 'myplugin.*' against a full plugin
* permission name, like 'myplugin.dosomething'. * permission name, like 'myplugin.dosomething'. As the example above, will
* As the example above, will return true. * return true.
* *
* Please sort permissions before sending them here. So negative tokens * Please sort permissions before sending them here. So negative tokens get
* get priority. * priority.
* *
* You must test if it start with negative outside this method. It will * You must test if it start with negative outside this method. It will only
* only tell if the nodes are matching or not. * tell if the nodes are matching or not.
* *
* Every '-' or '+' in the beginning is ignored. It will match only * Every '-' or '+' in the beginning is ignored. It will match only node
* node names. * names.
* *
* @param userAcessLevel * @param userAcessLevel
* @param fullPermissionName * @param fullPermissionName
@ -912,7 +948,6 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
fullPermissionName = fullPermissionName.substring(1); fullPermissionName = fullPermissionName.substring(1);
} }
StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, "."); StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, ".");
StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, "."); StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, ".");
while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) { while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) {
@ -944,6 +979,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* Returns a list of all groups. * Returns a list of all groups.
* *
* Including subgroups. * Including subgroups.
*
* @param userName * @param userName
* @return * @return
*/ */
@ -961,8 +997,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* A Breadth-first search thru inheritance model. * A Breadth-first search thru inheritance model.
* *
* Just a model to copy and paste. * Just a model to copy and paste. This will guarantee the closer groups
* This will guarantee the closer groups will be checked first. * will be checked first.
*
* @param start * @param start
* @param targerPermission * @param targerPermission
* @return * @return
@ -979,8 +1016,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
while (!stack.isEmpty()) { while (!stack.isEmpty()) {
Group now = stack.pop(); Group now = stack.pop();
PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targerPermission); PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targerPermission);
if (resultNow.resultType.equals(PermissionCheckResult.Type.EXCEPTION) if (resultNow.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || resultNow.resultType.equals(PermissionCheckResult.Type.FOUND)) {
|| resultNow.resultType.equals(PermissionCheckResult.Type.FOUND)) {
return now; return now;
} }
if (resultNow.resultType.equals(PermissionCheckResult.Type.NEGATION)) { if (resultNow.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
@ -1003,8 +1039,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public String getInfoString(String entryName, String path, public String getInfoString(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {
@ -1021,8 +1056,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public int getInfoInteger(String entryName, String path, public int getInfoInteger(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {
@ -1039,8 +1073,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public double getInfoDouble(String entryName, String path, public double getInfoDouble(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {
@ -1058,8 +1091,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public boolean getInfoBoolean(String entryName, String path, public boolean getInfoBoolean(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {