fix logic and some cleaning

This commit is contained in:
muhammadeko 2022-05-14 11:32:33 +07:00 committed by Melledy
parent c7849c0462
commit c0d79aa75b

View File

@ -144,24 +144,22 @@ public class Account {
} }
public boolean hasPermission(String permission) { public boolean hasPermission(String permission) {
if (this.permissions.contains(permission)) {
return true; if (this.permissions.contains(permission)) return true;
} if(this.permissions.contains("*") && this.permissions.size() == 1) return true;
if(this.permissions.contains("*") && this.permissions.contains("-"+permission)) {
return false;
}
String[] permissionParts = permission.split("\\."); String[] permissionParts = permission.split("\\.");
for (String p : this.permissions) { for (String p : this.permissions) {
if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) { if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) {
Grasscutter.getLogger().info("Permission " + permission + " denied to " + this.username);
return false; return false;
} }
if (permissionMatchesWildcard(p, permissionParts)) {
Grasscutter.getLogger().info("Permission " + p + " matches " + permission); if (permissionMatchesWildcard(p, permissionParts)) return true;
return true;
}
} }
return false;
return this.permissions.contains("*");
} }
public boolean removePermission(String permission) { public boolean removePermission(String permission) {