mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-08-26 07:22:56 +02:00
rewrite of comparePermissionString (snowleo)
This commit is contained in:
parent
73a7a6a1dd
commit
127681736d
|
@ -966,59 +966,35 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||||
* @param fullPermissionName
|
* @param fullPermissionName
|
||||||
* @return true if found a matching token. false if not.
|
* @return true if found a matching token. false if not.
|
||||||
*/
|
*/
|
||||||
public boolean comparePermissionString(String userAcessLevel, String fullPermissionName) {
|
public boolean comparePermissionString(String userAccessLevel, String fullPermissionName) {
|
||||||
if (userAcessLevel == null || fullPermissionName == null) {
|
int userAccessLevelLength;
|
||||||
return false;
|
if (userAccessLevel == null || fullPermissionName == null
|
||||||
}
|
|| (userAccessLevelLength = userAccessLevel.length()) == 0 || fullPermissionName.length() == 0) {
|
||||||
boolean logFinest = (GroupManager.logger.getLevel() == Level.FINEST);
|
return false;
|
||||||
|
}
|
||||||
if (logFinest)
|
|
||||||
GroupManager.logger.finest("COMPARING " + userAcessLevel + " WITH " + fullPermissionName);
|
|
||||||
|
|
||||||
if (userAcessLevel.startsWith("+")) {
|
int userAccessLevelOffset;
|
||||||
userAcessLevel = userAcessLevel.substring(1);
|
if (userAccessLevel.charAt(0) == '+' || userAccessLevel.charAt(0) == '-') {
|
||||||
} else if (userAcessLevel.startsWith("-")) {
|
userAccessLevelOffset = 1;
|
||||||
userAcessLevel = userAcessLevel.substring(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 (fullPermissionName.startsWith("+")) {
|
if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
|
||||||
fullPermissionName = fullPermissionName.substring(1);
|
userAccessLevelLength--;
|
||||||
} else if (fullPermissionName.startsWith("-")) {
|
}
|
||||||
fullPermissionName = fullPermissionName.substring(1);
|
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.
|
* Returns a list of all groups.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user