mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-21 02:42:01 +00:00
rewrite of comparePermissionString (snowleo)
This commit is contained in:
parent
73a7a6a1dd
commit
127681736d
|
@ -966,60 +966,36 @@ 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) {
|
||||
public boolean comparePermissionString(String userAccessLevel, String fullPermissionName) {
|
||||
int userAccessLevelLength;
|
||||
if (userAccessLevel == null || fullPermissionName == null
|
||||
|| (userAccessLevelLength = userAccessLevel.length()) == 0 || fullPermissionName.length() == 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
int userAccessLevelOffset;
|
||||
if (userAccessLevel.charAt(0) == '+' || userAccessLevel.charAt(0) == '-') {
|
||||
userAccessLevelOffset = 1;
|
||||
} else {
|
||||
if (logFinest)
|
||||
GroupManager.logger.finest("FAIL");
|
||||
return false;
|
||||
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--;
|
||||
}
|
||||
if (logFinest)
|
||||
GroupManager.logger.finest("FAIL");
|
||||
return false;
|
||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of all groups.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue