mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 13:08:19 +01:00
Convenience toMilliseconds, add UpdateOption methods
This commit is contained in:
parent
c105fcc339
commit
f68054d564
@ -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}.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user