From c0d79aa75b85a0492c9b2e6f67a3c8b39524661f Mon Sep 17 00:00:00 2001 From: muhammadeko Date: Sat, 14 May 2022 11:32:33 +0700 Subject: [PATCH] fix logic and some cleaning --- .../java/emu/grasscutter/game/Account.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 39fb8969e..518bd4786 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -144,24 +144,22 @@ public class Account { } public boolean hasPermission(String permission) { - if (this.permissions.contains(permission)) { - return true; - } - if(this.permissions.contains("*") && this.permissions.contains("-"+permission)) { - return false; - } + + if (this.permissions.contains(permission)) return true; + if(this.permissions.contains("*") && this.permissions.size() == 1) return true; String[] permissionParts = permission.split("\\."); for (String p : this.permissions) { + if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) { + Grasscutter.getLogger().info("Permission " + permission + " denied to " + this.username); return false; } - if (permissionMatchesWildcard(p, permissionParts)) { - Grasscutter.getLogger().info("Permission " + p + " matches " + permission); - return true; - } + + if (permissionMatchesWildcard(p, permissionParts)) return true; } - return false; + + return this.permissions.contains("*"); } public boolean removePermission(String permission) {