Merge pull request #308 from Project-Cepi/update-option-scheduling

Convenience toMilliseconds, add UpdateOption methods to TaskBuilder
This commit is contained in:
TheMode 2021-06-02 11:31:05 +02:00 committed by GitHub
commit da7bed78ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}
}