summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager
diff options
context:
space:
mode:
authorElgarL <ElgarL@palmergames.com>2011-11-24 15:57:21 +0000
committerElgarL <ElgarL@palmergames.com>2011-11-24 15:57:21 +0000
commit127681736de3e985c85acf4d7e1a61207f629033 (patch)
tree6418820aafaec27c97c86c6f2c07d42036a7ca9c /EssentialsGroupManager
parent73a7a6a1ddbddb294254b0d271a2928509db574f (diff)
downloadEssentials-127681736de3e985c85acf4d7e1a61207f629033.tar
Essentials-127681736de3e985c85acf4d7e1a61207f629033.tar.gz
Essentials-127681736de3e985c85acf4d7e1a61207f629033.tar.lz
Essentials-127681736de3e985c85acf4d7e1a61207f629033.tar.xz
Essentials-127681736de3e985c85acf4d7e1a61207f629033.zip
rewrite of comparePermissionString (snowleo)
Diffstat (limited to 'EssentialsGroupManager')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java80
1 files changed, 28 insertions, 52 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
index 94052bb25..66561a1b8 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
@@ -966,59 +966,35 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* @param fullPermissionName
* @return true if found a matching token. false if not.
*/
- public boolean comparePermissionString(String userAcessLevel, String fullPermissionName) {
- if (userAcessLevel == null || fullPermissionName == null) {
- return false;
- }
- boolean logFinest = (GroupManager.logger.getLevel() == Level.FINEST);
-
- if (logFinest)
- GroupManager.logger.finest("COMPARING " + userAcessLevel + " WITH " + fullPermissionName);
-
- if (userAcessLevel.startsWith("+")) {
- userAcessLevel = userAcessLevel.substring(1);
- } else if (userAcessLevel.startsWith("-")) {
- userAcessLevel = userAcessLevel.substring(1);
- }
-
- if (fullPermissionName.startsWith("+")) {
- fullPermissionName = fullPermissionName.substring(1);
- } else if (fullPermissionName.startsWith("-")) {
- fullPermissionName = fullPermissionName.substring(1);
- }
+ public boolean comparePermissionString(String userAccessLevel, String fullPermissionName) {
+ int userAccessLevelLength;
+ if (userAccessLevel == null || fullPermissionName == null
+ || (userAccessLevelLength = userAccessLevel.length()) == 0 || fullPermissionName.length() == 0) {
+ return false;
+ }
+
+ int userAccessLevelOffset;
+ if (userAccessLevel.charAt(0) == '+' || userAccessLevel.charAt(0) == '-') {
+ userAccessLevelOffset = 1;
+ } else {
+ userAccessLevelOffset = 0;
+ }
+ if ("*".regionMatches(0, userAccessLevel, userAccessLevelOffset, userAccessLevelLength - userAccessLevelOffset)) {
+ return true;
+ }
+ int fullPermissionNameOffset;
+ if (fullPermissionName.charAt(0) == '+' || fullPermissionName.charAt(0) == '-') {
+ fullPermissionNameOffset = 1;
+ } else {
+ fullPermissionNameOffset = 0;
+ }
+
+ if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
+ userAccessLevelLength--;
+ }
+ return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset);
+ }
- StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, ".");
- StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, ".");
- while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) {
- String levelA = levelATokenizer.nextToken();
- String levelB = levelBTokenizer.nextToken();
- if (logFinest)
- GroupManager.logger.finest("ROUND " + levelA + " AGAINST " + levelB);
- if (levelA.contains("*")) {
- if (logFinest)
- GroupManager.logger.finest("WIN");
- return true;
- }
- if (levelA.equalsIgnoreCase(levelB)) {
- if (!levelATokenizer.hasMoreTokens() && !levelBTokenizer.hasMoreTokens()) {
- if (logFinest)
- GroupManager.logger.finest("WIN");
- return true;
- }
- if (logFinest)
- GroupManager.logger.finest("NEXT");
- continue;
- } else {
- if (logFinest)
- GroupManager.logger.finest("FAIL");
- return false;
- }
-
- }
- if (logFinest)
- GroupManager.logger.finest("FAIL");
- return false;
- }
/**
* Returns a list of all groups.