From 54474d710099fa9352e288a579b84f733a75cd93 Mon Sep 17 00:00:00 2001 From: A248 Date: Fri, 2 Apr 2021 01:51:54 -0400 Subject: [PATCH] Add Duration methods to TaskBuilder (#445) --- .../api/scheduler/Scheduler.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java b/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java index 1ff2b8afa..f59324d65 100644 --- a/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java +++ b/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.scheduler; +import java.time.Duration; import java.util.concurrent.TimeUnit; import org.checkerframework.common.value.qual.IntRange; @@ -38,6 +39,16 @@ public interface Scheduler { */ TaskBuilder delay(@IntRange(from = 0) long time, TimeUnit unit); + /** + * Specifies that the task should delay its execution by the specified amount of time. + * + * @param duration the duration of the delay + * @return this builder, for chaining + */ + default TaskBuilder delay(Duration duration) { + return delay(duration.toMillis(), TimeUnit.MILLISECONDS); + } + /** * Specifies that the task should continue running after waiting for the specified amount, until * it is cancelled. @@ -48,6 +59,17 @@ public interface Scheduler { */ TaskBuilder repeat(@IntRange(from = 0) long time, TimeUnit unit); + /** + * Specifies that the task should continue running after waiting for the specified amount, until + * it is cancelled. + * + * @param duration the duration of the delay + * @return this builder, for chaining + */ + default TaskBuilder repeat(Duration duration) { + return repeat(duration.toMillis(), TimeUnit.MILLISECONDS); + } + /** * Clears the delay on this task. *