50 lines
1.7 KiB
Java
50 lines
1.7 KiB
Java
package dev.itxiaohui.contentguard.admin;
|
|
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventPriority;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
public final class PermissionManager implements Listener {
|
|
public static final String ADMIN = "itxiaohui.contentguard.admin";
|
|
public static final String BYPASS = "itxiaohui.contentguard.bypass";
|
|
public static final String NOTIFY = "itxiaohui.contentguard.notify";
|
|
public static final String LOGS = "itxiaohui.contentguard.logs";
|
|
public static final String TEST = "itxiaohui.contentguard.test";
|
|
|
|
public record Identity(UUID id, String name, boolean bypass) {}
|
|
private final ConcurrentHashMap<Player, Identity> online = new ConcurrentHashMap<>();
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
public void onJoin(PlayerJoinEvent event) {
|
|
refresh(event.getPlayer());
|
|
}
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
public void onQuit(PlayerQuitEvent event) {
|
|
online.remove(event.getPlayer());
|
|
}
|
|
|
|
public void refresh(Player player) {
|
|
online.put(player, new Identity(player.getUniqueId(), player.getName(), player.hasPermission(BYPASS)));
|
|
}
|
|
|
|
public boolean cachedBypass(Player player) {
|
|
Identity identity = identity(player);
|
|
return identity != null && identity.bypass();
|
|
}
|
|
|
|
public Identity identity(Player player) {
|
|
return online.get(player);
|
|
}
|
|
|
|
public Set<Player> online() {
|
|
return online.keySet();
|
|
}
|
|
}
|