Don't lazy-load in PermissibleBase. This'll be a performance hit, but it's causing subscription issues.

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-09-04 00:23:50 +01:00
parent 3fd400d31d
commit f82dfdc717

View File

@ -18,7 +18,6 @@ public class PermissibleBase implements Permissible {
private Permissible parent = this; private Permissible parent = this;
private final List<PermissionAttachment> attachments = new LinkedList<PermissionAttachment>(); private final List<PermissionAttachment> attachments = new LinkedList<PermissionAttachment>();
private final Map<String, PermissionAttachmentInfo> permissions = new HashMap<String, PermissionAttachmentInfo>(); private final Map<String, PermissionAttachmentInfo> permissions = new HashMap<String, PermissionAttachmentInfo>();
private boolean dirtyPermissions = true;
public PermissibleBase(ServerOperator opable) { public PermissibleBase(ServerOperator opable) {
this.opable = opable; this.opable = opable;
@ -27,7 +26,7 @@ public class PermissibleBase implements Permissible {
this.parent = (Permissible)opable; this.parent = (Permissible)opable;
} }
calculatePermissions(); recalculatePermissions();
} }
public boolean isOp() { public boolean isOp() {
@ -51,8 +50,6 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission name cannot be null"); throw new IllegalArgumentException("Permission name cannot be null");
} }
calculatePermissions();
return permissions.containsKey(name.toLowerCase()); return permissions.containsKey(name.toLowerCase());
} }
@ -69,8 +66,6 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission name cannot be null"); throw new IllegalArgumentException("Permission name cannot be null");
} }
calculatePermissions();
String name = inName.toLowerCase(); String name = inName.toLowerCase();
if (isPermissionSet(name)) { if (isPermissionSet(name)) {
@ -91,8 +86,6 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission cannot be null"); throw new IllegalArgumentException("Permission cannot be null");
} }
calculatePermissions();
String name = perm.getName().toLowerCase(); String name = perm.getName().toLowerCase();
if (isPermissionSet(name)) { if (isPermissionSet(name)) {
@ -156,27 +149,19 @@ public class PermissibleBase implements Permissible {
} }
public void recalculatePermissions() { public void recalculatePermissions() {
dirtyPermissions = true; clearPermissions();
} Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
public synchronized void calculatePermissions() { for (Permission perm : defaults) {
if (dirtyPermissions) { String name = perm.getName().toLowerCase();
clearPermissions(); permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true));
Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp()); Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent); calculateChildPermissions(perm.getChildren(), false, null);
}
for (Permission perm : defaults) { for (PermissionAttachment attachment : attachments) {
String name = perm.getName().toLowerCase(); calculateChildPermissions(attachment.getPermissions(), false, attachment);
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;
} }
} }
@ -187,7 +172,8 @@ public class PermissibleBase implements Permissible {
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent); 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(); permissions.clear();
} }
@ -246,7 +232,6 @@ public class PermissibleBase implements Permissible {
} }
public Set<PermissionAttachmentInfo> getEffectivePermissions() { public Set<PermissionAttachmentInfo> getEffectivePermissions() {
calculatePermissions();
return new HashSet<PermissionAttachmentInfo>(permissions.values()); return new HashSet<PermissionAttachmentInfo>(permissions.values());
} }