Add Bukkit child permissions to the PermissionRegistry

This commit is contained in:
Luck 2021-05-06 12:23:09 +01:00
parent 528d668bc6
commit 1511193e58
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 25 additions and 7 deletions

View File

@ -241,6 +241,10 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
NotifyingChildrenMap(Map<String, Boolean> delegate) {
this.delegate = delegate;
for (String key : this.delegate.keySet()) {
LuckPermsPermissionMap.this.plugin.getPermissionRegistry().insert(key);
}
}
@Override
@ -251,6 +255,7 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
@Override
public Boolean put(@NonNull String key, @NonNull Boolean value) {
Boolean ret = super.put(key, value);
LuckPermsPermissionMap.this.plugin.getPermissionRegistry().insert(key);
LuckPermsPermissionMap.this.update();
return ret;
}
@ -258,6 +263,9 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
@Override
public void putAll(@NonNull Map<? extends String, ? extends Boolean> map) {
super.putAll(map);
for (String key : map.keySet()) {
LuckPermsPermissionMap.this.plugin.getPermissionRegistry().insert(key);
}
LuckPermsPermissionMap.this.update();
}

View File

@ -93,6 +93,8 @@ public class PermissionRegistry implements AutoCloseable {
}
private void doInsert(String permission) {
permission = permission.toLowerCase();
// split the permission up into parts
Iterable<String> parts = DOT_SPLIT.split(permission);

View File

@ -206,11 +206,11 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
try {
//noinspection unchecked
Map<String, Boolean> children = (Map<String, Boolean>) PERMISSION_CHILDREN_FIELD.get(permission);
while (children instanceof PermissionNotifyingChildrenMap) {
children = ((PermissionNotifyingChildrenMap) children).delegate;
while (children instanceof NotifyingChildrenMap) {
children = ((NotifyingChildrenMap) children).delegate;
}
PermissionNotifyingChildrenMap notifyingChildren = new PermissionNotifyingChildrenMap(children);
NotifyingChildrenMap notifyingChildren = new NotifyingChildrenMap(children);
PERMISSION_CHILDREN_FIELD.set(permission, notifyingChildren);
} catch (Exception e) {
e.printStackTrace();
@ -226,8 +226,8 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
try {
//noinspection unchecked
Map<String, Boolean> children = (Map<String, Boolean>) PERMISSION_CHILDREN_FIELD.get(permission);
while (children instanceof PermissionNotifyingChildrenMap) {
children = ((PermissionNotifyingChildrenMap) children).delegate;
while (children instanceof NotifyingChildrenMap) {
children = ((NotifyingChildrenMap) children).delegate;
}
PERMISSION_CHILDREN_FIELD.set(permission, children);
} catch (Exception e) {
@ -236,11 +236,15 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
return permission;
}
private final class PermissionNotifyingChildrenMap extends ForwardingMap<String, Boolean> {
private final class NotifyingChildrenMap extends ForwardingMap<String, Boolean> {
private final Map<String, Boolean> delegate;
PermissionNotifyingChildrenMap(Map<String, Boolean> delegate) {
NotifyingChildrenMap(Map<String, Boolean> delegate) {
this.delegate = delegate;
for (String key : this.delegate.keySet()) {
LuckPermsPermissionMap.this.plugin.getPermissionRegistry().insert(key);
}
}
@Override
@ -251,6 +255,7 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
@Override
public Boolean put(@NonNull String key, @NonNull Boolean value) {
Boolean ret = super.put(key, value);
LuckPermsPermissionMap.this.plugin.getPermissionRegistry().insert(key);
LuckPermsPermissionMap.this.update();
return ret;
}
@ -258,6 +263,9 @@ public final class LuckPermsPermissionMap extends ForwardingMap<String, Permissi
@Override
public void putAll(@NonNull Map<? extends String, ? extends Boolean> map) {
super.putAll(map);
for (String key : map.keySet()) {
LuckPermsPermissionMap.this.plugin.getPermissionRegistry().insert(key);
}
LuckPermsPermissionMap.this.update();
}