mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
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 com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
@ -153,7 +151,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
defaultsProvider = new DefaultsProvider();
|
||||
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(() -> {
|
||||
defaultsProvider.refresh();
|
||||
childPermissionProvider.setup();
|
||||
@ -164,21 +162,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
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));
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
perms.forEach(p -> permissionVault.offer(p));
|
||||
}, 1L);
|
||||
|
||||
// register events
|
||||
|
@ -40,21 +40,27 @@ public class ChildPermissionProvider {
|
||||
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
||||
|
||||
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()) {
|
||||
// handle true
|
||||
Map<String, Boolean> trueChildren = new HashMap<>();
|
||||
resolveChildren(trueChildren, Collections.singletonMap(permission.getName(), true), false);
|
||||
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(trueChildren));
|
||||
trueChildren.remove(permission.getName(), true);
|
||||
if (!trueChildren.isEmpty()) {
|
||||
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(trueChildren));
|
||||
}
|
||||
|
||||
// handle false
|
||||
Map<String, Boolean> falseChildren = new HashMap<>();
|
||||
resolveChildren(falseChildren, Collections.singletonMap(permission.getName(), false), false);
|
||||
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false), ImmutableMap.copyOf(falseChildren));
|
||||
falseChildren.remove(permission.getName(), false);
|
||||
if (!falseChildren.isEmpty()) {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user