mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
Reverse order of wildcard permission check, respect explicit values (#85)
This commit is contained in:
parent
f5dce23f18
commit
8ce6e2f8d3
1 changed files with 22 additions and 18 deletions
|
@ -25,9 +25,9 @@ public enum Permissions {
|
||||||
EXEMPT("exempt"),
|
EXEMPT("exempt"),
|
||||||
CROSSWORLD("crossworld"),
|
CROSSWORLD("crossworld"),
|
||||||
SILENT("silent"),
|
SILENT("silent"),
|
||||||
SILENT_DEFAULT("silent", "default"),
|
SILENT_DEFAULT("silent.default"),
|
||||||
ANYCHEST("anychest"),
|
ANYCHEST("anychest"),
|
||||||
ANY_DEFAULT("any", "default"),
|
ANY_DEFAULT("any.default"),
|
||||||
ENDERCHEST("openender"),
|
ENDERCHEST("openender"),
|
||||||
ENDERCHEST_ALL("openenderall"),
|
ENDERCHEST_ALL("openenderall"),
|
||||||
SEARCH("search"),
|
SEARCH("search"),
|
||||||
|
@ -35,31 +35,35 @@ public enum Permissions {
|
||||||
EDITENDER("editender"),
|
EDITENDER("editender"),
|
||||||
OPENSELF("openself");
|
OPENSELF("openself");
|
||||||
|
|
||||||
private final String[] permission;
|
private final String permission;
|
||||||
|
|
||||||
Permissions(String... permissions) {
|
Permissions(String permission) {
|
||||||
this.permission = new String[permissions.length + 1];
|
this.permission = "OpenInv." + permission;
|
||||||
this.permission[0] = "OpenInv";
|
|
||||||
System.arraycopy(permissions, 0, this.permission, 1, permissions.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPermission(Permissible permissible) {
|
public boolean hasPermission(Permissible permissible) {
|
||||||
StringBuilder permissionBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
// Support wildcard nodes.
|
boolean hasPermission = permissible.hasPermission(permission);
|
||||||
for (int i = 0; i < permission.length; i++) {
|
if (hasPermission || permissible.isPermissionSet(permission)) {
|
||||||
if (permissible.hasPermission(permissionBuilder.toString() + "*")) {
|
return hasPermission;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
permissionBuilder.append(permission[i]).append('.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete trailing period.
|
StringBuilder permissionDestroyer = new StringBuilder(permission);
|
||||||
if (permissionBuilder.length() > 0) {
|
for (int lastPeriod = permissionDestroyer.lastIndexOf("."); lastPeriod > 0;
|
||||||
permissionBuilder.deleteCharAt(permissionBuilder.length() - 1);
|
lastPeriod = permissionDestroyer.lastIndexOf(".")) {
|
||||||
|
permissionDestroyer.delete(lastPeriod + 1, permissionDestroyer.length()).append('*');
|
||||||
|
|
||||||
|
hasPermission = permissible.hasPermission(permissionDestroyer.toString());
|
||||||
|
if (hasPermission || permissible.isPermissionSet(permissionDestroyer.toString())) {
|
||||||
|
return hasPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
return permissible.hasPermission(permissionBuilder.toString());
|
permissionDestroyer.delete(lastPeriod, permissionDestroyer.length());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return permissible.hasPermission("*");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue