mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-06-02 01:11:46 +00:00
8c0195970b
* Consistenty use javax annotations. - Unfortunately jetbrains annotations seem to be exposed transitively via core somewhere, but with the correct IDE settings, annotations can be defaulted to javax - Cleaning up of import order in #1195 - Must be merged before #1195 * Add and apply .editorconfig from P2 - Does not rearrange entries * Address some comments * add back some javadoc comments * Address final comments Co-authored-by: NotMyFault <mc.cache@web.de>
38 lines
1.0 KiB
Java
38 lines
1.0 KiB
Java
package com.fastasyncworldedit.bukkit;
|
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.permissions.PermissionAttachment;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
public class BukkitPermissionAttachmentManager {
|
|
|
|
private final WorldEditPlugin plugin;
|
|
private final Map<Player, PermissionAttachment> attachments = new ConcurrentHashMap<>();
|
|
|
|
public BukkitPermissionAttachmentManager(WorldEditPlugin plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
public PermissionAttachment getOrAddAttachment(@Nullable final Player p) {
|
|
if (p == null) {
|
|
return null;
|
|
}
|
|
return attachments.computeIfAbsent(p, k -> k.addAttachment(plugin));
|
|
}
|
|
|
|
public void removeAttachment(@Nullable final Player p) {
|
|
if (p == null) {
|
|
return;
|
|
}
|
|
PermissionAttachment attach = attachments.remove(p);
|
|
if (attach != null) {
|
|
p.removeAttachment(attach);
|
|
}
|
|
}
|
|
|
|
}
|