net.chestmc.common.time.Cooldown.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chest-server Show documentation
Show all versions of chest-server Show documentation
A spigot fork to kotlin structure and news.
The newest version!
package net.chestmc.common.time
import net.chestmc.common.extensions.currentMillis
import net.chestmc.common.extensions.numbers.toDate
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import java.util.*
import java.util.concurrent.TimeUnit
/**
* A cooldown class represents a duration that can be expired.
*/
@Serializable
data class Cooldown(val duration: Long, @Transient val unit: TimeUnit = TimeUnit.MILLISECONDS) : StartedTime {
override var startMillis: Long = currentMillis
}
/**
* Returns the time left to expires this cooldown.
*/
val Cooldown.expiresIn: Long
get() = startMillis + unit.toMillis(duration) / currentMillis
/**
* Returns the date to expires this cooldown.
*/
inline val Cooldown.expiresDate: Date
get() = expiresIn.toDate()
/**
* Verifies if this cooldown has expired.
*/
inline val Cooldown.isExpired: Boolean
get() = expiresIn <= 0
© 2015 - 2025 Weber Informatics LLC | Privacy Policy