From 5e26f06c54c9988ab0203b4dee6465ef8d5e3e76 Mon Sep 17 00:00:00 2001 From: Lukas Planz Date: Sat, 29 Jun 2024 11:32:41 +0200 Subject: [PATCH] Add option to apply cooldowns to multiple categories --- CHANGELOG.md | 1 + .../waypoints/config/general/TeleportConfiguration.kt | 4 ++++ .../de/md5lukas/waypoints/util/TeleportManager.kt | 10 +++++++--- waypoints/src/main/resources/config.yml | 9 +++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7706e1a..90364df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/general/TeleportConfiguration.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/general/TeleportConfiguration.kt index 47b39b1..9a50044 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/general/TeleportConfiguration.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/general/TeleportConfiguration.kt @@ -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 @@ -33,6 +34,9 @@ class TypedTeleportConfiguration { var cooldown: Duration = Duration.ZERO private set + var alsoApplyCooldownTo: List = emptyList() + private set + var mustVisit: Boolean? = false private set diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/TeleportManager.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/TeleportManager.kt index 3a29095..92dd122 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/TeleportManager.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/TeleportManager.kt @@ -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 = @@ -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) { diff --git a/waypoints/src/main/resources/config.yml b/waypoints/src/main/resources/config.yml index c4db399..55c3324 100644 --- a/waypoints/src/main/resources/config.yml +++ b/waypoints/src/main/resources/config.yml @@ -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 @@ -155,6 +158,8 @@ general: # This only affects the price of the teleportation private: cooldown: 24h + alsoApplyCooldownTo: + - death mustVisit: true @@ -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 @@ -176,6 +183,7 @@ general: public: cooldown: 24h + alsoApplyCooldownTo: [] mustVisit: true @@ -186,6 +194,7 @@ general: permission: cooldown: 4h + alsoApplyCooldownTo: [] mustVisit: false