-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new TaskTime & TimerTaskTime with 0-delay task handling
- Loading branch information
Showing
8 changed files
with
587 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...it/hscore-bukkit-scheduler/src/main/java/me/hsgamer/hscore/bukkit/scheduler/TaskTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package me.hsgamer.hscore.bukkit.scheduler; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* The time for the task | ||
*/ | ||
public class TaskTime { | ||
private final long time; | ||
private final TimeUnit unit; | ||
private final long ticks; | ||
|
||
private TaskTime(long time, TimeUnit unit) { | ||
this.time = Math.max(time, 0); | ||
this.unit = unit; | ||
this.ticks = unit.toMillis(this.time) / 50; | ||
} | ||
|
||
/** | ||
* Create a new task time | ||
* | ||
* @param time the time | ||
* @param unit the unit | ||
* | ||
* @return the task time | ||
*/ | ||
public static TaskTime of(long time, TimeUnit unit) { | ||
return new TaskTime(time, unit); | ||
} | ||
|
||
/** | ||
* Create a new task time from ticks | ||
* | ||
* @param ticks the ticks | ||
* | ||
* @return the task time | ||
*/ | ||
public static TaskTime of(long ticks) { | ||
return new TaskTime(ticks * 50, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
/** | ||
* Get the time | ||
* | ||
* @return the time | ||
*/ | ||
public long getTime() { | ||
return time; | ||
} | ||
|
||
/** | ||
* Get the unit | ||
* | ||
* @return the unit | ||
*/ | ||
public TimeUnit getUnit() { | ||
return unit; | ||
} | ||
|
||
/** | ||
* Get the ticks | ||
* | ||
* @return the ticks | ||
*/ | ||
public long getTicks() { | ||
return ticks; | ||
} | ||
} |
Oops, something went wrong.