From 6676461f656f7a69ff973869aa7a26388e10178e Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 17 Jan 2012 18:03:16 +0000 Subject: v 1.9: Optimize populating Bukkit perms so we no longer calculate the child nodes (Bukkit already does this). --- .../permissions/AnjoPermissionsHandler.java | 61 ++++++++++++++-------- .../permissions/BukkitPermissions.java | 18 ++++--- .../permissions/PermissionsReaderInterface.java | 2 + 3 files changed, 53 insertions(+), 28 deletions(-) (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index b23fc01d4..167103796 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -90,13 +90,24 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { /** * Returns All permissions (including inheritance and sub groups) for the - * player. + * player, including child nodes from Bukkit. * * @param userName * @return List of all players permissions. */ @Override public List getAllPlayersPermissions(String userName) { + return getAllPlayersPermissions(userName, true); + } + /** + * Returns All permissions (including inheritance and sub groups) for the + * player. With or without Bukkit child nodes. + * + * @param userName + * @return List of all players permissions. + */ + @Override + public List getAllPlayersPermissions(String userName, Boolean includeChildren) { List playerPermArray = new ArrayList(); @@ -104,14 +115,16 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) { playerPermArray.add(perm); - Map children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray); - - if (children != null) { - for (String child : children.keySet()) { - if (children.get(child)) - if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) { - playerPermArray.add(child); - } + if (includeChildren) { + Map children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray); + + if (children != null) { + for (String child : children.keySet()) { + if (children.get(child)) + if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) { + playerPermArray.add(child); + } + } } } } @@ -122,12 +135,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) { playerPermArray.add(perm); - Map children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray); - if (children != null) { - for (String child : children.keySet()) { - if (children.get(child)) - if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) - playerPermArray.add(child); + if (includeChildren) { + Map children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray); + if (children != null) { + for (String child : children.keySet()) { + if (children.get(child)) + if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) + playerPermArray.add(child); + } } } } @@ -137,13 +152,15 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) { playerPermArray.add(perm); - Map children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray); - if (children != null) { - for (String child : children.keySet()) { - if (children.get(child)) - if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) { - playerPermArray.add(child); - } + if (includeChildren) { + Map children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray); + if (children != null) { + for (String child : children.keySet()) { + if (children.get(child)) + if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) { + playerPermArray.add(child); + } + } } } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index ebaadf8bd..91f9a9bd6 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -79,7 +79,7 @@ public class BukkitPermissions { public BukkitPermissions(GroupManager plugin) { this.plugin = plugin; - //this.collectPermissions(); + this.collectPermissions(); this.registerEvents(); this.updateAllPlayers(); @@ -105,15 +105,20 @@ public class BukkitPermissions { manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin); } - /* + public void collectPermissions() { registeredPermissions.clear(); + /* for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) { for (Permission permission : bukkitPlugin.getDescription().getPermissions()) registeredPermissions.push(permission); } + */ + + registeredPermissions = new LinkedList(Bukkit.getPluginManager().getPermissions()); + } - */ + public void updatePermissions(Player player) { this.updatePermissions(player, null); @@ -194,7 +199,7 @@ public class BukkitPermissions { // Add all permissions for this player (GM only) // child nodes will be calculated by Bukkit. - List playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName()); + List playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName(), false); Map newPerms = new HashMap(); for (String permission : playerPermArray) { @@ -210,6 +215,7 @@ public class BukkitPermissions { */ newPerms.put(permission, value); } + //player.recalculatePermissions(); /** @@ -373,13 +379,13 @@ public class BukkitPermissions { if (!GroupManager.isLoaded()) return; - //collectPermissions(); + collectPermissions(); updateAllPlayers(); } @Override public void onPluginDisable(PluginDisableEvent event) { - // collectPermissions(); + collectPermissions(); // updateAllPlayers(); } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java index c0383c160..cf11bd37f 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java @@ -234,4 +234,6 @@ public abstract class PermissionsReaderInterface { ////////////////////////////// public abstract List getAllPlayersPermissions(String userName); + + public abstract List getAllPlayersPermissions(String userName, Boolean includeChildren); } -- cgit v1.2.3