Simplify further as using ConcurrentHashMap

This commit is contained in:
dordsor21 2020-10-01 17:08:29 +01:00
parent 197e08a937
commit 88e64a0632
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -19,26 +19,16 @@ public class BukkitPermissionAttachmentManager {
if (p == null) { if (p == null) {
return null; return null;
} }
PermissionAttachment attachment = attachments.get(p); return attachments.computeIfAbsent(p, k -> k.addAttachment(plugin));
if (attachment != null) {
return attachment;
}
synchronized (this) {
return attachments.computeIfAbsent(p, k -> k.addAttachment(plugin));
}
} }
public void removeAttachment(@Nullable final Player p) { public void removeAttachment(@Nullable final Player p) {
if (p == null || attachments.get(p) == null) { if (p == null) {
return; return;
} }
synchronized (this) { PermissionAttachment attach = attachments.remove(p);
PermissionAttachment attach = attachments.remove(p); if (attach != null) {
if (attach != null) { p.removeAttachment(attach);
p.removeAttachment(attach);
}
} }
} }
} }