From 89ff3b169b9cea33c4495f939d411e17350b79aa Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 18 Feb 2017 21:01:09 +0000 Subject: [PATCH] Fix bukkit child permission handling to not include permissions with no children & cleanup permission registration --- .../luckperms/bukkit/LPBukkitPlugin.java | 20 ++----------------- .../bukkit/model/ChildPermissionProvider.java | 14 +++++++++---- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 03349cdde..79c2e5855 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -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, ImmutableMap> permissions = childPermissionProvider.getPermissions(); - for (Map.Entry, ImmutableMap> e : permissions.entrySet()) { - permissionVault.offer(e.getKey().getKey()); - for (Map.Entry e1 : e.getValue().entrySet()) { - permissionVault.offer(e1.getKey()); - } - } - }); - + perms.forEach(p -> permissionVault.offer(p)); }, 1L); // register events diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java index 6dc0287d7..79cb61b5f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java @@ -40,21 +40,27 @@ public class ChildPermissionProvider { private ImmutableMap, ImmutableMap> permissions = ImmutableMap.of(); public void setup() { - Map, ImmutableMap> permissions = new HashMap<>(); + ImmutableMap.Builder, ImmutableMap> permissions = ImmutableMap.builder(); for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) { // handle true Map 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 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 accumulator, Map children, boolean invert) {