EpicKnarvik97 52b033c005 Adds Vault integration
Adds the EconomyManager class for handling Vault payments
Adds the unfinished PermissionManager class for granting permissions through Vault
Adds the GPLv3 license
Fixes dependencies
Adds some code for withdrawing money and granting permissions when a sign is clicked
Changes cost to a double to be compliant with Vault
2022-01-14 10:30:44 +01:00

80 lines
2.9 KiB
Java

package net.knarcraft.permissionsigns.manager;
import net.knarcraft.permissionsigns.container.TemporaryPermission;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.List;
/**
* A manager that performs all Permission tasks
*/
public class PermissionManager {
private static Permission permission;
private static List<TemporaryPermission> temporaryPermissions;
/**
* Initializes the permission manager
*
* @param permission <p>The permission object to use for everything permission-related</p>
*/
public static void initialize(Permission permission) {
PermissionManager.permission = permission;
}
/**
* Grants a permission to the given player
*
* @param player <p>The player to grant the permission to</p>
* @param permissionNode <p>The permission node to grant the player</p>
* @param permanent <p>Whether to permanently grant the permission node</p>
*/
public static void addPermission(Player player, String permissionNode, boolean permanent) {
if (permanent) {
addPermission(player, permissionNode);
} else {
addTemporaryPermission(player, permissionNode);
}
}
/**
* Grants a permanent permission to a player
*
* @param player <p>The player to grant the permission to</p>
* @param permissionNode <p>The permission node to grant to the player</p>
*/
private static void addPermission(Player player, String permissionNode) {
permission.playerAdd(player, permissionNode);
}
/**
* Grants a temporary permission to a player
*
* @param player <p>The player to give the permission to</p>
* @param permissionNode <p>The temporary permission to grant</p>
*/
private static void addTemporaryPermission(OfflinePlayer player, String permissionNode) {
permission.playerAddTransient(player, permissionNode);
//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 <p>The player to remove the permission from</p>
* @param permissionNode <p>The permission node to remove from the player</p>
*/
public static void removeTemporaryPermission(OfflinePlayer player, String permissionNode) {
permission.playerRemoveTransient(player, permissionNode);
}
}