Convenience toMilliseconds, add UpdateOption methods

This commit is contained in:
LeoDog896 2021-06-01 11:29:40 -04:00
parent c105fcc339
commit f68054d564
2 changed files with 34 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package net.minestom.server.timer;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption;
import org.jetbrains.annotations.NotNull;
/**
@ -72,6 +73,18 @@ public class TaskBuilder {
return this;
}
/**
* Specifies that the {@link Task} should delay its execution by the specified amount of time.
*
* @param updateOption the UpdateOption for this builder.
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder delay(UpdateOption updateOption) {
this.delay = updateOption.toMilliseconds();
return this;
}
/**
* Specifies that the {@link Task} should continue to run after waiting for the specified value until it is terminated.
*
@ -85,6 +98,18 @@ public class TaskBuilder {
return this;
}
/**
* Specifies that the {@link Task} should continue to run after waiting for the specified value until it is terminated.
*
* @param updateOption the UpdateOption for this builder.
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder repeat(UpdateOption updateOption) {
this.repeat = updateOption.toMilliseconds();
return this;
}
/**
* Clears the delay interval of the {@link Task}.
*

View File

@ -35,4 +35,13 @@ public class UpdateOption {
UpdateOption updateOption = (UpdateOption) o;
return Objects.equals(value, updateOption.value) && Objects.equals(timeUnit, updateOption.timeUnit);
}
/**
* Converts this update option to milliseconds
*
* @return the converted milliseconds based on the time value and the unit
*/
public long toMilliseconds() {
return timeUnit.toMilliseconds(value);
}
}