105 lines
3.5 KiB
Java
105 lines
3.5 KiB
Java
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<TemporaryPermission> {
|
|
|
|
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 <p>The player the temporary permission was assigned to</p>
|
|
* @param permissionNode <p>The permission node granted to the player</p>
|
|
* @param duration <p>The duration, in seconds, the temporary permission should last</p>
|
|
* @param world <p>The world the permission should be added to</p>
|
|
*/
|
|
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 <p>The player the temporary permission was assigned to</p>
|
|
* @param permissionNode <p>The permission node granted to the player</p>
|
|
* @param grantedTime <p>The time this temporary permission was granted</p>
|
|
* @param duration <p>The duration, in seconds, the temporary permission should last</p>
|
|
* @param world <p>The world the permission should be added to</p>
|
|
*/
|
|
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 <p>The time (current time millis) this permission was granted</p>
|
|
*/
|
|
public long getGrantedTime() {
|
|
return this.grantedTime;
|
|
}
|
|
|
|
/**
|
|
* Gets the duration the player should be granted this permission for
|
|
*
|
|
* @return <p>The duration of the temporary permission</p>
|
|
*/
|
|
public int getGrantedDuration() {
|
|
return this.duration;
|
|
}
|
|
|
|
/**
|
|
* Gets the player this temporary permission was granted to
|
|
*
|
|
* @return <p>The player this temporary permission was granted to</p>
|
|
*/
|
|
public @NotNull OfflinePlayer getGrantedPlayer() {
|
|
return grantedPlayer;
|
|
}
|
|
|
|
/**
|
|
* Gets the permission node that was granted to this player
|
|
*
|
|
* @return <p>The permission node that was granted to this player</p>
|
|
*/
|
|
public @NotNull String getPermissionNode() {
|
|
return permissionNode;
|
|
}
|
|
|
|
/**
|
|
* Gets the world the permission node should be added to
|
|
*
|
|
* @return <p>The world the permission node should be added to</p>
|
|
*/
|
|
public @Nullable String getWorld() {
|
|
return world;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(@NotNull TemporaryPermission other) {
|
|
return (int) (grantedTime + (1000 * duration) - (grantedTime + (1000 * other.duration)));
|
|
}
|
|
|
|
}
|