From b860e943f63f2006a15441e75492dc9b44f041cc Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 13 Jan 2013 16:20:09 +0000 Subject: Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../permissions/BukkitPermissions.java | 37 ++++++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 175d59959..0fb2d9d17 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -205,4 +205,5 @@ v 2.0: - Add support for Rcon. - Prevent GM commands from being used on CommandBlocks. - Clear our attachment map upon a manload so we correctly reconfigure a players new permissions. - - Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks). \ No newline at end of file + - Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks). + - Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 6b02a2286..a200a7b9a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -137,8 +137,7 @@ public class BukkitPermissions { /** * Push all permissions which are registered with GM for this player, on - * this world to Bukkit - * and make it update for the child nodes. + * this world to Bukkit and make it update for the child nodes. * * @param player * @param world @@ -148,9 +147,9 @@ public class BukkitPermissions { if (player == null || !GroupManager.isLoaded()) { return; } - + String name = player.getName(); - + // Reset the User objects player reference. User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(name); if (user != null) @@ -175,7 +174,8 @@ public class BukkitPermissions { List playerPermArray = new ArrayList(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(name, false)); LinkedHashMap newPerms = new LinkedHashMap(); - // Sort the perm list by parent/child, so it will push to superperms correctly. + // Sort the perm list by parent/child, so it will push to superperms + // correctly. playerPermArray = sort(playerPermArray); Boolean value = false; @@ -186,25 +186,28 @@ public class BukkitPermissions { /** * This is put in place until such a time as Bukkit pull 466 is - * implemented - * https://github.com/Bukkit/Bukkit/pull/466 + * implemented https://github.com/Bukkit/Bukkit/pull/466 */ try { // Codename_B source - @SuppressWarnings("unchecked") - Map orig = (Map) permissions.get(attachment); - // Clear the map (faster than removing the attachment and recalculating) - orig.clear(); - // Then whack our map into there - orig.putAll(newPerms); - // That's all folks! - attachment.getPermissible().recalculatePermissions(); - //player.recalculatePermissions(); + synchronized (attachment.getPermissible()) { + + @SuppressWarnings("unchecked") + Map orig = (Map) permissions.get(attachment); + // Clear the map (faster than removing the attachment and + // recalculating) + orig.clear(); + // Then whack our map into there + orig.putAll(newPerms); + // That's all folks! + attachment.getPermissible().recalculatePermissions(); + + } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } - + GroupManager.logger.finest("Attachment updated for: " + name); } -- cgit v1.2.3