Fix bukkit child permission handling to not include permissions with no children & cleanup permission registration
This commit is contained in:
parent
abddb265be
commit
89ff3b169b
@ -24,8 +24,6 @@ package me.lucko.luckperms.bukkit;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.Logger;
|
import me.lucko.luckperms.api.Logger;
|
||||||
import me.lucko.luckperms.api.LuckPermsApi;
|
import me.lucko.luckperms.api.LuckPermsApi;
|
||||||
@ -153,7 +151,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
defaultsProvider = new DefaultsProvider();
|
defaultsProvider = new DefaultsProvider();
|
||||||
childPermissionProvider = new ChildPermissionProvider();
|
childPermissionProvider = new ChildPermissionProvider();
|
||||||
|
|
||||||
// give all plugins a chance to load their defaults, then refresh.
|
// give all plugins a chance to load their permissions, then refresh.
|
||||||
scheduler.doSyncLater(() -> {
|
scheduler.doSyncLater(() -> {
|
||||||
defaultsProvider.refresh();
|
defaultsProvider.refresh();
|
||||||
childPermissionProvider.setup();
|
childPermissionProvider.setup();
|
||||||
@ -164,21 +162,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
perms.addAll(p.getChildren().keySet());
|
perms.addAll(p.getChildren().keySet());
|
||||||
});
|
});
|
||||||
|
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
|
||||||
defaultsProvider.getOpDefaults().entrySet().stream().map(Map.Entry::getKey).forEach(e -> permissionVault.offer(e));
|
|
||||||
defaultsProvider.getNonOpDefaults().entrySet().stream().map(Map.Entry::getKey).forEach(e -> permissionVault.offer(e));
|
|
||||||
|
|
||||||
perms.forEach(p -> permissionVault.offer(p));
|
perms.forEach(p -> permissionVault.offer(p));
|
||||||
|
|
||||||
ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = childPermissionProvider.getPermissions();
|
|
||||||
for (Map.Entry<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
|
|
||||||
permissionVault.offer(e.getKey().getKey());
|
|
||||||
for (Map.Entry<String, Boolean> e1 : e.getValue().entrySet()) {
|
|
||||||
permissionVault.offer(e1.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}, 1L);
|
}, 1L);
|
||||||
|
|
||||||
// register events
|
// register events
|
||||||
|
@ -40,21 +40,27 @@ public class ChildPermissionProvider {
|
|||||||
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Map<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = new HashMap<>();
|
ImmutableMap.Builder<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.builder();
|
||||||
|
|
||||||
for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) {
|
for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) {
|
||||||
// handle true
|
// handle true
|
||||||
Map<String, Boolean> trueChildren = new HashMap<>();
|
Map<String, Boolean> trueChildren = new HashMap<>();
|
||||||
resolveChildren(trueChildren, Collections.singletonMap(permission.getName(), true), false);
|
resolveChildren(trueChildren, Collections.singletonMap(permission.getName(), true), false);
|
||||||
|
trueChildren.remove(permission.getName(), true);
|
||||||
|
if (!trueChildren.isEmpty()) {
|
||||||
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(trueChildren));
|
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(trueChildren));
|
||||||
|
}
|
||||||
|
|
||||||
// handle false
|
// handle false
|
||||||
Map<String, Boolean> falseChildren = new HashMap<>();
|
Map<String, Boolean> falseChildren = new HashMap<>();
|
||||||
resolveChildren(falseChildren, Collections.singletonMap(permission.getName(), false), false);
|
resolveChildren(falseChildren, Collections.singletonMap(permission.getName(), false), false);
|
||||||
|
falseChildren.remove(permission.getName(), false);
|
||||||
|
if (!falseChildren.isEmpty()) {
|
||||||
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false), ImmutableMap.copyOf(falseChildren));
|
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false), ImmutableMap.copyOf(falseChildren));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.permissions = ImmutableMap.copyOf(permissions);
|
this.permissions = permissions.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
|
private static void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
|
||||||
|
Loading…
Reference in New Issue
Block a user