package net.knarcraft.permissionsigns.manager; import net.knarcraft.permissionsigns.container.TemporaryPermission; import net.milkbowl.vault.permission.Permission; import org.bukkit.entity.Player; import java.util.Queue; import java.util.concurrent.PriorityBlockingQueue; /** * A manager that performs all Permission tasks */ public class PermissionManager { private static Permission permission; private static final Queue temporaryPermissions = new PriorityBlockingQueue<>(); /** * Initializes the permission manager * * @param permission

The permission object to use for everything permission-related

*/ public static void initialize(Permission permission) { PermissionManager.permission = permission; } /** * Gets the registered temporary permissions * * @return

The registered temporary permissions

*/ public static Queue getTemporaryPermissions() { return temporaryPermissions; } /** * Grants a permanent permission to a player * * @param player

The player to grant the permission to

* @param permissionNode

The permission node to grant to the player

*/ public static void addPermission(Player player, String permissionNode) { //TODO: Account for world when granting permissions, if wanted permission.playerAdd(null, player, permissionNode); } /** * Grants a temporary permission to a player * * @param player

The player to give the permission to

* @param permissionNode

The temporary permission to grant

* @param duration

The duration for which the player should keep the given permission

*/ public static void addTemporaryPermission(Player player, String permissionNode, int duration) { permission.playerAddTransient(null, player, permissionNode); temporaryPermissions.add(new TemporaryPermission(player, permissionNode, duration)); //TODO: Create and store a temporary permission // Check all stored temporary permissions on startup: // * Remove expired temporary permissions // * Grant transient permissions // In a separate thread, remove any expired permissions, checking at least once every seconds. Might want to // store the granted permissions in a priority queue where the priority is the least duration left. // How to store temporary permissions? Identifier as Player + permission granted time? } /** * Removes a temporary permission * * @param player

The player to remove the permission from

* @param permissionNode

The permission node to remove from the player

*/ public static void removeTemporaryPermission(Player player, String permissionNode) { if (player.hasPermission(permissionNode)) { permission.playerRemoveTransient(null, player, permissionNode); } } }