package net.knarcraft.permissionsigns.container; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * A temporary permission that needs to be removed after a given duration */ public class TemporaryPermission implements Comparable { private final long grantedTime; private final OfflinePlayer grantedPlayer; private final String permissionNode; private final int duration; private final String world; /** * Instantiates a new temporary permission * * @param player

The player the temporary permission was assigned to

* @param permissionNode

The permission node granted to the player

* @param duration

The duration, in seconds, the temporary permission should last

* @param world

The world the permission should be added to

*/ public TemporaryPermission(@NotNull Player player, @NotNull String permissionNode, int duration, @Nullable String world) { grantedTime = System.currentTimeMillis(); this.grantedPlayer = player; this.permissionNode = permissionNode; this.duration = duration; this.world = world; } /** * Instantiates a new temporary permission * * @param player

The player the temporary permission was assigned to

* @param permissionNode

The permission node granted to the player

* @param grantedTime

The time this temporary permission was granted

* @param duration

The duration, in seconds, the temporary permission should last

* @param world

The world the permission should be added to

*/ public TemporaryPermission(@NotNull OfflinePlayer player, @NotNull String permissionNode, long grantedTime, int duration, @Nullable String world) { this.grantedPlayer = player; this.permissionNode = permissionNode; this.grantedTime = grantedTime; this.duration = duration; this.world = world; } /** * Gets the time that this temporary permission was granted * * @return

The time (current time millis) this permission was granted

*/ public long getGrantedTime() { return this.grantedTime; } /** * Gets the duration the player should be granted this permission for * * @return

The duration of the temporary permission

*/ public int getGrantedDuration() { return this.duration; } /** * Gets the player this temporary permission was granted to * * @return

The player this temporary permission was granted to

*/ public @NotNull OfflinePlayer getGrantedPlayer() { return grantedPlayer; } /** * Gets the permission node that was granted to this player * * @return

The permission node that was granted to this player

*/ public @NotNull String getPermissionNode() { return permissionNode; } /** * Gets the world the permission node should be added to * * @return

The world the permission node should be added to

*/ public @Nullable String getWorld() { return world; } @Override public int compareTo(@NotNull TemporaryPermission other) { return (int) (grantedTime + (1000 * duration) - (grantedTime + (1000 * other.duration))); } }