MCPcopy Create free account
hub / github.com/Solara-Development/Neptune / Time

Class Time

Plugin/src/main/java/dev/lrxh/neptune/utils/Time.java:5–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import dev.lrxh.api.utils.ITime;
4
5public class Time implements ITime {
6 private long oldTime;
7 private long lastCurrentTime;
8 private boolean stop;
9
10 public Time() {
11 this.oldTime = System.currentTimeMillis();
12 this.stop = false;
13 }
14
15 public String formatTime() {
16 if (!stop) {
17 lastCurrentTime = System.currentTimeMillis();
18 }
19
20 long elapsedTime = lastCurrentTime - oldTime;
21
22 long minutes = (elapsedTime / 1000) / 60;
23 long seconds = (elapsedTime / 1000) % 60;
24
25 return (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
26 }
27
28 public String formatSecondsMillis() {
29 if (!stop) {
30 lastCurrentTime = System.currentTimeMillis();
31 }
32
33 long elapsedTime = lastCurrentTime - oldTime;
34
35 long millis = (elapsedTime % 1000) / 10;
36 long seconds = (elapsedTime / 1000) % 60;
37
38 return (seconds < 10 ? "0" : "") + seconds + "." + (millis < 10 ? "0" : "") + millis + "s";
39 }
40
41 public long getElapsed() {
42 return System.currentTimeMillis() - oldTime;
43 }
44
45 public void setZero() {
46 this.oldTime = 0;
47 this.lastCurrentTime = 0;
48 }
49
50 public void setStop(boolean stop) {
51 this.stop = stop;
52
53 if (!stop) {
54 this.oldTime = System.currentTimeMillis();
55 }
56 }
57}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected