Skip to content

Commit

Permalink
Add option to apply cooldowns to multiple categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytm committed Jun 29, 2024
1 parent 3aa0334 commit 5e26f06
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- Added Traditional Chinese translations by ItzTheBear
- Added config option to apply cooldowns from one waypoint type to other ones

### Changed
- **CommandAPI is no longer required**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import de.md5lukas.konfig.ConfigPath
import de.md5lukas.konfig.Configurable
import de.md5lukas.konfig.TypeAdapter
import de.md5lukas.konfig.UseAdapter
import de.md5lukas.waypoints.api.Type
import de.md5lukas.waypoints.util.Expression
import de.md5lukas.waypoints.util.MathParser
import java.time.Duration
Expand Down Expand Up @@ -33,6 +34,9 @@ class TypedTeleportConfiguration {
var cooldown: Duration = Duration.ZERO
private set

var alsoApplyCooldownTo: List<Type> = emptyList()
private set

var mustVisit: Boolean? = false
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ class TeleportManager(private val plugin: WaypointsPlugin) : Listener {

val playerData = plugin.api.getWaypointPlayer(player.uniqueId)

val cooldownUntil = playerData.getCooldownUntil(waypoint.type)
if (cooldownUntil != null) {
playerData.getCooldownUntil(waypoint.type)?.let { cooldownUntil ->
val remainingMillis = Duration.between(Instant.now(), cooldownUntil).toMillis()
if (remainingMillis > 0) {
val remainingCooldown =
Expand Down Expand Up @@ -216,7 +215,12 @@ class TeleportManager(private val plugin: WaypointsPlugin) : Listener {
val cooldown = config.cooldown

if (cooldown.toSeconds() > 0) {
playerData.setCooldownUntil(waypoint.type, OffsetDateTime.now().plus(cooldown))
val cooldownUntil = OffsetDateTime.now().plus(cooldown)
playerData.setCooldownUntil(waypoint.type, cooldownUntil)
config.alsoApplyCooldownTo.forEach {
if (it === waypoint.type) return@forEach
playerData.setCooldownUntil(it, cooldownUntil)
}
}
} else {
when (config.paymentType) {
Expand Down
9 changes: 9 additions & 0 deletions waypoints/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ general:
# The cooldown between each teleportation for a player
# Set to 0s to disable
#
# alsoApplyCooldownTo:
# When teleporting to a waypoint of this type, all listed types will also receive the same cooldown as this one.
#
# mustVisit:
# If set to true, the player must have visited the waypoint before.
# To mark a waypoint as visited the player must have either created it at his current location without coordinates
Expand All @@ -155,6 +158,8 @@ general:
# This only affects the price of the teleportation
private:
cooldown: 24h
alsoApplyCooldownTo:
- death

mustVisit: true

Expand All @@ -165,6 +170,8 @@ general:

death:
cooldown: 24h
alsoApplyCooldownTo:
- private

# Allows the player to only teleport to the last location they died at, not all of them
onlyLastWaypoint: true
Expand All @@ -176,6 +183,7 @@ general:

public:
cooldown: 24h
alsoApplyCooldownTo: []

mustVisit: true

Expand All @@ -186,6 +194,7 @@ general:

permission:
cooldown: 4h
alsoApplyCooldownTo: []

mustVisit: false

Expand Down

0 comments on commit 5e26f06

Please sign in to comment.