From f82dfdc7174fd000d4af6789699e7ae7e6399af2 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sun, 4 Sep 2011 00:23:50 +0100 Subject: [PATCH] Don't lazy-load in PermissibleBase. This'll be a performance hit, but it's causing subscription issues. By: Dinnerbone --- .../bukkit/permissions/PermissibleBase.java | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java b/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java index ec6fb6ca33..6bf0e51014 100644 --- a/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java +++ b/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java @@ -18,7 +18,6 @@ public class PermissibleBase implements Permissible { private Permissible parent = this; private final List attachments = new LinkedList(); private final Map permissions = new HashMap(); - private boolean dirtyPermissions = true; public PermissibleBase(ServerOperator opable) { this.opable = opable; @@ -27,7 +26,7 @@ public class PermissibleBase implements Permissible { this.parent = (Permissible)opable; } - calculatePermissions(); + recalculatePermissions(); } public boolean isOp() { @@ -51,8 +50,6 @@ public class PermissibleBase implements Permissible { throw new IllegalArgumentException("Permission name cannot be null"); } - calculatePermissions(); - return permissions.containsKey(name.toLowerCase()); } @@ -69,8 +66,6 @@ public class PermissibleBase implements Permissible { throw new IllegalArgumentException("Permission name cannot be null"); } - calculatePermissions(); - String name = inName.toLowerCase(); if (isPermissionSet(name)) { @@ -91,8 +86,6 @@ public class PermissibleBase implements Permissible { throw new IllegalArgumentException("Permission cannot be null"); } - calculatePermissions(); - String name = perm.getName().toLowerCase(); if (isPermissionSet(name)) { @@ -156,27 +149,19 @@ public class PermissibleBase implements Permissible { } public void recalculatePermissions() { - dirtyPermissions = true; - } + clearPermissions(); + Set defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp()); + Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent); - public synchronized void calculatePermissions() { - if (dirtyPermissions) { - clearPermissions(); - Set defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp()); - Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent); + for (Permission perm : defaults) { + String name = perm.getName().toLowerCase(); + permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true)); + Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); + calculateChildPermissions(perm.getChildren(), false, null); + } - for (Permission perm : defaults) { - String name = perm.getName().toLowerCase(); - permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true)); - Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); - calculateChildPermissions(perm.getChildren(), false, null); - } - - for (PermissionAttachment attachment : attachments) { - calculateChildPermissions(attachment.getPermissions(), false, attachment); - } - - dirtyPermissions = false; + for (PermissionAttachment attachment : attachments) { + calculateChildPermissions(attachment.getPermissions(), false, attachment); } } @@ -187,7 +172,8 @@ public class PermissibleBase implements Permissible { Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent); } - Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(isOp(), parent); + Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent); + Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent); permissions.clear(); } @@ -246,7 +232,6 @@ public class PermissibleBase implements Permissible { } public Set getEffectivePermissions() { - calculatePermissions(); return new HashSet(permissions.values()); }