Synchronize pushing to Bukkit perms to prevent any

ConcurrentModificationException.
This commit is contained in:
ElgarL 2013-01-13 16:20:09 +00:00
parent 999d922fb9
commit b860e943f6
2 changed files with 22 additions and 18 deletions

View File

@ -205,4 +205,5 @@ v 2.0:
- Add support for Rcon. - Add support for Rcon.
- Prevent GM commands from being used on CommandBlocks. - Prevent GM commands from being used on CommandBlocks.
- Clear our attachment map upon a manload so we correctly reconfigure a players new permissions. - 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). - Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks).
- Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException.

View File

@ -137,8 +137,7 @@ public class BukkitPermissions {
/** /**
* Push all permissions which are registered with GM for this player, on * Push all permissions which are registered with GM for this player, on
* this world to Bukkit * this world to Bukkit and make it update for the child nodes.
* and make it update for the child nodes.
* *
* @param player * @param player
* @param world * @param world
@ -148,9 +147,9 @@ public class BukkitPermissions {
if (player == null || !GroupManager.isLoaded()) { if (player == null || !GroupManager.isLoaded()) {
return; return;
} }
String name = player.getName(); String name = player.getName();
// Reset the User objects player reference. // Reset the User objects player reference.
User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(name); User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(name);
if (user != null) if (user != null)
@ -175,7 +174,8 @@ public class BukkitPermissions {
List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(name, false)); List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(name, false));
LinkedHashMap<String, Boolean> newPerms = new LinkedHashMap<String, Boolean>(); LinkedHashMap<String, Boolean> newPerms = new LinkedHashMap<String, Boolean>();
// 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); playerPermArray = sort(playerPermArray);
Boolean value = false; Boolean value = false;
@ -186,25 +186,28 @@ public class BukkitPermissions {
/** /**
* This is put in place until such a time as Bukkit pull 466 is * This is put in place until such a time as Bukkit pull 466 is
* implemented * implemented https://github.com/Bukkit/Bukkit/pull/466
* https://github.com/Bukkit/Bukkit/pull/466
*/ */
try { // Codename_B source try { // Codename_B source
@SuppressWarnings("unchecked") synchronized (attachment.getPermissible()) {
Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(attachment);
// Clear the map (faster than removing the attachment and recalculating) @SuppressWarnings("unchecked")
orig.clear(); Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(attachment);
// Then whack our map into there // Clear the map (faster than removing the attachment and
orig.putAll(newPerms); // recalculating)
// That's all folks! orig.clear();
attachment.getPermissible().recalculatePermissions(); // Then whack our map into there
//player.recalculatePermissions(); orig.putAll(newPerms);
// That's all folks!
attachment.getPermissible().recalculatePermissions();
}
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
GroupManager.logger.finest("Attachment updated for: " + name); GroupManager.logger.finest("Attachment updated for: " + name);
} }