Commit 9dfab9fc7eddb6b30ca5592d2d56a01022ee3d80
1 parent
7b19b205
Hopefully fix CME in client permissions manager, closes #25
Showing
1 changed file
with
40 additions
and
22 deletions
src/main/java/com/mumfrey/liteloader/permissions/PermissionsManagerClient.java
... | ... | @@ -47,37 +47,37 @@ public final class PermissionsManagerClient implements PermissionsManager, Plugi |
47 | 47 | * Permissions permissible which is a proxy for permissions that are common |
48 | 48 | * to all mods. |
49 | 49 | */ |
50 | - private static Permissible allMods = new PermissibleAllMods(); | |
51 | - | |
52 | - /** | |
53 | - * Minecraft instance | |
54 | - */ | |
55 | - private GameEngine<?, ?> engine; | |
50 | + private final static Permissible allMods = new PermissibleAllMods(); | |
56 | 51 | |
57 | 52 | /** |
58 | 53 | * List of registered client mods supporting permissions |
59 | 54 | */ |
60 | - private Map<String, Permissible> registeredClientMods = new HashMap<String, Permissible>(); | |
55 | + private final Map<String, Permissible> registeredClientMods = new HashMap<String, Permissible>(); | |
61 | 56 | |
62 | 57 | /** |
63 | 58 | * List of registered client permissions, grouped by mod |
64 | 59 | */ |
65 | - private Map<Permissible, TreeSet<String>> registeredClientPermissions = new HashMap<Permissible, TreeSet<String>>(); | |
60 | + private final Map<Permissible, TreeSet<String>> registeredClientPermissions = new HashMap<Permissible, TreeSet<String>>(); | |
66 | 61 | |
67 | 62 | /** |
68 | 63 | * Objects which listen to events generated by this object |
69 | 64 | */ |
70 | - private Set<Permissible> permissibles = new HashSet<Permissible>(); | |
65 | + private final Set<Permissible> permissibles = new HashSet<Permissible>(); | |
71 | 66 | |
72 | 67 | /** |
73 | 68 | * Local permissions, used when server permissions are not available |
74 | 69 | */ |
75 | - private LocalPermissions localPermissions = new LocalPermissions(); | |
70 | + private final LocalPermissions localPermissions = new LocalPermissions(); | |
76 | 71 | |
77 | 72 | /** |
78 | 73 | * Server permissions, indexed by mod |
79 | 74 | */ |
80 | - private Map<String, ServerPermissions> serverPermissions = new HashMap<String, ServerPermissions>(); | |
75 | + private final Map<String, ServerPermissions> serverPermissions = new HashMap<String, ServerPermissions>(); | |
76 | + | |
77 | + /** | |
78 | + * Minecraft instance | |
79 | + */ | |
80 | + private GameEngine<?, ?> engine; | |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Last time onTick was called, used to detect tamper condition if no ticks |
... | ... | @@ -124,8 +124,11 @@ public final class PermissionsManagerClient implements PermissionsManager, Plugi |
124 | 124 | if (mod == null) mod = allMods; |
125 | 125 | String modName = mod.getPermissibleModName(); |
126 | 126 | |
127 | - ServerPermissions modPermissions = this.serverPermissions.get(modName); | |
128 | - return modPermissions != null ? modPermissions : this.localPermissions; | |
127 | + synchronized (this.serverPermissions) | |
128 | + { | |
129 | + ServerPermissions modPermissions = this.serverPermissions.get(modName); | |
130 | + return modPermissions != null ? modPermissions : this.localPermissions; | |
131 | + } | |
129 | 132 | } |
130 | 133 | |
131 | 134 | /* (non-Javadoc) |
... | ... | @@ -138,8 +141,11 @@ public final class PermissionsManagerClient implements PermissionsManager, Plugi |
138 | 141 | if (mod == null) mod = allMods; |
139 | 142 | String modName = mod.getPermissibleModName(); |
140 | 143 | |
141 | - ServerPermissions modPermissions = this.serverPermissions.get(modName); | |
142 | - return modPermissions != null ? modPermissions.getReplicationTime() : 0; | |
144 | + synchronized (this.serverPermissions) | |
145 | + { | |
146 | + ServerPermissions modPermissions = this.serverPermissions.get(modName); | |
147 | + return modPermissions != null ? modPermissions.getReplicationTime() : 0; | |
148 | + } | |
143 | 149 | } |
144 | 150 | |
145 | 151 | /** |
... | ... | @@ -208,7 +214,10 @@ public final class PermissionsManagerClient implements PermissionsManager, Plugi |
208 | 214 | */ |
209 | 215 | protected void clearServerPermissions() |
210 | 216 | { |
211 | - this.serverPermissions.clear(); | |
217 | + synchronized (this.serverPermissions) | |
218 | + { | |
219 | + this.serverPermissions.clear(); | |
220 | + } | |
212 | 221 | |
213 | 222 | for (Permissible permissible : this.permissibles) |
214 | 223 | { |
... | ... | @@ -264,7 +273,10 @@ public final class PermissionsManagerClient implements PermissionsManager, Plugi |
264 | 273 | } |
265 | 274 | else |
266 | 275 | { |
267 | - this.serverPermissions.remove(modName); | |
276 | + synchronized (this.serverPermissions) | |
277 | + { | |
278 | + this.serverPermissions.remove(modName); | |
279 | + } | |
268 | 280 | } |
269 | 281 | } |
270 | 282 | |
... | ... | @@ -289,12 +301,15 @@ public final class PermissionsManagerClient implements PermissionsManager, Plugi |
289 | 301 | } |
290 | 302 | } |
291 | 303 | |
292 | - for (Map.Entry<String, ServerPermissions> modPermissions : this.serverPermissions.entrySet()) | |
304 | + synchronized (this.serverPermissions) | |
293 | 305 | { |
294 | - if (!modPermissions.getValue().isValid()) | |
306 | + for (Map.Entry<String, ServerPermissions> modPermissions : this.serverPermissions.entrySet()) | |
295 | 307 | { |
296 | - modPermissions.getValue().notifyRefreshPending(); | |
297 | - this.sendPermissionQuery(this.registeredClientMods.get(modPermissions.getKey())); | |
308 | + if (!modPermissions.getValue().isValid()) | |
309 | + { | |
310 | + modPermissions.getValue().notifyRefreshPending(); | |
311 | + this.sendPermissionQuery(this.registeredClientMods.get(modPermissions.getKey())); | |
312 | + } | |
298 | 313 | } |
299 | 314 | } |
300 | 315 | |
... | ... | @@ -336,7 +351,10 @@ public final class PermissionsManagerClient implements PermissionsManager, Plugi |
336 | 351 | |
337 | 352 | if (modPermissions != null && modPermissions.getModName() != null) |
338 | 353 | { |
339 | - this.serverPermissions.put(modPermissions.getModName(), modPermissions); | |
354 | + synchronized (this.serverPermissions) | |
355 | + { | |
356 | + this.serverPermissions.put(modPermissions.getModName(), modPermissions); | |
357 | + } | |
340 | 358 | |
341 | 359 | Permissible permissible = this.registeredClientMods.get(modPermissions.getModName()); |
342 | 360 | if (permissible != null) permissible.onPermissionsChanged(this); | ... | ... |